UnixDroid

Lesson 3 of 5 · 7 min

DNS: the internet’s phone book

How a domain name becomes an IP address, the record types you will query most, and how attackers abuse DNS.

Computers talk using IP addresses, but people remember names. DNS (Domain Name System) connects the two. Every time you open a website, DNS works quietly in the background first.

The steps a DNS lookup takes from your browser to the authoritative server
The steps a DNS lookup takes from your browser to the authoritative server

Query DNS yourself

dig unixdroid.com              # full answer
dig +short unixdroid.com       # just the IP
dig @1.1.1.1 unixdroid.com     # ask a specific resolver
dig +trace example.com         # watch every step from the root
nslookup unixdroid.com         # works on Windows too

dig +trace is the best way to see the diagram above happen for real.

Record types you'll use

TypeHoldsExample use
AIPv4 addressWhere the website lives
AAAAIPv6 addressSame, for IPv6
CNAMEAnother name (alias)www pointing to the main domain
MXMail serverWhere email for the domain goes
TXTFree textEmail security (SPF, DMARC), ownership checks
NSName serversWho is in charge of the domain

How attackers abuse DNS

  • Typosquatting: registering unixdorid.com and waiting for people to mistype.
  • DNS spoofing: feeding a victim a fake answer so the real name points to the attacker's server.
  • Subdomain discovery: during recon, finding forgotten hosts like old-admin.example.com.
  • DNS tunnelling: hiding data inside DNS queries to sneak it past firewalls.

The hosts file

Before asking DNS, your computer checks a local file: /etc/hosts on Linux, C:\Windows\System32\drivers\etc\hosts on Windows. Malware sometimes edits it to send banking sites to fake servers, so it's worth checking on a suspicious machine.

DNS answers are cached for a time called the TTL. That's why a change to a domain can take a while to show up everywhere.

Try it yourself
  1. Run dig +short for three websites you use and write down their IPs.
  2. Run dig example.com MX and dig example.com TXT. What do you find?
  3. Run dig +trace example.com and match each block of output to a step in the diagram.
  4. Open your hosts file and check it has nothing unexpected in it.
No Linux machine? Practise in the free online terminal

Quick check

Which DNS record type holds a domain’s IPv4 address?

Need a hint?

It is a single letter.

Finished this lesson?

Done lessons keep your daily streak going 🔥

0 day streak

0 lessons done

best 0 days

Log in to keep your streak on every device →