How does DNS work
Few people memorize all their friends' phone numbers; usually we look them up by name. The internet works the same way. Computers find each other by number address, but those numbers are hard for people to remember. So we use names that are easy to remember, and DNS turns those names into number addresses.
Names Are Easier to Remember than Numbers
We learned that computers find each other by number address. But those numbers are very hard for people to memorize.
Just as we look up a friend by name instead of memorizing phone numbers, we use easy-to-remember names instead of numbers. The name you type into the address bar is called a domain.
Tap the name card and the number-address card to compare them. The name sticks at a glance while the numbers quickly blur, and you can feel right away which is easier to remember.
A name stays in memory after one look, but numbers quickly get mixed up. People want to use names; computers need numbers. What the two want is different.
So someone has to turn names into numbers. That is the job of DNS.
Asking DNS for a Name
When a computer wants to go somewhere by name, it first asks DNS, "What is the number address for this name?" DNS answers, "The address for that name is this."
It is like calling directory assistance with a name and being told the number. Finding an address from a name like this is called a lookup.
Tap a name and my computer sends DNS a question; the number address for that name comes back as the answer.
The question went out and the address came neatly back. We only knew the name, and now the computer has the number it needs.
Now a real connection can begin to that number address. But where does DNS keep all those names and addresses?
DNS Is a Giant Phone Book
DNS is like a list holding a huge number of name and address pairs. Think of a phone book: names listed one after another, each with its address beside it.
Ask for a name and DNS finds the matching pair in the list and hands back the address. So all we have to give is the name.
Tap a name in the phone book and the matching row lights up, showing that name's number address. Each name is paired with one address.
Real DNS, however, is not a single book. There are far too many names in the world, so countless servers around the globe share the list between them.
The root servers at the top point to the servers that handle endings such as .com, and those in turn point to the server run by the owner of the name. The final answer comes after asking a few servers in turn.
Walking that path from the start every single time would be slow, though. So there is a clever trick.
Remembering What Was Found Once
It is smart to jot down a name and address once they have been found. Keeping them like this is called caching.
The next time the same name is needed, there is no need to go all the way to the phone book, because the address comes straight out of the note kept close by. So from the second time on, the connection is much faster.
Look up the same name twice. The first time it travels to the phone book and is slow; the second time it takes the address straight from memory and is fast. Press clear memory and it starts from scratch again.
The second lookup was noticeably faster, because it took the address straight from memory instead of going to the phone book.
Of course, the memory lasts only a short while. Addresses can change, so it must not be trusted for too long; how long it may be kept is set by the owner of the name.
Still, in that short time, the memory makes the internet faster.
Summing Up
In one line: people use names, computers use numbers, and DNS turns names into number addresses.
DNS is like a giant phone book full of pairs, and what it has found once it keeps in memory for a while, so the next time is faster. Thanks to that, we can leave the complicated numbers to DNS and just remember names.
Each press of the button reveals one more key point. (name vs number → ask DNS → giant phone book → remember once found) Once all four have appeared, the review is done.
Now you know how a name becomes a number address. With the address in hand, it is finally time to send data to the other computer.
But what if a few packets vanish on the way, or arrive out of order? The next lesson is about making sure everything arrives, with nothing missing and in the right order.