Anime-Sanctuary

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
  1. Get a domain name
  2. The three records to know
  3. 1. Point exemple.fr at the server
  4. 2. Check with dig and host
  5. 3. Understand TTL and propagation
  6. 4. Log in by name
  7. If it fails
  8. What's next
  9. Sources

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.

TypeRoleExample value
Athe name leads to an IPv4 address (the four-number kind)203.0.113.10
AAAAthe name leads to an IPv6 address (the long version, explained in The words: IP, DNS, domain, port, firewall)2001:db8::10
CNAMEthe name is an alias for another nameexemple.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 A line already exists (often a parking page from the registrar): edit it instead of adding a second one.
  • A www of type A already exists: delete it, because it prevents you from creating a CNAME.
  • MX or TXT lines: leave them alone, they handle email.
TypeNameValueTTL
A@203.0.113.10300
AAAA@2001:db8::10300
CNAMEwwwexemple.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.

On your computer
dig +noall +answer exemple.fr
Expected output
exemple.fr.		300	IN	A	203.0.113.10

This 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.

On your computer
dig +short exemple.fr
Expected output
203.0.113.10
On your computer
dig +short AAAA exemple.fr
Expected output
2001:db8::10
On your computer
dig +short www.exemple.fr
Expected output
exemple.fr.
203.0.113.10

For 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.

On your computer
host exemple.fr
host www.exemple.fr
Expected output
exemple.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::10

Do 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.

On your computer, right after the change
dig +short exemple.fr
Expected output
203.0.113.99

The diagram follows the same request, before and after the memory expires.

Why a DNS change takes time to arrive Your computer asks your provider's resolver for exemple.fr. The resolver answers with the old address it kept in memory. After 300 seconds, it asks the DNS zone again and gets the new address. Your computer Provider's resolver memory: 203.0.113.99 DNS zone exemple.fr = 203.0.113.10 1. exemple.fr? 2. 203.0.113.99 3. after 300 s 4. 203.0.113.10
Text version: your computer asks the resolver for exemple.fr (arrow 1). The resolver answers with the old address 203.0.113.99, kept in memory (arrow 2), without asking the DNS zone. Once the 300 seconds are over, it asks the zone again (arrow 3) and gets the new address 203.0.113.10 (arrow 4).

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.

On your computer
ssh alice@exemple.fr

SSH 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 +short prints nothing: the name doesn't exist in the zone. Check the spelling and that the line is really saved. host says it more clearly, with NXDOMAIN ("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 A record 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:

On your computer
host inconnu.exemple.fr
Expected output
Host 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:

On your computer
dig +short exemple.fr
Expected output
203.0.113.10
203.0.113.99

What'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.