Chapter 3 · Lesson 1 of 22
Domains and HTTPS

Point a domain at your server (A record)

A domain points at a server through a DNS A record that maps the name to the server's IPv4 address.

By the end you will

Point your domain at your server with an A record and check it with dig.

Time
16 min
Level
Beginner
Check
4 questions
You need
  • A domain you control, with access to its DNS settings
  • Your server's public IPv4 address

To point a domain at your server, create an A record that maps the name to the server’s public IPv4 address, then check it with dig +short example.com A. Most changes show up within minutes, but resolvers may keep the old answer until its TTL runs out.

How it works#

DNS is a distributed phone book. Your domain has a zone, which is a list of records, and the zone is served by name servers that you choose at your registrar. When a browser wants example.com, it asks a resolver (usually your ISP’s or a public one such as 1.1.1.1). The resolver walks down from the root to your name servers, gets the answer, and remembers it for the record’s TTL (time to live, in seconds). Until the TTL runs out, the resolver answers from memory and never asks you again.

An A record maps a name to an IPv4 address. A name can have several A records, and each name is separate: example.com and www.example.com are two names, so each needs its own record (or a CNAME for www). In most dashboards the bare domain is written as @.

Visitors on IPv6 networks look for an AAAA record first. If one exists, they use it. If you have none, they fall back to IPv4. That is why a wrong AAAA record hurts and a missing one does not.

Step 1: Find your server’s public address#

On the server:

bash
curl -4 https://ifconfig.me

-4 forces IPv4. What you should see: one IPv4 address, for example 203.0.113.10. If your provider gives you an address in its dashboard, use that one instead. For a server behind NAT at home, this shows your router’s address, and you also need port forwarding.

Step 2: Add the A records#

In your DNS provider’s dashboard add:

TypeNameValue
A@ (the bare domain)203.0.113.10
Awww203.0.113.10

Leave the TTL at the default or set it to 300 seconds while you test. A short TTL means a wrong value is corrected quickly. Remove any old or parking-page records for the same names, because two A records with different values make visitors reach either one.

Step 3: Query the answer#

bash
dig +short example.com A

What you should see: 203.0.113.10, your server’s IP, and nothing else. +short prints only the answer. If you see nothing or an old address, wait and try again, or ask a public resolver directly:

bash
dig +short example.com A @1.1.1.1

@1.1.1.1 sends the query to that resolver instead of your own. If dig is missing, install dnsutils on Debian or Ubuntu.

Check it worked#

Check both names and then the server itself:

bash
dig +short www.example.com A
curl -I http://example.com

What you should see: the same IP from dig for both names, and a response from your web server (any HTTP status line, such as HTTP/1.1 200 OK, means the name reached a live server). If curl hangs, the DNS is fine but the server’s firewall or web server is the problem.

Edge cases and gotchas#

  • Cached answers hide your change. Resolvers keep the old value until the previous TTL ends, not the new one. Lower the TTL before a planned move, wait for the old TTL to pass, then change the record.
  • The bare domain and www are separate. Fixing one does not fix the other. Add both.
  • A CNAME cannot sit next to other records at the bare domain. Use A records there. Some DNS hosts offer ALIAS, ANAME or CNAME flattening if you need to point the bare domain at another hostname.
  • A proxy in the way. If your DNS host proxies traffic (an orange cloud, for example), dig shows the proxy’s address, not yours. That is expected. It also changes how HTTPS and redirects behave.
  • Wrong or stale AAAA. If you added an AAAA once and later moved servers, IPv6 visitors keep going to the old host. Update or remove it.
  • Trailing dots and the name field. Many dashboards append the domain automatically. Typing example.com in the Name field can create example.com.example.com. Use @ for the bare domain.
  • Your own machine caches too. If dig is right but the browser is wrong, the browser or the operating system cached the old answer. Restart the browser or flush the OS DNS cache.

Troubleshooting#

SymptomLikely causeFix
dig prints nothingRecord not created, or wrong zoneCheck the record exists in the DNS provider that your name servers point to
status: NXDOMAIN in dig example.comThe name does not exist in that zoneAdd the record, check spelling
Old address returnedCached until TTL endsWait, or query @1.1.1.1 and the authoritative name server
Works for www onlyNo record for @Add the A record for @
Address is not yoursDNS proxying is onTurn proxying off for the test, or expect the proxy’s IP
Browser says This site can't be reached but dig is rightServer firewall closed or web server downCheck ports 80 and 443 and the service
curl hangs after correct digFirewall blocks port 80Allow it in the firewall and the provider’s security group
Name shows example.com.example.comThe dashboard appended the domain to what you typedUse @ for the bare domain and www for www
Two different addresses come backAn old record is still in the zoneDelete the extra A record

Real-world scenario#

Ana buys example.com and gets a VPS with the address 203.0.113.10. She opens her DNS dashboard, deletes the registrar’s parking record, and adds two A records: @ and www, both pointing at the server. She sets the TTL to 300 seconds because she expects to fix typos.

bash
dig +short example.com A
dig +short www.example.com A @1.1.1.1
curl -I http://example.com

The first answer is still the parking page address. Her own resolver cached it. The query to 1.1.1.1 already shows 203.0.113.10, so she knows the zone is right and waits. Ten minutes later the first command agrees. The curl call hangs, which is not DNS: her cloud firewall blocks port 80. She opens ports 80 and 443 (see set up a firewall with UFW and the provider’s own firewall) and curl returns the default page. The next steps are in HTTPS and Let’s Encrypt and check DNS with dig.

Quick reference#

TaskCommand or setting
Bare domainA record, name @
wwwA record, or CNAME to the bare domain
Ask your resolverdig +short example.com A
Ask a public resolverdig +short example.com A @1.1.1.1
Check IPv6dig +short example.com AAAA
Test the server answerscurl -I http://example.com
While testingTTL 300 seconds

Next#

Understand every record you might add next in DNS record types explained.

Try it: Check your A record

After adding the A records at your DNS provider, verify them with dig.

practice, nothing runs on your machine

Want a real machine? Free browser labs: Killercoda

Check what you learned4 questions
1The www name works but the bare domain does not. What is missing?
2dig returns an address that is not your server's. If DNS proxying is on, what may this be?
3You changed the record but still see the old address. What is the most likely reason?
4You added an AAAA record with a typo in the address. What is the likely effect?

Frequently asked questions

How long does a DNS change take?

Often a few minutes, but the record's TTL decides how long old answers are cached. It can take longer for resolvers that cached the old value.

Do I need an AAAA record too?

Only if your server has a public IPv6 address and listens on it. An A record is enough for IPv4.

Why does the site work on my phone but not on my laptop?

The two may be using different resolvers with different cached answers. Ask a public resolver with dig and compare, then wait for the TTL to run out or flush the local cache.

Should I add an AAAA record if I am not sure about IPv6?

No. A wrong AAAA record sends IPv6 visitors to a server that does not answer. Add it only after you confirm the server listens on that IPv6 address.

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios