Monday, April 23, 2012

Linux / Unix: Look Up IP Addresses

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

No comments:

Post a Comment