Tips

How to Find the IP Address of a Website in Linux

Wondering how to get the IP address of a website in Linux? Here are 3 command line utilities to query the DNS and get you the IP address and other details.

Abhishek Prakash
Abhishek Prakash

How do I find the IP address of a website using Linux terminal?

Finding the public IP address of a website’s server is quite easy. In fact, there are several command line tools you can use to find the IP address of a website.

In an earlier article, I showed you how to find IP address in Linux. In this one, I am going to show you some of those commands here.

Commands to find IP address of a website in Linux

Do note that you might have to install some of these utilities mentioned here. Good news is that they are available in the default repositories of most Linux distributions. You can easily install them using the package manager of your distribution.

Method 1: Get website IP address with dig command

Dig is a DNS lookup utility. The sole purpose of this command is to perform DNS lookup and display the answers returned by the nameserver of the queried website.

The syntax is simple.

dig <website>

A sample output for the dig command looks like this:

dig facebook.com

; <<>> DiG 9.11.3-1ubuntu1.5-Ubuntu <<>> facebook.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2224
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;facebook.com.            IN  A

;; ANSWER SECTION:
facebook.com.        198 IN  A   157.240.25.35

;; Query time: 67 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Apr 03 17:57:12 IST 2019
;; MSG SIZE  rcvd: 57

You can see the IP address of the website in the ‘ANSWER SECTION’.

Facebook has tons of servers and you may see a different IP address based on your geo-location and time. You shouldn’t find it unusual.

Method 2: Use nslookup command to find IP address of website in Linux

Like Dig, nslookup command is also used for querying the DNS records. nslookup stands for ‘name server lookup’.

You might need to install nslookup. If you have sudo access, you can use your Linux distribution’s installation command to install this tool. On Debian and Ubuntu, the command below will install nslookup:

sudo apt install nslookup

Once you have the tool, just use it in the following fashion:

nslookup <website>

For example, if I try to get the IP address of Facebook.com, this is the output I get:

nslookup facebook.com
Server:        127.0.0.53
Address:    127.0.0.53#53
Non-authoritative answer:
Name:    facebook.com
Address: 157.240.25.35
Name:    facebook.com
Address: 2a03:2880:f10c:83:face:b00c:0:25de

Method 3:Get IP address of website using host command

Like the above two, host is also a DNS lookup utility. But unlike the above two commands, the output of the host command is neat and precise. It just displays the IPv4 and IPv6 addresses of a website.

You can use it like this:

host <website>

Sample output would be like this:

host facebook.com
facebook.com has address 157.240.13.35
facebook.com has IPv6 address 2a03:2880:f139:83:face:b00c:0:25de
facebook.com mail is handled by 10 msgin.vvv.facebook.com.

Method 4: Get website’s IP address with ping command in Linux

Let’s see how to get the IP address of a website with the ping command in Linux.

Ping command is used to check whether the remote host is up or not. You can use either the server’s IP address or the URL. The syntax is pretty much the same.

ping <website>

A sample output for facebook.com looks like this:

ping facebook.com
PING facebook.com (157.240.24.35) 56(84) bytes of data.
64 bytes from edge-star-mini-shv-01-sin2.facebook.com (157.240.24.35): icmp_seq=1 ttl=52 time=203 ms
64 bytes from edge-star-mini-shv-01-sin2.facebook.com (157.240.24.35): icmp_seq=2 ttl=52 time=163 ms
64 bytes from edge-star-mini-shv-01-sin2.facebook.com (157.240.24.35): icmp_seq=3 ttl=52 time=248 ms
^C
--- facebook.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3001ms
rtt min/avg/max/mdev = 163.965/205.339/248.902/34.713 ms

You’ll have to use Ctrl+C to stop the ping command.

Conclusion

So, you just saw three networking tools that would give you the same result. I hope this quick Linux tip helped you to find the IP address of a website in Linux terminal.

In a related post, you may also read about finding the default gateway IP in Linux.

If you have any questions or suggestions, please leave a comment below. Don’t forget to subscribe to the newsletter and get all the new tutorials once each week, for free.



Join the conversation.