CodeGym /Courses /Docker SELF /DNS Check: commands `nslookup`, `dig`

DNS Check: commands `nslookup`, `dig`

Docker SELF
Level 4 , Lesson 2
Available

DNS Check: commands nslookup, dig

1. Introduction to DNS

Imagine this: you wanna access your favorite website — like google.com. But your browser doesn’t understand the word "google"; it needs IP addresses (for example, 142.250.74.206). Converting a domain name to an IP address happens with DNS (Domain Name System). If this process breaks, you’ll see a browser message like: "Server not found". As a future Linux network guru, you gotta know how to diagnose and fix DNS-related issues.

DNS is like the internet’s phone book. Instead of remembering those complicated IP addresses, we use easy names, which the DNS system translates. Here’s some key stuff to know:

  1. DNS records:

    • A record (Address Record): links a domain name to an IPv4 address.
    • AAAA record: links a domain name to an IPv6 address.
    • CNAME record (Canonical Name): points to a domain alias.
    • MX record (Mail Exchange): points to mail-handling servers.
  2. DNS servers:

    • Everyday users typically use their ISP’s DNS servers.
    • Alternatives: public DNS servers like Google (8.8.8.8), Cloudflare (1.1.1.1).
  3. Name resolving:

    • When you type a domain name into your browser, it sends a request to a DNS server to get the IP address.

With this knowledge in your toolkit, you’re ready to dive into the practical magic of DNS using the nslookup and dig commands.


2. Command nslookup

nslookup is a utility that lets us check how DNS works. It's available on most Linux distributions and other operating systems.

Main syntax:

nslookup [options] [domain or IP address]

Simple example:

Let's check the IP address for the site google.com:

nslookup google.com

Output:

Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   google.com
Address: 142.250.74.206

Notes on the output:

  • Server: The DNS server that processed the request.
  • Non-authoritative answer: This means the info was fetched not from the root DNS server but via another server’s cache.

Checking the DNS Server

If you wanna use a specific DNS server, you can specify it when calling the command:

nslookup google.com 8.8.8.8

Here, we explicitly selected Google's DNS server (8.8.8.8).

Practice: Find the IP for a learning site

Try running this command:

nslookup linux.org

Take a look at the results — these are the IP addresses associated with the website's server.


3. Command dig

dig (Domain Information Groper) is a more advanced tool for working with DNS. It provides detailed information about DNS queries and responses.

Main syntax:

dig [domain] [options]

Query example:

dig google.com

Output (main points):

;; Question section:
;google.com.			IN	A

;; ANSWER SECTION:
google.com.		300	IN	A	142.250.74.206

;; Query time: 35 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Oct 19 10:00:00 UTC 2023
;; MSG SIZE  rcvd: 68

Output sections:

  • ANSWER SECTION: IP addresses associated with the domain.
  • Query time: time taken to process the query.
  • SERVER: the DNS server that handled the query.

4. Basic DNS Records and How to Check Them

A Record (IPv4)

dig linux.org A

The result will show IPv4 addresses for the domain.

AAAA Record (IPv6)

dig linux.org AAAA

The output will contain IPv6 addresses. Useful if you're working with modern networks.

MX Record (Mail Servers)

dig linux.org MX

Used to check which servers handle mail correspondence for the domain.


5. Advanced Practice: dig vs nslookup

Now you can compare the results of the two commands:

  1. Run:

        nslookup linux.org
    
  2. Then:

        dig linux.org
    

Note that dig provides more details. For example, you can see the query execution time as well as information about the server that responded to the request.


6. Checking Google's DNS Server

Task:

  1. Using nslookup, check if Google's public DNS server is working:

    nslookup github.com 8.8.8.8
    
  2. Now do the same with dig:

    dig @8.8.8.8 github.com
    
  3. Check if the site has IPv6 addresses:

    dig github.com AAAA
    

7. Common Errors and Features

Working with DNS almost always involves these common problems:

  1. Incorrect DNS server settings: If your DNS server isn't working or is configured incorrectly, you might not get a response. Check the server's availability by manually specifying its IP when using nslookup or dig.
  2. DNS Caching: Sometimes changes to DNS can take time due to caching. For instance, you may see outdated information if a DNS record was recently updated.

  3. DNS Server Unavailability: If you see an error like connection timed out; no servers could be reached, it might mean the server is unavailable or blocked.

  4. Alternative Commands: nslookup isn't always available in minimal Linux setups, while dig is more commonly part of the default toolset.

Practical Knowledge Use: Why Know This?

  • Diagnosing DNS Issues. You'll quickly figure out why your browser "can't see" a website.
  • Server Configuration. When setting up a cloud server, you need to check if DNS records are configured correctly.
  • Internet Security. Knowing how to work with DNS records helps analyze phishing websites.
  • Job Interviews. Knowing dig and nslookup commands is a standard question for Linux/DevOps professionals.

Now you're armed with everything you need for deep understanding and DNS diagnostics. Fire up your terminal, try out the commands, and let no "DNS failure" catch you off guard.

1
Task
Docker SELF, level 4, lesson 2
Locked
Check the availability of a website using nslookup
Check the availability of a website using nslookup
1
Task
Docker SELF, level 4, lesson 2
Locked
Determining domain mail servers
Determining domain mail servers
1
Task
Docker SELF, level 4, lesson 2
Locked
Checking IPv6 addresses for a website
Checking IPv6 addresses for a website
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION