Skip to content
ryancamargoRyan Camargo — home
All posts
networking~6min readRyan Camargo

DNS: how names become IP addresses

What DNS is, how a lookup works, and why DNS security matters.

#networking#dns#cybersecurity

When you type example.com into your browser, your computer needs an IP address to connect. DNS is the system that turns the name into that address.

Think of it like a phone book. You know the name. DNS finds the number.

Why DNS is not one big list

Every computer needs an IP address to talk to another computer. You could keep every name and address in one file, but that file would be huge, it changes all the time, and every connection would need to read it.

So DNS is split into many parts. Each part is controlled by a different organization. That part is called a zone. example.com is a zone. .com is a bigger zone above it. The root is the biggest zone.

What happens when you open a website

You type https://example.com. Before the browser can connect, it needs the IP address for example.com.

1. Your computer asks for the address

Your browser does not do DNS by itself. It asks your operating system. The OS uses a small program called a stub resolver. That program's only job is to ask the next server.

The stub resolver needs to know who to ask. On Linux, that setting is in /etc/resolv.conf. It may come from your Wi-Fi router, or you may have set it yourself, like 1.1.1.1 or 8.8.8.8.

Some browsers, like Chrome and Firefox, can use their own DNS service. That is why dig and your browser can give different answers.

2. The recursive resolver does the work

The next server is the recursive resolver. It is like a helper who calls around until it finds the answer.

If it already knows the address, it answers right away. If not, it asks three places:

  1. A root server: "Who handles .com?"
  2. A .com server: "Who handles example.com?"
  3. The server that owns example.com: "What is the IP address?"

The first two answers are referrals. A referral is not the answer. It is a pointer to the next server to ask.

Every answer is saved for a short time. That time limit is called a TTL. Saving answers is called caching. Caching makes DNS fast.

3. The authoritative server answers

The server that owns the zone is called an authoritative server. It is the source of truth for that zone. It answers from its own records or says no.

Most zones have more than one authoritative server. If one fails, the others can still answer.

The records you will see

DNS stores different kinds of records. The record type tells you what kind of information it holds. The addresses below are examples.

Type What it means Example
A IPv4 address for a name 192.0.2.1
AAAA IPv6 address for a name 2001:db8::1
CNAME A nickname for another name www.example.com → example.com
MX Mail server, with a priority 10 mail.example.com
TXT Free text (SPF, DKIM, verification) "v=spf1 -all"
NS The name servers for a zone a.iana-servers.net
SOA Zone information: serial, refresh, retry, expire, minimum
PTR Reverse lookup: IP → name 1.2.0.192.in-addr.arpa → example.com

A CNAME is a nickname. A name with a CNAME cannot have any other record. That is why you normally cannot put one at the apex, the bare example.com. Some providers work around this with "flattening" or records like ALIAS and ANAME.

Look up a name yourself

dig is a command that asks DNS questions. It is already on macOS. On Debian or Ubuntu, install dnsutils. On Fedora or RHEL, install bind-utils.

In the examples, $ is the prompt. Do not type it.

# Ask your normal resolver for the A record.
dig example.com

# Ask a specific resolver.
dig @1.1.1.1 example.com

# Show only the answer.
dig +short example.com AAAA

# Follow the chain from the root.
dig +trace example.com

# Look at TXT records.
dig +short TXT example.com

A +short answer shows only the data:

$ dig +short example.com
192.0.2.1

Your answer will be different. A full dig answer has a header, a question, an answer, and more. The field to watch is status:

$ dig example.com
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4242
;; ANSWER SECTION:
example.com.  300  IN  A  192.0.2.1

NOERROR means the name exists. NXDOMAIN means the name does not exist in that zone.

DNS security

DNS was made when people trusted the network. It had no way to prove an answer was real, and no privacy. Security work added both.

Fake answers

An attacker can try to send a fake answer before the real one arrives. This is called spoofing. If the fake answer gets saved, the bad answer can spread. That is cache poisoning.

In 2008, the Kaminsky attack showed this could be done from far away. The fix was to randomize the numbers used in each request. That made the attack much harder. DNSSEC goes further.

DNSSEC

DNSSEC adds a signature to DNS answers. A signature is like a wax seal. It proves who made the answer and that nobody changed it.

The trust starts at the root and goes down: root → .com → example.com. Each zone signs its own keys. The parent zone publishes a DS record with a fingerprint of the child's key. That is how the parent says "this child is real."

Not every zone uses DNSSEC. Many do not.

DoT and DoH

Normal DNS is not encrypted. Anyone between you and your resolver can see the names you look up.

  • DoT (DNS over TLS) puts DNS inside an encrypted connection on port 853.
  • DoH (DNS over HTTPS) puts DNS inside normal HTTPS traffic on port 443.

DoT is easier to manage on a network. DoH is harder to block because it looks like normal web traffic.

Both protect the trip, not the answer. A fake answer can still arrive encrypted. You need DNSSEC for that.

A short checklist

  1. Are your resolvers checking DNSSEC?
  2. Are your devices using DoT or DoH?
  3. Are your zones signed?
  4. Do your mail records have SPF, DKIM, and DMARC? SPF lists allowed senders. DKIM signs mail. DMARC says what to do when those checks fail.
  5. Do your mail servers have PTR records? Many receivers reject mail without one.
  6. Are your TTLs reasonable? Long TTLs make changes slow. Short TTLs make attacks like fast flux easier.

Bottom line

DNS turns names into addresses. It does this with zones, resolvers, and caching. DNSSEC proves answers are real. DoT and DoH hide the questions. They solve different problems.

Sources: RFC 1034, RFC 1035, RFC 9364 for DNSSEC, and the PowerDNS docs.

On this page