We can use a few commands with server “hostname” to find the corresponding public IP address associated with that. Here are the ways to use the command line on Linux, Windows, or macOS to get the hostname IP address.
Using the nslookup Command
The first command tool is “nslookup,” which is commonly used to query the Domain Name System (DNS) and obtain a domain name or IP address mapping.
nslookup hostname
Note: In each command, replace the “hostname” with your actual hostname, the public IP address you want to discover.
![nslookup hostname find public ip address](https://linux.how2shout.com/wp-content/uploads/2024/08/nslookup-hostname-find-public-ip-address.webp)
Using the dig Command
Next, we can use the DIG command if NSLOOKUP doesn’t work for you. It is also used for querying DNS name servers; DIG stands for Domain Information Groper. Here is the command to follow:
dig +short hostname
If you replace the “hostname,” for example, with google.com, you will receive the public IP address in return for the given hostname.
![DIG command to lookup DNS](https://linux.how2shout.com/wp-content/uploads/2024/08/DIG-command-to-lookup-DNS.webp)
Using the host Command
We can also use the host command on Linux to perform the DNS lookup and get the IP address assigned to the hostname you want to check. Just use your actual hostname in the given command, and it will show the public IP address.
host hostname
![host Command to get public address](https://linux.how2shout.com/wp-content/uploads/2024/08/host-Command-to-get-public-address.webp)
Using ping Command
Ping is the most commonly used command to confirm whether two devices or PCs can communicate with each other. However, we can also use it to find the IP address of a hostname by sending ICMP echo request packets. The hostname’s IP address will appear in the ping output.
ping -c 1 hostname
![Ping command to find Public Ipaddress](https://linux.how2shout.com/wp-content/uploads/2024/08/Ping-command-to-find-Public-Ipaddress.webp)
Using getent Command
The getent command can fetch entries from the administrative database, including DNS information.
getent ahosts hostname
![getent Command to find hostname public ipaddress](https://linux.how2shout.com/wp-content/uploads/2024/08/getent-Command-to-find-hostname-public-ipaddress.webp)
Other Articles: