Linux / Unix: Look Up IP Addresses

in Categories , last updated April 13, 2011

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
$ dig
$ nslookup
Replace server1 with the name of the server or workstation you want to look up, and 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
$ host
Sample outputs: has address has IPv6 address 2607:f0d0:1002:51::4

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

; <<>> DiG 9.7.0-P1 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29656
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 4

;		IN	A


;; AUTHORITY SECTION:		53113	IN	NS		53113	IN	NS		53113	IN	NS		53113	IN	NS

;; ADDITIONAL SECTION:	52988	IN	A	52989	IN	A	52988	IN	A	52988	IN	A

;; Query time: 0 msec
;; WHEN: Thu Apr 14 02:35:41 2011
;; MSG SIZE  rcvd: 201

The nslookup command is used to query
$ nslookup
Sample outputs:


Non-authoritative answer:

See also

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 1 comments/add one below):

1 comment

  1. 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.

    Have a question? Post it on our forum!