Linux / Unix: Look Up IP Addresses

by on April 13, 2011 · 1 comment· LAST UPDATED April 13, 2011

in

How can I look up IP addresses under UNIX or Linux operating systems using command line options?

You can use the following commands to lookup up an IP address:

[a] host command

[b] dig command

[c] nslookup command

You also need to know the full name of the server or workstation (PC) you are looking up. Open a command-line terminal (select Applications > Accessories > Terminal), and then type one of the following commands at the Linux / UNIX shell:
$ host server1.nixcraft.com
OR
$ dig server1.nixcraft.com
OR
$ nslookup server1.nixcraft.com
Replace server1 with the name of the server or workstation you want to look up, and nixcraft.com with the actual domain name. Please note that the nslookup command may be removed from many Linux distros and UNIX operating systems, so use host or dig to look up IP addresses. In this example lookup an IP addresses for www.cyberciti.biz:
$ host www.cyberciti.biz
Sample outputs:

www.cyberciti.biz has address 75.126.153.206
www.cyberciti.biz has IPv6 address 2607:f0d0:1002:51::4

The dig command is used to find out an IP address of www.cyberciti.biz:
$ dig www.cyberciti.biz
Sample outputs:

; <<>> DiG 9.7.0-P1 <<>> www.cyberciti.biz
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29656
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 4
;; QUESTION SECTION:
;www.cyberciti.biz.		IN	A
;; ANSWER SECTION:
www.cyberciti.biz.	571513	IN	A	75.126.153.206
;; AUTHORITY SECTION:
cyberciti.biz.		53113	IN	NS	ns2.p24.dynect.net.
cyberciti.biz.		53113	IN	NS	ns1.p24.dynect.net.
cyberciti.biz.		53113	IN	NS	ns3.p24.dynect.net.
cyberciti.biz.		53113	IN	NS	ns4.p24.dynect.net.
;; ADDITIONAL SECTION:
ns1.p24.dynect.net.	52988	IN	A	208.78.70.24
ns2.p24.dynect.net.	52989	IN	A	204.13.250.24
ns3.p24.dynect.net.	52988	IN	A	208.78.71.24
ns4.p24.dynect.net.	52988	IN	A	204.13.251.24
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Apr 14 02:35:41 2011
;; MSG SIZE  rcvd: 201

The nslookup command is used to query www.cyberciti.biz:
$ nslookup www.cyberciti.biz
Sample outputs:

Server:		127.0.0.1
Address:	127.0.0.1#53
Non-authoritative answer:
Name:	www.cyberciti.biz
Address: 75.126.153.206

See also

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 NinjaSysadmin June 22, 2011 at 2:13 pm

If you know the IP Address but not the name, you can run dig -x and providing a Reverse DNS entry exists (why shouldn’t it) then you’ll get a response.

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous Faq:

Next Faq: