Skip to content

Beginner · Networking for security · topic 9 of 43 · 30 min

DNS: the internet's phone book

Explanation

DNS (Domain Name System) turns names like example.com into IP addresses. Nearly every connection starts with a DNS lookup, so DNS logs show where every device is trying to go. Attackers abuse DNS with look-alike domains, hijacked records and hidden data, and email security checks (SPF, DKIM, DMARC) live in DNS too.

Why DNS matters to defenders

Computers talk using IP addresses, but people remember names. DNS (Domain Name System) is the system that answers "what is the IP address of this name?". Because almost every connection starts with a DNS question, DNS logs are one of the best ways to see which websites and servers a device is reaching, including malware calling its control server.

How a lookup works

  1. Your laptop asks its resolver (usually your router, your ISP or a public resolver) "what is the address of shop.example?"
  2. If the resolver does not already have the answer cached (saved), it asks a root server, which points to the server for .example.
  3. That server points to the authoritative name server for shop.example, which knows the real answer.
  4. The resolver returns the answer to you and caches it for the time set by the TTL (time to live).
Think of it like this: Like asking at a railway enquiry counter. The clerk does not know every train, so she phones the zonal office, which phones the right station, and then she remembers the answer for the next person who asks today.

Record types

TypeWhat it holdsExample
AIPv4 addressshop.example → 203.0.113.10
AAAAIPv6 addressshop.example → 2001:db8::10
CNAMEAn alias pointing to another namewww.shop.example → shop.example
MXMail server for the domain10 mail.shop.example
TXTFree text, used for email security and ownership checks"v=spf1 ... -all"
NSWhich servers are authoritative for the domainns1.provider.example
bash
$ dig shop.example A +short
203.0.113.10
$ dig shop.example MX +short
10 mail.shop.example.
$ dig _dmarc.shop.example TXT +short
"v=DMARC1; p=reject; rua=mailto:dmarc@shop.example"
dig on Linux asks DNS directly. +short shows only the answer.
powershell
PS> Resolve-DnsName shop.example -Type A

Name           Type   TTL   Section    IPAddress
----           ----   ---   -------    ---------
shop.example   A      300   Answer     203.0.113.10
The same lookup on Windows. nslookup works on both systems too.

DNS normally uses UDP port 53, and TCP port 53 for large answers and zone transfers. Newer encrypted forms are DNS over HTTPS (DoH, port 443) and DNS over TLS (DoT, port 853).

Email security records

  • SPF (Sender Policy Framework): a TXT record listing which servers may send mail for the domain.
  • DKIM (DomainKeys Identified Mail): the sending server signs each email; the public key to check the signature is published in DNS.
  • DMARC: a TXT record at _dmarc.domain that tells receivers what to do when SPF and DKIM checks fail: p=none (only report), p=quarantine (send to spam) or p=reject (refuse).

A domain with p=reject is much harder to spoof in phishing emails. Many banks and government domains now publish strict DMARC policies.

How attackers abuse DNS (and how it is detected)

  • Look-alike domains (typosquatting), such as a letter swapped or added. Detect: watch new domain registrations similar to your brand, and block newly registered domains.
  • DNS hijacking: changing a domain's records at the registrar after stealing the account login. Prevent: MFA and registrar lock on domain accounts.
  • Cache poisoning: feeding a resolver a fake answer. Prevent: DNSSEC (signed DNS answers) and up-to-date resolvers.
  • DNS tunnelling: hiding data inside many long, random-looking sub-domain queries. Detect: very long names, many unique sub-domains for one domain, and unusual volumes of TXT queries.

Common mistakes

  • Leaving DMARC at p=none forever. It only reports; it does not stop spoofing.
  • Forgetting that DNS is often not logged. Turn on resolver logging so investigations can see lookups.
  • Thinking a domain is safe because it resolves. Every phishing site resolves too.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

DNS: the internet's phone book · 1/7

Name → IP address

DNS turns names into IP addresses. Almost every connection starts with a DNS lookup.

Prefer a video by a teacher? Find free videos on “how DNS works explained SPF DKIM DMARC for beginners” on YouTube ↗

In real life: Malware found through DNS logs

A SOC at an Indian bank reviews DNS logs every morning. One laptop made 4,000 lookups overnight for names like a8f3k2...data.update-check.example, each with a long random first part. Normal software does not do that. The analyst isolates the laptop and finds malware that was sending data out hidden in DNS queries. The firewall alone did not notice, because DNS traffic was allowed.

Practice (0/3 done)

Task 1 · Question

Which DNS record type tells the world where to deliver email for a domain?

Task 2 · Code · Python

Write dmarc_policy(record) that reads a DMARC TXT record like "v=DMARC1; p=reject; rua=mailto:d@shop.example" and returns the value of p ("none", "quarantine" or "reject"). If the record does not start with "v=DMARC1" or has no p tag, return None. Tags are separated by ";" and may have spaces around them.

Task 3 · Code · Python

A simple DNS tunnelling check: write long_labels(names, limit) that returns the names (in the same order) where ANY label (the parts between dots) is longer than limit characters.

Quick quiz

Question 1

1.Which port does classic DNS use?

Question 2

2.What does DMARC p=reject tell a receiving mail server?

Question 3

3.What is TTL in a DNS answer?

Question 4

4.Thousands of queries for long random sub-domains of one domain may indicate…

Question 5

5.Which protects a domain's DNS records from being changed by someone who stole the registrar login?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which port does classic DNS use?

Answer: 53

DNS uses port 53 (UDP mostly, TCP for big answers). DoT uses 853 and DoH uses 443.

What does DMARC p=reject tell a receiving mail server?

Answer: Refuse mail that fails the SPF/DKIM checks for this domain

p=reject asks receivers to refuse unauthenticated mail claiming to be from the domain.

What is TTL in a DNS answer?

Answer: Time to live: how long the answer may be cached

TTL is how many seconds resolvers may reuse the answer.

Thousands of queries for long random sub-domains of one domain may indicate…

Answer: DNS tunnelling (data hidden in DNS)

Long random labels and high volume to one domain is a classic tunnelling sign.

Which protects a domain's DNS records from being changed by someone who stole the registrar login?

Answer: MFA and registrar lock on the domain account

Hijacking happens at the registrar, so protect that account.

Which record tells other mail servers where to deliver email for a domain?Related

Answer: MX

MX records name the mail servers; the lowest preference number is tried first.

From DNS: names to addresses

What does DNS do?Related

Answer: Turns a domain name into an IP address

DNS works like a contacts list: you give it a name and it finds the IP address of the server.

From Clients, servers, IP addresses and URLs

Which Sysmon Event ID records process creation?Related

Answer: 1

Sysmon Event ID 1 is process creation, with command line and hashes.

From Logs and log sources

You will move a website to new servers tomorrow. What should you do today with its DNS record?Related

Answer: Lower the TTL, for example to 60 seconds

A short TTL makes resolvers pick up the new address quickly after the change.

From DNS and CDN: Route 53 and CloudFront

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 1 more topic in “Networking for security” before its exam: HTTP, HTTPS and TLS.
  2. Module 2 exam: Networking for security · 12 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Systems and cryptography. 43 topics left in the course before the final exam.

← Previous: Ports and protocols