IP Addresses and DNS
Table of Contents
- Computers Don't Know Names
- IP Addresses
- IPv4 and IPv6
- Private Addresses and localhost
- DNS: The Internet's Phone Book
- Following One Lookup
- DNS Records You'll Actually Use
- Caching and "Propagation"
- Try It Yourself
1. Computers Don't Know Names
You type dara-sok.github.io. But the network that carries your request
doesn't understand names at all. Routers — the devices that pass data
along from network to network — only understand numbers.
So before your browser can send a single byte of the request, it has to answer one question: what number belongs to this name? That number is an IP address, and the system that answers the question is DNS. This chapter covers both.
2. IP Addresses
An IP address identifies a device on a network, the way a postal address identifies a house. IP stands for Internet Protocol: the rules for how data is split into small pieces called packets, each labelled with a from address and a to address, and passed from router to router until it arrives.
A typical address looks like this:
185.199.108.153
That's one of the addresses GitHub Pages uses. Every request to your site is a stream of packets addressed to a number like it.
You can think of the internet as a giant postal system: no single router knows the whole route, but each one knows which direction to send a packet next. A packet from Phnom Penh to a server in Singapore might pass through ten or fifteen routers on the way.
3. IPv4 and IPv6
The address above is IPv4: four numbers from 0 to 255, separated by dots. Each number is one byte — so an IPv4 address is 4 bytes, or 32 bits (remember Bits and Bytes from How Computers Work). That allows about 4.3 billion addresses.
That sounded like plenty in the 1980s. Today there are far more devices than that, and the world has run out of new IPv4 addresses. The replacement is IPv6, with 128-bit addresses written in hex:
2606:50c0:8000::153
IPv6 has enough addresses to give every grain of sand on Earth its own
— many times over. (The :: is shorthand for "a run of zeros here".)
Most of the internet now speaks both. Your phone or laptop may well be using IPv6 already without you noticing. For this series, you can treat them the same: both are just the number of a computer.
4. Private Addresses and localhost
Not every address is reachable from the whole internet. Some ranges are private, reserved for use inside a home or office network:
| Range | Where you'll see it |
|---|---|
192.168.x.x | Most home Wi-Fi routers |
10.x.x.x | Offices, cloud networks, Docker |
172.16.x.x – 172.31.x.x | Offices, Docker's default networks |
Your laptop probably has a private address like 192.168.1.23. Your
router has one public address for the whole house, and passes
replies back to the right device inside. That's why two people in
different homes can both have 192.168.1.23 at the same time — the
addresses only have to be unique inside each network.
Then there's one very special address:
127.0.0.1 (IPv4)
::1 (IPv6)
Both mean "this computer", and both have a name: localhost.
Packets sent to localhost never leave your machine. When you open
http://localhost:3000, your browser is talking to a server process on
the same computer — no internet needed.
The Networking for Developers series on the Backend track goes much
deeper into addresses, routing, and why a server listening on
localhost can't be reached from outside.
5. DNS: The Internet's Phone Book
Nobody wants to remember 185.199.108.153. DNS — the Domain
Name System — lets us use names instead. You give it a name, and it
gives you back the IP address.
The clever part is that DNS isn't one big list on one computer. It's spread out across thousands of servers around the world, organised as a tree that matches the parts of a domain name from chapter 2:
. (root)
│
┌──────────────┼──────────────┐
com io kh
│ │ │
example github gov
│
dara-sok
Nobody has to know everything. The root servers only know who is in
charge of .com, .io, .kh, and so on. The .io servers only know
who is in charge of github.io. And GitHub's own servers know the
addresses for everything under github.io. Each level points you to
the next.
6. Following One Lookup
Here's what happens the first time your computer looks up
dara-sok.github.io:
Your computer ──1──▶ Resolver: "What's dara-sok.github.io?"
│
├──2──▶ Root server: "Ask the .io servers."
├──3──▶ .io server: "Ask GitHub's name servers."
├──4──▶ GitHub's NS: "It's 185.199.108.153."
│
Your computer ◀──5───── Resolver: "185.199.108.153"
- Your computer asks a resolver: a DNS server that does the hard
work for you. Usually it belongs to your internet provider, or it's a
public one like Cloudflare's
1.1.1.1or Google's8.8.8.8. Your Wi-Fi router tells your computer which one to use. - If the resolver doesn't already know, it asks a root server.
- The root server points it to the TLD servers for
.io. - The
.ioservers point it to GitHub's authoritative name servers — the ones with the real answer. They reply with the address. - The resolver hands the answer back to your computer.
That sounds like a lot of trips, but each is tiny and fast. And it almost never happens in full, because every step remembers answers (section 8). Before even asking the resolver, your browser and your operating system check their own memory first.
One more place your computer checks: the hosts file, a plain text
file of names and addresses that overrides DNS on your computer only.
On macOS, Linux, and WSL it's /etc/hosts; on Windows it's
C:\Windows\System32\drivers\etc\hosts. Open it with cat — you'll
probably find the line that makes localhost mean 127.0.0.1.
7. DNS Records You'll Actually Use
DNS doesn't only store IP addresses. Each name can have several records of different types. When you buy a domain one day, you'll set these up in your registrar's dashboard:
| Type | What it says | Example |
|---|---|---|
| A | This name's IPv4 address | example.com → 185.199.108.153 |
| AAAA | This name's IPv6 address | example.com → 2606:50c0:8000::153 |
| CNAME | This name is an alias for another name | www.example.com → dara-sok.github.io |
| MX | Where to deliver email for this domain | example.com → mail server |
| TXT | Any text — often to prove you own the domain | "google-site-verification=…" |
| NS | Which name servers are in charge of this domain | example.com → ns1.registrar.com |
The bonus section at the end of Git & GitHub for Beginners mentioned
connecting your own domain to GitHub Pages. This is what that looks like
under the hood: a CNAME record pointing www.yourname.com to
<your-username>.github.io, or A records pointing yourname.com at
GitHub's IP addresses. GitHub's docs list the exact values.
8. Caching and "Propagation"
Doing the full lookup for every request would be slow, so every DNS answer comes with a TTL — time to live — in seconds. It says how long anyone may remember the answer before asking again:
dara-sok.github.io. 3600 IN A 185.199.108.153
└─┬─┘
remember this for 1 hour
Your browser, your operating system, and the resolver all keep a cache, and reuse the answer until the TTL runs out. That's why the second visit to a site starts faster than the first.
It's also why, when you change a DNS record, some people see the new address right away and others keep seeing the old one for hours. People call this "waiting for DNS propagation", but nothing is really spreading — it's caches around the world slowly expiring. A common trick: lower the TTL a day before a planned change, so old answers expire quickly when you make it.
When "the site works on my phone but not my laptop", a stale DNS cache is one of the first things to suspect.
9. Try It Yourself
-
Look up a name. In your terminal, run:
nslookup dara-sok.github.io(Use your own username.) You'll see something like:
Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: Name: dara-sok.github.io Address: 185.199.108.153 Name: dara-sok.github.io Address: 185.199.109.153 Name: dara-sok.github.io Address: 185.199.110.153 Name: dara-sok.github.io Address: 185.199.111.153The Server line is your resolver. Non-authoritative means the answer came from the resolver's cache, not straight from GitHub's name servers. Why four addresses? So that if one GitHub server is down or busy, your browser can try another.
nslookupis built into Windows, macOS, and most Linux systems. If it's missing on Linux or WSL, install it withsudo apt install dnsutils. -
Compare domains. Look up
google.com,github.com, and a Cambodian site you use. Do any return IPv6 (AAAA) addresses too? -
Find your own private address. Run
ipconfig(Windows PowerShell),ipconfig getifaddr en0(macOS), orhostname -I(Linux/WSL). It should start with192.168.,10., or172.. -
Read your hosts file. Run
cat /etc/hostsand find thelocalhostline.
The browser now has an address. In the next chapter, it opens a connection to it — and makes sure nobody can listen in.
Buy Me a Coffee
Found this tutorial helpful? Consider buying me a coffee to support more free content!