dig

The nslookup command has been deprecated. Instead, a new, more powerful command – dig (domain information groper) – should be used. On some newer Linux servers the nslookup command may not be even available.

Here is an example; to check the name resolution of the host oracle.com, you use the following command:

# dig oracle.com
; DiG 9.2.4  oracle.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER;; flags: qr rd ra; QUERY: 1,  ANSWER: 1, AUTHORITY: 8, ADDITIONAL: 8
 
;; QUESTION SECTION:
;oracle.com.                    IN      A
 
;; ANSWER SECTION:
oracle.com.             300     IN      A       141.146.8.66
 
;; AUTHORITY SECTION:
oracle.com.             3230    IN      NS      ns1.oracle.com.
oracle.com.             3230    IN      NS      ns4.oracle.com.
oracle.com.             3230    IN      NS      u-ns1.oracle.com.
oracle.com.             3230    IN      NS      u-ns2.oracle.com.
oracle.com.             3230    IN      NS      u-ns3.oracle.com.
oracle.com.             3230    IN      NS      u-ns4.oracle.com.
oracle.com.             3230    IN      NS      u-ns5.oracle.com.
oracle.com.             3230    IN      NS      u-ns6.oracle.com.
 
;; ADDITIONAL SECTION:
ns1.oracle.com.         124934  IN      A       148.87.1.20
ns4.oracle.com.         124934  IN      A       148.87.112.100
u-ns1.oracle.com.       46043   IN      A       204.74.108.1
u-ns2.oracle.com.       46043   IN      A       204.74.109.1
u-ns3.oracle.com.       46043   IN      A       199.7.68.1
u-ns4.oracle.com.       46043   IN      A       199.7.69.1
u-ns5.oracle.com.       46043   IN      A       204.74.114.1
u-ns6.oracle.com.       46043   IN      A       204.74.115.1
 
;; Query time: 97 msec
;; SERVER:  10.14.1.58#53(10.14.1.58)
;; WHEN: Mon Dec 29 22:05:56  2008
;; MSG SIZE  rcvd: 328
From the mammoth output, several things stand out. It shows that the command sent a query to the nameserver and the host got a response back from the nameserver. The name resolution was also done at some other nameservers such as ns1.oracle.com. It shows that the query took 97 milliseconds.

If the size of the output might not make it all that useful, you can use the +short option to remove all those verbose output:

# dig +short oracle.com
141.146.8.66
You can also use the IP address to reverse lookup the host name from the IP address. The -x option is used for that.

# dig -x 141.146.8.66
The +domain parameter is useful when you are looking for a host inside a domain. For instance, suppose you are searching for the host otn in the oracle.com domain, you can either use:

# dig +short otn.oracle.com
Or you can use the +domain parameter:

# dig +short +tcp  +domain=oracle.com otn
www.oracle.com.
www.oraclegha.com.
141.146.8.66

Usage for the Oracle User

The connectivity is established between the app server and the database server.
The TNSNAMES.ORA file, used by SQL*Net may look like this:

prodb3 =
  (description =
    (address_list =
      (address = (protocol = tcp)(host = prolin3)(port = 1521))
    )
    (connect_data =
      (sid = prodb3)
    )
  )

The host name prolin3 should be able to be resolved by the app server. Either this should be in the /etc/hosts file; or the host prolin3 should be defined in the DNS.

To make sure the name resolution works and works correctly to point to the right host, you can use the dig command.

With these two commands you can handle most of the tasks involved with network in a Linux environment.

nslookup

Every reachable host in a network should have an IP address, which identifies it uniquely in the network. In the internet, which is a big network anyway, IP addresses allow the connections to reach servers running Websites, e.g. www.oracle.com. So, when one host (such as a client) wants to connect to another (such as a database server) using its name and not the IP address, how does the client browser know which IP address to connect to?

The mechanism of translating the host name to IP addresses is known as name resolution. In the most rudimentary level, the host has a special file called hosts, which stores the IP Address – Hostname pairs. Here is an example file:

# cat /etc/hosts
# Do not remove the following  line, or various programs
# that require network  functionality will fail.
127.0.0.1       localhost.localdomain       localhost
192.168.1.101   prolin1.proligence.com      prolin1
192.168.1.102   prolin2.proligence.com      prolin2
This shows that the hostname prolin1.proligence.com is translated to 192.168.1.101. The special entry with the IP address 127.0.0.1 is called a loopback entry, which points back to the server itself via a special network interface called lo (which you saw earlier in the ifconfig and netstat commands).

Well, this is good, but you can’t possibly put all the IP addresses in the world in this file. There should be another mechanism to perform the name resolution. A special purpose server called a nameserver performs that role. It’s like a phonebook that your phone company provides; not your personal phonebook. There may be several nameservers available either inside or outside the private network. The host contacts one of the nameservers first, gets the IP address of the destination host it want to contact, and then attempts to connect to the IP address.

How does the host know what these nameservers are? It looks into a special file called /etc/resolv.conf to get that information. Here is a sample resolv file.

; generated by  /sbin/dhclient-script
search proligence.com
nameserver 10.14.1.58
nameserver 10.14.1.59
nameserver 10.20.223.108

How do you make sure that the name resolution is working fine for a specific host name? In other words, you want to make sure that when the Linux system tries to contact a host called oracle.com, it can find the IP address on the nameserver. The nslookup command is useful for that. Here is how you use it:

# nslookup oracle.com
Server:         10.14.1.58
Address:        10.14.1.58#53
Non-authoritative answer:
Name:   oracle.com
Address: 141.146.8.66

Let’s dissect the output. The Server output is the address of the nameserver. The name oracle.com resolves to the IP address 141.146.8.66. The name was resolved by the nameserver shown next to the word Server in the output.

If you put this IP address in a browser–http://141.146.8.66 instead of http://oracle.com–the browser will go the oracle.com site.

If you made a mistake, or looked for a wrong host:

# nslookup oracle-site.com
Server:         10.14.1.58
Address:        10.14.1.58#53
** server can’t find  oracle-site.com: NXDOMAIN

The message is quite clear: this host does not exist.

 
(Extracted from oracle technet notes author Arup Nanda)