Get hostname from IP address

Before getting or knowing the hostname from the IP address, it is important to know what the hostname and IP address are and why they are needed. So, firstly we will discuss the hostname and IP address then tell you to find the hostname from the IP address.

We will brief you how you can get the hostname if you have its IP address. Basically, how can one get the hostname from the IP address?

Here, we have some points that we will discuss below in this chapter:

What is hostname?

A hostname is a name called on the network. The term hostname is used for computer name and website name. It helps to distinguish the machines on a local network. Basically, a hostname is an internet address of a website or machine.

A hostname for a computer can be any selectable name DESKTOP-MZ53DV or anything you want.

As we already know that IP address (e.g., 69.171.250.35) is difficult to remember while hostname (facebook.com) is easy to call and remind. Thereby hostname came into existence. In real life, each person has any name for identifying him. Similarly, hostname helps to identify a machine or website by its hostname.

A hostname for a website may be a domain name with a prefix. For example, a hostname for the domain javatpoint.com is www.javatpoint.com.

Get the hostname of a computer

Sometimes, you require the hostname of your computer system when it connects with a network. The hostname helps the other devices to find your computer on that network. You can easily get the hostname of your computer system by typing a simple command on command prompt (CMD) in the Windows operating system.

Command 1

Open the command prompt (CMD in Windows) and run the above command on it.

Get hostname from IP address

The hostname returned by running this command (DESKTOP-MAJMT36) is your computer name. It can be used on the network when creating a network.

Command 2

Following is another command to get the hostname of your computer. This will not only display the hostname, but it will also display some other details:

Open the command prompt. Copy and run the above command to see the response.

Get hostname from IP address

The hostname will be labeled as Host Name.

Get hostname of a website from IP address

There are various ways to find out the hostname from the IP address of any website. We will tell you how you can get the hostname of a website from an IP address. All the above methods and commands are for Windows operating system that you need to run on command prompt (CMD).

See all the methods discussed below:

Method 1: Using ping command

In this method, we will run a ping command to get the hostname of a website using the IP address. So, copy and run the below command on CMD (Command Prompt) in Windows operating system.

For example,

Example 1

Run the command on CMD to get the hostname for the IP address 8.8.8.8. For your information, this IP address is the IP address of Google.

Get hostname from IP address

Result

In the above screenshot, you will see that the hostname is Google for the IP address 8.8.8.8.

Example 2

Get the hostname for another IP address 194.169.80.121. For your information, this IP address is our Javatpoint website IP address.

Get hostname from IP address

Result

You can see in the above screenshot that we will get the hostname www.javatpoint.com from the IP address 194.169.80.121.

Similarly, you can find the hostname from the other IP addresses using this ping command.

Method 2: Using nslookup command

This is another method to get the hostname from the IP address. Run the nslookup command with an IP address from which you want to get the hostname. This command works a bit differently from the ping command that is discussed above. See the syntax to run on command prompt (CMD).

Syntax

For example

Example 1

Run the command on CMD to get the hostname for the IP address 8.8.8.8. Note that 8.8.8.8 is the IP address of Google. You can see that after executing the command in the below screenshot.

Get hostname from IP address

Result

In the above screenshot, you will see that the hostname is Google for the IP address 8.8.8.8.

Example 2

Get the hostname for another IP address 194.169.80.121. For your information this IP address is our website Javatpoint IP address.

Get hostname from IP address

Other than all the above methods, you can get the hostname using the Java programming language. It provides methods to find out the hostname from the IP address and vice-versa. But if you are a non-technical user, it is almost impossible to write the Java code and get the hostname from IP.

In that case, we will suggest you to use the methods that we have discussed in this chapter.

Result

You can see in the above screenshot that we will get the hostname www.javatpoint.com from the IP address 194.169.80.121.

Similarly, you can find the hostname from the other IP addresses using the nslookup command.

What is IP address?

An IP address refers to the Internet Protocol address. An Internet Protocol address is your hardware address on the network. E.g., Every computer system has an IP address when it is on a network. An IP address is always unique for all devices connected within a network.

The IP address can be different for the same computer device every time when it gets connected with a network. However, the IP address of a website is always the same that can be used to access a website on the web.

You can access a website either using its web address or IP address. Basically, it is difficult to remember the number of IP addresses compared to website names.

Drawback

We all know that IP address (e.g., 69.171.250.35) is difficult to remember while hostname (facebook.com) is easy to call and remind. Thereby hostname came into existence.

Get IP address of a website from hostname

There are various ways to find out the IP address of any website from its hostname. These are almost similar to the above methods that we discussed. Here, you will see how you can get the IP of a website from hostname. All the above methods and commands are for Windows operating system that you need to run on command prompt (CMD).

See all the methods discussed below:

Method 1: Using ping command

In this method, we will run a ping command to get the hostname of a website using the IP address. So, copy and run the below command on CMD (Command Prompt) in Windows operating system.

For example,

Example 1

Run the command on CMD to get the IP address of Javatpoint using the ping command. The hostname of Facebook is www.javatpoint.com.

Get hostname from IP address

Result

On running the ping command with a hostname, it has returned the IP address of Javatpoint with some other information. The IP address of Javatpoint returned by the ping command is 194.169.80.121.

Example 2

Run the command on CMD to get the IP address of Twitter using the ping command. The hostname of Twitter is www.twitter.com.

Get hostname from IP address

Result

On running the ping command with a hostname, it has returned the IP address of Twitter with some other information. The IP address of Twitter returned by the ping command is 104.244.42.1.

Method 2: Using nslookup command

This is another method to get the IP address from the hostname. Run the nslookup command with the hostname for which you would like to get the IP address. See the syntax to run on command prompt (CMD).

Syntax

For example,

Example 1

Open the command prompt on windows and run the command on it to get the IP address of Facebook. The hostname of Facebook is www.facebook.com.

Get hostname from IP address

Result

On running the nslookup command with a hostname, it has returned the Name, Addresses, and Aliases. The IP address of Facebook returned by the nslookup command is 69.171.250.32.

Example 2

Open the command prompt on windows and run the command on it to get the IP address of Javatpoint. The hostname of Facebook is www.javatpoint.com.

Get hostname from IP address

Result

On running the nslookup command with a hostname, it has returned the Name, Addresses, and Aliases. The IP address of Javatpoint returned by the nslookup command is 69.171.250.32.

All the given methods will help the user to find the hostname from the IP address and vice versa.






Latest Courses