Skip to main content
Engineering LibreTexts

10-F.11.2: Network Troubleshooting Commands - dig / nslookup / host

  • Page ID
    40970
  • The dig Command

    The dig command stands for Domain Information Groper. It is a network administration command-line tool for querying the Domain Name System (DNS). The dig command is useful for network troubleshooting and for educational purposes. It can operate based on command line option and flag arguments, or in batch mode by reading requests from an operating system file. When a specific name server is not specified in the command invocation, it uses the operating system's default resolver, usually configured in the file resolv.conf. Without any arguments it queries the DNS root zone.

    Syntax:

    dig [ OPTIONS ]

    dig is very easy to use, and works well without any options. The following example is a simple lookup of the IP address for the server specified on the command line - deltacollege.edu. The lines that begin with a semi-colon provide comments about the output.

    pbmac@pbmac-server $ dig deltacollege.edu
    ; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> deltacollege.edu
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64205
    ;; flags: qr rd ra; QUERY: 1, Answer: 1, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 512
    ;; QUESTION SECTION:
    ;deltacollege.edu.        IN    A
    
    ;; Answer SECTION:
    deltacollege.edu.    3599    IN    A    52.36.131.229
    
    

    The nslookup Command

    nslookup is a network administration command-line tool available in many computer operating systems for querying the Domain Name System (DNS) to obtain domain name or IP address mapping, or other DNS records. The name "nslookup" means "name server lookup."

    The command does not use the operating system's local Domain Name System resolver library to perform its queries, and thus may behave differently from dig, which it does. Additionally, vendor-provided versions may include output of other sources of name information, such as host files and Network Information Service. Some behaviors of nslookup may be modified by the contents of resolv.conf.

    Syntax:

    nslookup [ OPTION ] [name | -] [server]

    It is possible to use nslookup in a command line mode, or an interactive mode. In the first example the command prints output and returns to the system prompt. In the second example issuing nslookup alone takes the user to a command prompt where command specific input can be entered.

    pbmac@pbmac-server $ nslookup deltacollege.edu
    Server:        8.8.8.8
    Address:    8.8.8.8#53
    
    Non-authoritative answer:
    Name:    deltacollege.edu
    Address: 52.36.131.229
    
    pbmac@pbmac-server $ nslookup
    > deltacollege.edu
    Server:        8.8.8.8
    Address:    8.8.8.8#53
    
    Non-authoritative answer:
    Name:    deltacollege.edu
    Address: 52.36.131.229
    >
    

    The host Command

    The host command in Linux system is used for DNS (Domain Name System) lookup. It is used to find the IP address of a particular domain name, or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more specific details of a domain by specifying the corresponding option along with the domain name.

    Syntax:

    host [ OPTIONS ] hostname

    Without a hostname the command will print out the command options.

    Using the -v option generates a very verbose output - gives a lot of information.

    pbmac@pbmac-server $ host -v deltacollege.edu
    Trying "deltacollege.edu"
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53400
    ;; flags: qr rd ra; QUERY: 1, Answer: 1, AUTHORITY: 0, ADDITIONAL: 0
    ;; QUESTION SECTION:
    ;deltacollege.edu.        IN    A
    
    ;; Answer SECTION:
    deltacollege.edu.    3599    IN    A    52.36.131.229
    Received 50 bytes from 8.8.8.8#53 in 164 ms
    Trying "deltacollege.edu"
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4462
    ;; flags: qr rd ra; QUERY: 1, Answer: 0, AUTHORITY: 1, ADDITIONAL: 0
    
    ;; QUESTION SECTION:
    ;deltacollege.edu.        IN    AAAA
    ;; AUTHORITY SECTION:
    deltacollege.edu.    1799    IN    SOA    sdc-ns2.deltacampus.net. hostmaster.deltacollege.edu. 2015121323 1200 600 1209600 3600
    
    Received 104 bytes from 8.8.8.8#53 in 187 ms
    Trying "deltacollege.edu"
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41683
    ;; flags: qr rd ra; QUERY: 1, Answer: 4, AUTHORITY: 0, ADDITIONAL: 0
    
    ;; QUESTION SECTION:
    ;deltacollege.edu.        IN    MX
    
    ;; Answer SECTION:
    deltacollege.edu.    3599    IN    MX    20 mailin.deltacollege.edu.
    deltacollege.edu.    299    IN    MX    15 mailin1.deltacollege.edu.
    deltacollege.edu.    3599    IN    MX    5 deltacollege-edu.mail.protection.outlook.com.
    deltacollege.edu.    3599    IN    MX    15 mailin3.deltacollege.edu.
    Received 165 bytes from 8.8.8.8#53 in 133 ms
    

    Adapted from:
    "dig (command)" by Multiple ContributorsWikipedia is licensed under CC BY-SA 3.0
    "host command in Linux with examples" by sethusubramanian, Geeks for Geeks is licensed under CC BY-SA 4.0