Computing Foundations › How the Internet Works › Day 16
Day 16: IP Addresses, DNS, and Routing
After this lesson you will be able to explain how a machine is addressed, how a name is turned into that address by DNS, and how packets are routed to it — and to diagnose the two most common "can't reach the server" failures by hand with dig, ping, and traceroute.
Hands-on lab for this lesson
Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-016-ip-addresses-dns-and-routing
- Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git cd ai-roadmap-365.github.io - Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
cd labs/sections/computing-foundations/day-016-ip-addresses-dns-and-routing - Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
- Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
bash tests/run_tests.sh # or the test command named in the lab README
You can also open the lab as a local page (works offline, shows the file tree and expected output).
Learning objectives
By the end of this lesson you will be able to:
- Describe IPv4 dotted-quad and IPv6 addresses, the IPv4 address-exhaustion story, and why IPv6 was created
- Distinguish public from private address ranges (10.x, 172.16.x, 192.168.x) and the loopback 127.0.0.1, and read CIDR notation at an intuitive level
- Explain the DNS hierarchy — root, TLD, and authoritative servers — and the role of recursive resolvers, caching, and TTL
- Identify the common DNS record types (A, AAAA, CNAME, MX, TXT) and explain why a CNAME requires a second lookup
- Explain how packets are routed hop by hop between routers and, at a high level, how BGP and autonomous systems stitch networks together
- Use dig, nslookup, traceroute, whois, and ping to resolve names, inspect records, and trace the path to a host
- Diagnose whether a connection failure is a naming (DNS) problem or a reachability (routing) problem
Prerequisites
- Day 15 — What Happens When You Load a Web Page (the end-to-end request overview this lesson zooms into)
- Comfort running commands in a terminal (Days 8–14)
- A computer with a network connection and the dig/traceroute tools (installation covered in the lab)
Why this matters
-
Every service you deploy needs a name pointed at it, and DNS is how you do it.
-
DNS propagation delays are TTLs, not magic, and knowing that turns a mysterious wait into a number you set yourself.
-
“It works on my machine but not from the server” is very often a private address, and you can recognise one by sight after today.
-
A misconfigured DNS record takes a service down globally, in a way no code bug can.
-
Container and cloud networking is this lesson repeated at a smaller scale, with the same vocabulary.
The idea in plain language
-
An IP address is where. A name is what people type. DNS turns one into the other.
-
DNS is a distributed hierarchy, not a single directory. No one machine holds it all.
-
Every answer carries a TTL saying how long it may be cached, which is why the second lookup is instant and why changes take time to spread.
-
Routing is a chain of local decisions. No router knows the whole path; each one picks the next hop and forgets you.
-
The internet is tens of thousands of independent networks agreeing, mostly on trust, about who can reach what.
Historical background
-
Before DNS there was one file.
HOSTS.TXTlisted every machine on the network, maintained by hand at Stanford and copied around. -
That stopped scaling in the early 1980s, when the network grew faster than anyone could edit a file.
-
DNS arrived in 1983 with the idea that made it work: delegate. The root knows who runs
.com, and nothing more. -
IPv4 gave 4.3 billion addresses, which seemed limitless and was not. The last large blocks were allocated in 2011.
-
IPv6 followed with 128-bit addresses — enough that exhaustion is not a meaningful concept — though adoption has taken decades.
-
NAT was the stopgap that worked too well, letting whole networks share one public address and relieving the pressure that would have forced IPv6 sooner.
What it is — and what it is not
DNS is:
- A distributed, cached, hierarchical lookup system.
- Delegated at every level: root, top-level domain, then the domain’s own servers.
- Typed — the same name can return an address, a mail route, or arbitrary text.
DNS is not:
-
Not a single server. There is no “the DNS” to be down, though your resolver can be.
-
Not instant to change. A record’s old value lives in caches until its TTL expires.
-
Not authenticated by default. Plain DNS has no proof the answer is genuine, which is what DNSSEC and encrypted DNS address.
-
Not a directory of what exists. You cannot list a domain’s names; you can only ask about ones you already know.
Why it was created and what problems it solves
-
Humans do not remember numbers. Names are the interface; addresses are the implementation.
-
Addresses change and names should not. Move a service to new hardware and only the record changes.
-
One name can mean several machines, which is how load balancing and failover begin.
-
Delegation lets ownership be distributed. You control your domain’s records without asking anyone.
-
Routing had to work without central coordination, because no single organisation runs the internet — so each router makes one local decision and networks advertise what they can reach.
How it works
Resolving a name
Your computer asks a recursive resolver — your ISP’s, or a public one like
1.1.1.1 — to do the legwork:
-
Root. “Who handles
.com?” The root does not knowexample.com, but it knows the.comservers. There are 13 named root identities,athroughm, each a globally distributed fleet. -
TLD. “Who handles
example.com?” The.comservers refer it to the authoritative name servers the domain’s owner designated. -
Authoritative. That server returns the actual record — an A record giving an IPv4 address, for instance.
-
Answer and cache. The resolver returns the address and remembers it until the TTL expires.
| Record | Purpose | Example |
|---|---|---|
| A | Name to IPv4 address | 93.184.216.34 |
| AAAA | Name to IPv6 address | 2606:2800:220:1:248:1893:25c8:1946 |
| CNAME | Alias: this name is really that name | www.example.com → example.com |
| MX | Where email for the domain goes | 10 mail.example.com |
| TXT | Arbitrary text, for verification and policy | "v=spf1 ..." |
| NS | Delegates the domain to its authoritative servers | a.iana-servers.net |
- A CNAME points to another name, not an address, so the resolver must look that up too. This is how you point a custom domain at a hosting provider without hard-coding an address that may change.
Routing packets
-
Your machine compares the destination with its own network. Local addresses go direct; everything else goes to the default gateway — in a home, your Wi-Fi router.
-
From there the packet hops. Each router reads the destination, consults its routing table, forwards to the best next hop, and forgets about it.
-
No router plans the whole route. A packet may cross a dozen routers run by several companies.
-
Autonomous systems are large networks under single control, each with a number — an ISP, a university, a cloud provider.
-
BGP is how they agree. Each system advertises which address blocks it can reach, and those advertisements propagate.
-
BGP runs largely on trust, which is why a bad advertisement can misroute a region’s traffic — the “BGP leak” you occasionally see in the news.
Watching the hops
-
tracerouteexploits the hop limit carried in every IP packet — confusingly also called TTL, but a different one from the DNS field. -
Each router decrements it; at zero, the packet is discarded and an error returned.
-
Send with a limit of 1, then 2, then 3, and each elicits a reply from one more router along the path.
An everyday analogy
The postal system.
| The post | The network |
|---|---|
| A person’s name in a directory | A domain name |
| Their street address | An IP address |
| Directory enquiries | A recursive resolver |
| ”Ask the county office” | Delegation to a TLD |
| The local sorting office | Your default gateway |
| Each office deciding the next van | Routing, hop by hop |
| An internal room number | A private address |
-
No sorting office knows the whole route. Each one decides which van the parcel goes on next, and that is enough.
-
A room number is meaningless outside the building, which is exactly what a private address is.
-
The directory is cached in your memory for a while, which is a TTL.
Examples in practice
-
A new site not resolving yet: the old record’s TTL has not expired in some caches. Lower the TTL before a planned change, not after.
-
digshowing a CNAME chain three names deep, each costing another lookup. -
A server that reaches your laptop’s IP and gets nothing: the address is private, and not routable from outside your network.
-
127.0.0.1working while the machine’s real address does not: the service is bound to loopback only, so nothing outside can reach it. -
A traceroute that stops answering halfway: routers are not obliged to reply, and the path is usually fine.
Implications: security, privacy, performance, scalability, and cost
-
Security: DNS hijacking sends you to the wrong server with everything else looking correct. DNSSEC signs answers; encrypted DNS hides the questions.
-
Domain registrar access is production access. Anyone who can change your NS records controls where your traffic goes, and can obtain certificates in your name.
-
Privacy: your resolver sees every name you look up. That is a complete browsing history, held by whoever runs it.
-
Performance: DNS is on the critical path of the first request. A slow authoritative server delays everything after it.
-
A low TTL costs lookups; a high TTL costs agility. Choose deliberately: low before a migration, higher afterwards.
-
Cost: a lapsed domain registration is the cheapest catastrophic failure available. Set it to auto-renew and check the card on file.
Subnets and CIDR, briefly
-
A subnet is a contiguous block of addresses sharing a leading prefix, treated as one local network.
-
CIDR notation writes the block as an address, a slash, and a number —
192.168.1.0/24— where the number says how many leading bits are fixed. -
A
/24fixes 24 of 32 bits, leaving 8 for hosts: 256 addresses. -
A
/16fixes 16, holding 65,536. Each smaller number after the slash doubles the block. -
This is how routers summarise: one entry saying “everything in
93.184.216.0/24goes this way” stands in for 256 addresses.
| Range | Kind | Where it is used |
|---|---|---|
10.0.0.0/8 | Private | Large internal networks; ~16.7 million addresses |
172.16.0.0/12 | Private | Medium internal networks |
192.168.0.0/16 | Private | Home and small office |
127.0.0.0/8 | Loopback | This machine itself |
| Everything else routable | Public | Globally reachable, assigned by registries |
-
Private addresses are never routed on the public internet. A router performs NAT so many private devices share one public address.
-
Recognising a private address by sight explains a great many “works on my machine, not from the server” mysteries.
Alternatives: free, open source, and commercial
| Tool | Type | What it gives you |
|---|---|---|
dig | Free, built in | Exactly what was returned, and by which server |
nslookup | Free, built in | Simpler output; fine for a quick check |
host | Free, built in | The shortest answer of the three |
traceroute / mtr | Free | The path, and where latency appears |
1.1.1.1, 8.8.8.8, 9.9.9.9 | Free | Public resolvers, often faster than an ISP’s |
| Cloudflare / Route 53 / NS1 | Commercial, free tiers | Authoritative hosting with low-latency global fleets |
-
Learn
dig +trace. It performs the walk yourself, showing each delegation step rather than the resolver’s cached summary. -
Public resolvers are usually faster than an ISP’s, and change who sees your lookups — a trade rather than a free win.
Comparison with related concepts
| Term | What it actually is |
|---|---|
| IP address | Where a machine is, on a network |
| Domain name | A human-readable name that resolves to one |
| Resolver | The server that does the lookup work for you |
| Authoritative server | The one holding the real records for a domain |
| TTL | How long an answer may be cached |
| Autonomous system | A large network under one administrative control |
| BGP | How autonomous systems advertise what they can reach |
When to use it — and when not to
-
Lower a record’s TTL a day before a planned migration, so the change propagates quickly when you make it.
-
Use a CNAME when pointing at a service whose address you do not control, and an A record when you do.
-
Use
digbefore assuming an application is broken. Half of “the service is down” is a resolution problem. -
Do not hard-code IP addresses in configuration. That is what names are for, and the address will change.
-
Do not set a TTL of five seconds and leave it there. You pay for it on every request, forever.
-
Do not debug routing from one machine. A path that fails for you may work everywhere else, and that is itself the finding.
The AI connection
-
Model API endpoints are names behind global fleets. The address you resolve depends on where you are, which is how the provider puts inference near you.
-
A container that cannot reach the internet is usually a DNS problem inside the container, not a network outage.
-
Cluster service discovery is DNS. In Kubernetes, a service name resolves to its current addresses, and this lesson is the whole mechanism.
-
Private addressing is why your training machine cannot be reached directly, and why you tunnel through a bastion or use a VPN.
-
A slow first API call and fast subsequent ones is DNS caching, visible in your own latency numbers.
Knowledge check
quiz:
question: "You update a domain's A record to point at a new server. Some users reach the new server immediately; others keep landing on the old one for hours. What explains the split?"
options:
- "Resolvers are still serving the previous answer until its TTL expires"
- "The new server's DNS record was written with the wrong record type"
- "BGP has not yet propagated the route to the new server's network"
- "The authoritative name servers have not finished synchronising with each other"
answer_index: 0
explanation: "Every DNS answer carries a time to live, and a resolver that cached the old address serves it until that expires. Users behind a resolver with a fresh cache get the new answer; users behind one holding the old record do not, until the clock runs out."
Hands-on exercise
Resolve a name by hand, then follow a packet. Worked through fully in the Day 16 lab directory.
| What you are doing | Command |
|---|---|
| The short answer | dig example.com +short |
| The full answer with TTL | dig example.com |
| Walk the hierarchy yourself | dig example.com +trace |
| Ask a specific resolver | dig @1.1.1.1 example.com |
| Look up other record types | dig example.com MX and dig example.com NS |
| Follow the path | traceroute example.com |
| See your own addresses | ipconfig getifaddr en0 or ip addr |
Expected output
example.com. 3600 IN A 93.184.216.34
. 518400 IN NS a.root-servers.net.
com. 172800 IN NS a.gtld-servers.net.
example.com. 172800 IN NS a.iana-servers.net.
3600is the TTL — one hour before that answer must be looked up again.+traceshows the three delegations: root to.comto the domain’s own servers.
Validate your work
- You can read a TTL off a
diganswer and say what it means - You performed the full hierarchy walk with
+traceand named each step - You queried two different resolvers and compared their answers
- You identified whether your own machine has a public or a private address
- You ran
tracerouteand can say which hop is your own router -
bash tests/run_tests.shreports 0 failures
Troubleshooting
-
dignot installed. On some systems it is in adnsutilsorbind-toolspackage.hostandnslookupare usually present. -
+tracegives a short answer. Something is intercepting DNS — a corporate resolver, or a router that redirects port 53. -
Two resolvers disagree. Usually a stale cache on one of them; check the TTLs.
-
tracerouteshows asterisks. Routers may decline to reply. It is not evidence of a fault.
Common mistakes
-
Believing a change is live because it works for you. Your cache is not everyone’s.
-
Changing a TTL at the same time as the record. The old TTL governs how long the old value survives, so lower it in advance.
-
Confusing the DNS TTL with the IP hop limit. Same name, unrelated jobs.
-
Assuming a private address is reachable from anywhere but its own network.
Practice assignment
-
Resolve five well-known domains and tabulate their TTLs. Form a hypothesis about why they differ, then check whether the short ones belong to services that move.
-
Find a CNAME chain in the wild and count the lookups it costs.
-
Compare
tracerouteto a domestic host and an overseas one, and identify where the latency appears. -
Identify every address on your own machine, and classify each as loopback, private or public.
Extension challenge
-
Run your own resolver locally, point your machine at it, and watch the queries it makes. Seeing your own lookups is a genuinely uncomfortable exercise.
-
Measure the TTL trade-off. Query a name repeatedly and time each request, identifying the moment the cache expires.
-
Read a real BGP leak post-mortem and map what happened onto the routing diagram in this lesson.
-
Set up a subdomain with a low TTL, change it, and measure how long the old value actually survives across three different public resolvers.
Quiz
Q1. What is an IP address, and what is it primarily used for?
- A human-friendly name that the network routes traffic by directly
- A password that authenticates a machine to the network
- A permanent serial number burned into a device at the factory
- A numeric identifier for a network interface that routers use to deliver packets
Show answer
Answer: D. A numeric identifier for a network interface that routers use to deliver packets
An IP address is a numeric location on the network that routers use to forward packets. It is not a permanent device identity — addresses are reassigned, shared behind NAT, and change when a device moves networks.
Q2. A recursive resolver has never seen a name before. Which order does it query the DNS hierarchy?
- Root server, then TLD server, then authoritative server
- TLD server, then root server, then authoritative server
- Authoritative server, then TLD server, then root server
- It asks all three at once and takes the fastest reply
Show answer
Answer: A. Root server, then TLD server, then authoritative server
The resolver asks a root server which servers handle the TLD (e.g. .com), then asks a TLD server which servers are authoritative for the domain, then asks an authoritative server for the actual record. Each step returns a referral until the last one returns the answer.
Q3. What is the key difference between an A record and a CNAME record?
- An A record is for IPv4 and a CNAME is for IPv6
- An A record maps to an IP; a CNAME points to another name
- A CNAME maps a name to an IP address; an A record points to another name
- They are identical; CNAME is just an older spelling of A
Show answer
Answer: B. An A record maps to an IP; a CNAME points to another name
An A record ends in an actual IPv4 address. A CNAME is an alias that points to a different name, so the resolver must perform a second lookup on that name to eventually reach an address. (AAAA is the record type for IPv6 addresses.)
Q4. Which of these addresses is a private address that cannot be reached from the public internet?
- 93.184.216.34
- 8.8.8.8
- 192.168.1.10
- 1.1.1.1
Show answer
Answer: C. 192.168.1.10
192.168.0.0/16 is one of the RFC 1918 private ranges (along with 10.0.0.0/8 and 172.16.0.0/12), usable only inside a local network. The other three are public, globally routable addresses.
Q5. What does the TTL on a DNS record control?
- How many routers a packet may cross before being discarded
- How many times the record may be queried per second
- The maximum size in bytes of the DNS response
- How long a resolver may serve the answer from cache
Show answer
Answer: D. How long a resolver may serve the answer from cache
A DNS record's TTL (time to live) is how many seconds a resolver may cache and reuse the answer before it must re-query. This is why the second lookup of a name is fast, and why a record change can take time to take effect everywhere.
Q6. Why was IPv6 created?
- IPv4's 32-bit address space was running out
- IPv4 could not represent domain names, only numbers
- IPv6 replaced DNS with a simpler naming scheme
- IPv4 was too slow to route packets quickly enough
Show answer
Answer: A. IPv4's 32-bit address space was running out
IPv4 has 32-bit addresses — about 4.3 billion — which the growth of the internet exhausted (the central pool ran out in 2011). IPv6 uses 128-bit addresses, an effectively unlimited space, and now runs alongside IPv4.
Q7. How does a router decide where to send a packet?
- It knows the complete path to every machine on the internet in advance
- It reads the destination, picks the best next hop, and forwards
- It asks a central internet switchboard for directions
- It sends the packet to every neighbor and lets them sort it out
Show answer
Answer: B. It reads the destination, picks the best next hop, and forwards
Each router makes one local decision: it reads the destination IP, looks up the best next hop in its routing table, and forwards the packet one step closer. No router holds a map of the whole internet — a workable path emerges from many local decisions.
Q8. A service "can't be reached." You run `dig +short A the-host` and get a correct, expected IP address. What does this tell you?
- The problem is definitely inside the application code
- The DNS record is wrong and must be fixed first
- DNS works, so suspect routing, a firewall, or the service itself
- Nothing useful; the command cannot help diagnose connection issues
Show answer
Answer: C. DNS works, so suspect routing, a firewall, or the service itself
A correct resolution rules out DNS as the cause. The next step is to test reachability with ping and traceroute to see whether packets get to the destination and where they stop. Separating "wrong address" from "can't reach the address" is the core networking-debugging habit.
Glossary
- IP address
- A numeric identifier for a network interface that routers use to deliver packets; a machine's location on the network, not a permanent name for a device.
- IPv4
- The original internet addressing scheme using 32-bit addresses (about 4.3 billion), written as four numbers 0–255 separated by dots, such as 93.184.216.34.
- IPv6
- The newer addressing scheme using 128-bit addresses, written as eight groups of hexadecimal digits, created because the IPv4 space was exhausted.
- subnet
- A contiguous block of addresses that share a leading prefix and are treated as one local network.
- CIDR
- Classless Inter-Domain Routing notation, which writes an address block as an address plus a slash and a number of fixed leading bits, such as 192.168.1.0/24 (256 addresses).
- private IP
- An address in a reserved range (10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16) that works only inside a local network and is never routed on the public internet.
- loopback
- The special address 127.0.0.1, which always means "this very machine"; part of the 127.0.0.0/8 range.
- DNS
- The Domain Name System, a distributed, hierarchical directory that maps human-friendly names to records such as IP addresses.
- resolver
- A recursive resolver is a server that performs the full DNS lookup on your behalf — walking root, TLD, and authoritative servers — and returns and caches the final answer.
- A record
- A DNS record that maps a name to an IPv4 address; the AAAA record is its IPv6 equivalent.
- CNAME
- A DNS record that aliases one name to another name, which the resolver must then look up in turn, rather than pointing directly to an address.
- MX record
- A DNS mail-exchange record specifying which server receives email for a domain, with a priority number.
- TTL
- Time to live: on a DNS record, how many seconds a resolver may cache the answer; on an IP packet, the hop limit that traceroute exploits.
- router
- A machine that forwards packets between networks, reading each packet's destination address and sending it to the best next hop from its routing table.
- BGP
- The Border Gateway Protocol, by which autonomous systems advertise to their neighbors which address blocks they can reach, stitching independent networks into one internet.
- autonomous system
- A large network under a single administrative control (an ISP, university, or cloud provider), identified by an AS number and exchanging routes with others via BGP.
- traceroute
- A tool that reveals the routers along the path to a host by sending packets with increasing hop limits so each router in turn reports back.
Sources and further reading
- Domain Name System — Wikipedia (accessed 2026-07-12)
- IP address — Wikipedia (accessed 2026-07-12)
- How DNS works — MDN Web Docs (accessed 2026-07-12)
- High Performance Browser Networking — Primer on Latency and Bandwidth — Ilya Grigorik (accessed 2026-07-12)
- Cloudflare Learning — What is DNS? — Cloudflare (accessed 2026-07-12)
Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.