Beginner 6 min read

๐Ÿ“– What Is DNS? The Phonebook of the Internet

๐Ÿ“˜ What You Will Learn

  • What DNS is and why we need it
  • How a domain name is built (www.example.com)
  • The most common DNS record types (A, AAAA, CNAME, MX, NS, TXT)
  • How to look up DNS records with nslookup and dig
  • How to fix the most common DNS problems

๐Ÿง  What Is DNS?

DNS stands for Domain Name System. It is the phonebook of the internet.

It turns a domain name (like example.com) into an IP address (like 203.0.113.10).

People remember names. Computers need numbers. DNS connects the two.

Simple meaning:

You type   :  www.example.com
DNS finds  :  203.0.113.10
Your browser connects to 203.0.113.10

The IP addresses in this tutorial are example addresses. Real websites have different ones.

๐Ÿ‘‰ New to IP addresses? Read What Is an IP Address? IPv4 vs IPv6 Explained first.

๐Ÿ‘‰ DNS works at the Application layer and uses port 53: UDP for most questions, TCP for bigger jobs. See What Are Network Ports? for ports.

๐Ÿ“ฆ Easy Analogy

Imagine you want to call a friend, but you only remember the name.

You open your contacts app, search the name, and it gives you the number.

Friend's name        =  Domain name
Phone number         =  IP address
Your contacts app    =  DNS

That is DNS. You use the name. DNS finds the number.

๐Ÿค” Why Do We Need DNS?

  • Names are easy to remember. Numbers are not.
  • A website can change its IP address and keep the same name.
  • Without DNS, you would type numbers for every website.

๐Ÿงฉ The Parts of a Domain Name

A domain name is read from right to left.

www  .  example  .  com  .
|       |           |    |
|       |           |    +-- root (the dot at the very end, usually hidden)
|       |           +-------- TLD (top-level domain)
|       +-------------------- domain
+---------------------------- subdomain
  • Root: the top of the DNS tree
  • TLD: the last part, such as .com, .org or .in (India)
  • Domain: the name you register, such as example
  • Subdomain: an extra part in front, such as www

๐Ÿ“‹ Common DNS Record Types

A record is one entry in a domain's DNS data. Each record tells the world one fact about the domain.

Record What it stores Example
A The IPv4 address of a name example.com โ†’ 203.0.113.10
AAAA The IPv6 address of a name example.com โ†’ 2001:db8::10
CNAME An alias that points to another name, not to an IP www.example.com โ†’ example.com
MX The mail server of the domain. A lower number is tried first 10 mail.example.com
NS The nameserver that holds the domain's records ns1.example.com
TXT Text notes, often used for email security v=spf1 -all

You set these records at your domain provider (Cloudflare, GoDaddy, Namecheap and others).

๐Ÿ› ๏ธ Try It: Look Up DNS Records

Step 1: Ask with nslookup

nslookup is built into Windows and works on Linux too.

Windows and Linux:

nslookup example.com

If nslookup is missing on Linux, install it:

sudo apt install dnsutils

Sample output on Linux (yours will differ):

Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   example.com
Address: 203.0.113.10
Name:   example.com
Address: 2001:db8::10

Sample output on Windows (yours will differ):

Server:  dns.google
Address:  8.8.8.8

Non-authoritative answer:
Name:    example.com
Addresses:  2001:db8::10
          203.0.113.10
  • Server: the DNS resolver that answered you. It is the helper that looks up names for you.
  • Non-authoritative answer: the answer came from the resolver, not from the domain's own server. The next tutorial explains why.
  • Address: the IP address (or addresses) of the name

Step 2: Look Closer with dig (Linux)

dig shows more details.

dig example.com

Sample output on Linux (shortened, yours will differ):

; <<>> DiG 9.18.39 <<>> example.com
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18441
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;example.com.                   IN      A

;; ANSWER SECTION:
example.com.            3600    IN      A       203.0.113.10

;; Query time: 23 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)

How to read it:

  • status: NOERROR means the lookup worked. NXDOMAIN means the name does not exist.
  • QUESTION SECTION is what you asked.
  • ANSWER SECTION is the answer: the name, the TTL in seconds (3600), the class IN (Internet), the record type A, and the address.
  • Query time is how long it took. SERVER is the resolver, its port (53) and the protocol (UDP).

The TTL says how long the answer may be saved. The next tutorial explains it.

Step 3: Ask for Other Record Types

Linux:

dig +short example.com AAAA
dig +short example.com MX
dig +short example.com NS
dig +short example.com TXT

+short prints only the answer. Sample output (yours will differ):

2001:db8::10
10 mail.example.com.
ns1.example.com.
"v=spf1 -all"

Windows:

nslookup -type=MX example.com

Sample output on Windows (yours will differ):

Non-authoritative answer:
example.com     MX preference = 10, mail exchanger = mail.example.com

Replace MX with NS, TXT or AAAA to see other records.

example.com is a special name reserved for examples, so its real records may look different. Try a domain you know.

โŒ Common Errors & Solutions

Error / Symptom Cause Fix
NXDOMAIN or Non-existent domain The name does not exist Check the spelling. The domain may not be registered
no servers could be reached or timed out Your computer cannot reach the DNS server Check your internet connection and firewall, then try another resolver
A site opens by IP address but not by name DNS is the problem Switch your DNS to a public resolver such as 8.8.8.8 or 1.1.1.1
dig: command not found (Linux) dig is not installed Run sudo apt install dnsutils
You see a different IP than your friend Large websites give different addresses in different places Normal. Nothing is wrong

๐Ÿ’ก Pro Tip

When a website will not load, check if DNS is the problem.

Ping an IP address, then ping a name:

ping 8.8.8.8
ping google.com

If the IP works and the name fails, DNS is broken.

๐ŸŽฏ Final Summary

- DNS turns domain names into IP addresses (the phonebook of the internet)
- Domain names are read right to left: root, TLD, domain, subdomain
- Records: A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), NS (nameserver), TXT (text)
- DNS uses port 53: UDP for most questions, TCP for bigger jobs
- nslookup works on Windows and Linux
- dig (Linux) shows more detail: dig example.com
- NXDOMAIN = the name does not exist
- If ping by IP works but ping by name fails, DNS is the problem

๐Ÿ“Œ Next Tutorial

How DNS Works : what happens behind the scenes when you press Enter. Resolvers, root servers, caching and TTL.


TechWithJuned ยท Learn โ†’ Execute โ†’ Build

โœ๏ธ Written by TechWithJuned Team

๐Ÿ’ฌ Questions & Discussion

Have a doubt? Ask below โ€” no login needed.

Loading comments...