Domain name and DNS
Your server has only a number, and nobody remembers 203.0.113.10. Here is how to point a domain name at your server with DNS, then check that the name really leads to you.
- Course
- Tutorial 16 of 35
- Time
- 20 min to read
- Tested with
- Debian 13.7 (trixie), dig 9.20
What you will be able to do
- Get a domain name and know where to write its settings.
- Create an A record (and AAAA if you have an IPv6 address) and a www alias (CNAME).
- Check the result with dig and host.
- Understand the TTL and why the old address sometimes stays visible.
Before you start: The words: IP, DNS, domain, port, firewall, Your first SSH connection.
Contents
How do you point a domain name at your server? You write a line in the DNS that says "this name matches this IP address". In The words: IP, DNS, domain, port, firewall, we saw that the DNS is the directory that turns a name into an IP address, the number that identifies a machine on the network. Since Your first SSH connection, you reach your server by its number. Time to give it a name.
Get a domain name
You don't buy a domain name, you rent it, for a year or more, from a registrar. That's the company you go through to reserve the name. If you forget to renew, the name becomes free again and someone else can take it.
Three landmarks are enough to choose:
- The name: short, no accents, easy to dictate over the phone;
- The extension (the end of the name):
.fr,.com,.org…; - Availability: the registrar's website tells you right away whether the name is free.
Some services also offer a free subdomain, like mysite.example.org. It's handy for learning, but the name stays the property of the service.
In what follows, exemple.fr stands in for your name: replace it with yours. Once the name is yours, it still leads nowhere. You have to write down where your server is.
The three records to know
What you write is called a record: a line that says "this name matches that thing". The list of these lines for your domain is called the DNS zone. You edit it in your registrar's customer area (the part of its website where you manage your account), under a menu named "DNS zone" or "Manage DNS". Three types are enough to start.
| Type | Role | Example value |
|---|---|---|
A | the name leads to an IPv4 address (the four-number kind) | 203.0.113.10 |
AAAA | the name leads to an IPv6 address (the long version, explained in The words: IP, DNS, domain, port, firewall) | 2001:db8::10 |
CNAME | the name is an alias for another name | exemple.fr. |
The A record is the must-have. The AAAA is only for when your provider gave you an IPv6 address. The CNAME saves you from repeating the address: www.exemple.fr becomes a simple pointer to exemple.fr, and if the address ever changes, only one record needs editing. On to the practice.
1Point exemple.fr at the server
In your domain's DNS zone, create or edit the lines in the table below (the AAAA line only if you have an IPv6 address). First, note what already exists.
- An
Aline already exists (often a parking page from the registrar): edit it instead of adding a second one. - A
wwwof typeAalready exists: delete it, because it prevents you from creating aCNAME. MXorTXTlines: leave them alone, they handle email.
| Type | Name | Value | TTL |
|---|---|---|---|
A | @ | 203.0.113.10 | 300 |
AAAA | @ | 2001:db8::10 | 300 |
CNAME | www | exemple.fr. | 300 |
The name @ stands for the domain itself, exemple.fr; some interfaces prefer an empty field. The final dot of exemple.fr. marks the end of the name, and some interfaces add it for you. The addresses in this tutorial are example addresses, reserved for documentation: use your own. To read them aloud, say the numbers one by one ("203 dot 0 dot 113 dot 10"). In 2001:db8::10, the double colon replaces a run of zeros: read "2001, db8, 10".
The TTL ("time to live") is a delay in seconds. During that delay, other computers keep the answer in memory instead of asking again. Here it's 300 seconds, or 5 minutes: short, so handy for testing.
Save. The registrar updates its own servers within seconds, but the rest of the Internet follows more slowly. Let's see what the DNS answers.
2Check with dig and host
The dig command queries the DNS and prints the answer. If it's missing on your Debian computer, install it with sudo apt install bind9-dnsutils. The +noall +answer options, added to dig, hide everything except the answer.
dig +noall +answer exemple.frexemple.fr. 300 IN A 203.0.113.10This line reads from left to right: the name, the TTL (300 seconds), IN (the Internet network, always there), the type A, then the address. To get only the address, the +short option is enough. For another type, name it before the domain.
dig +short exemple.fr203.0.113.10dig +short AAAA exemple.fr2001:db8::10dig +short www.exemple.frexemple.fr.
203.0.113.10For www, two lines: the pointer to exemple.fr., then the address found at the end. The host command says the same thing in sentences, which is easier to read.
host exemple.fr
host www.exemple.frexemple.fr has address 203.0.113.10
exemple.fr has IPv6 address 2001:db8::10
www.exemple.fr is an alias for exemple.fr.
exemple.fr has address 203.0.113.10
exemple.fr has IPv6 address 2001:db8::10Do you see your addresses? Then the name leads to your server. But sometimes dig still answers the old address, or nothing at all. Let's see why.
3Understand TTL and propagation
"Propagation" isn't a message traveling from server to server: it's memories expiring. Every internet provider (the company that gives you Internet) and every computer keeps the last answer it received for a name in memory (in a "cache"), for the length of the TTL. Until that delay is over, it answers with the old address without asking again.
Here is what that looks like right after a change. The registrar already answers the new address, but your provider's resolver (the DNS server that answers your questions) kept the old one: here 203.0.113.99, the address of a parking page.
dig +short exemple.fr203.0.113.99The diagram follows the same request, before and after the memory expires.
Nothing is broken: the memory expires after the TTL, 5 minutes here, and the same command then gives 203.0.113.10. With a TTL of one hour, the wait lasts an hour. Every computer has its own memory, so two people can see two different addresses for a few minutes.
The name leads to your server, and you know why it sometimes takes a while. All that's left is to use it.
4Log in by name
Once dig shows the right address, SSH accepts the name in place of the number. Simply replace 203.0.113.10 with exemple.fr.
ssh alice@exemple.frSSH asks about the fingerprint (the code that identifies the machine) again, as on your first login: to SSH, exemple.fr is a new name, even though the machine is the same. Compare the fingerprint with the one from Your first SSH connection, then answer yes. You then log in with your key. If something went wrong along the way, here are the most common cases.
If it fails
Three cases come up most often.
dig +shortprints nothing: the name doesn't exist in the zone. Check the spelling and that the line is really saved.hostsays it more clearly, withNXDOMAIN("this name doesn't exist").- The old address is still displayed: the TTL hasn't finished running. Wait for its length, as in step 3.
- Two addresses show up: an old
Arecord stayed next to the new one. Delete it, otherwise part of your visitors will land on the wrong machine.
The first case for real, with a name nobody created:
host inconnu.exemple.frHost inconnu.exemple.fr not found: 3(NXDOMAIN)And the third: the two addresses come out one under the other, in an order that can change:
dig +short exemple.fr203.0.113.10
203.0.113.99What's next
Your name exemple.fr now leads to your server, and so does www. But if you type that name in a browser, nothing answers: no program is listening for web visitors yet. The next article, Your first website with Apache, installs that program and shows your first page. It comes at the right time: the name you just created is the front door of that site.