Point a domain name to a VPS
A, AAAA and CNAME records, sample DNS zone entries, and step-by-step checks before you install your site on the VPS.
A domain name does not know where your server is: the DNS zone tells it. A few records are enough to point example.com to your VPS address, as long as you know what each one does.
- An A record points a name to an IPv4 address, AAAA to an IPv6 address, CNAME to another name.
- The bare name (@) cannot carry a CNAME: use A or AAAA for the main domain.
- Check with dig against a public resolver before you request an HTTPS certificate.
Find the IP address of the VPS
Before you create a record, note the public address of the VPS. Run two commands on the server to display it. One IPv4 address is enough for most sites; IPv6 is optional.
- curl -4 ifconfig.me: shows the public IPv4 address of the server, the one it exposes on the Internet.
- curl -6 ifconfig.me: shows the public IPv6 address, if the VPS has one.
- Note these addresses: they become the values of your A and AAAA records.
Create the A, AAAA and CNAME records
In the DNS zone of your domain, at your registrar or at the DNS provider you chose, add the following records. The name @ stands for the bare domain, example.com, and www stands for the www subdomain.
- A @ 203.0.113.10: example.com points to the IPv4 of the VPS.
- A www 203.0.113.10: www.example.com points to the same machine.
- AAAA @ 2001:db8::10: the same target in IPv6, if you use it.
- CNAME blog example.com.: blog.example.com follows the target example.com.
Check before you install the site
A DNS change sometimes takes a few minutes to spread, longer if the old value had a high TTL. Do not request the HTTPS certificate until the name resolves correctly: validation would fail.
- dig +short example.com A: should return 203.0.113.10.
- dig +short blog.example.com: should return example.com. then the IP address.
- nslookup example.com 1.1.1.1: queries a public resolver, to avoid the cache of your local box.
Frequently asked questions
What is the difference between a domain and a subdomain?
The domain is the name you buy, for example example.com. A subdomain adds a prefix, for example blog.example.com. Both are managed in the same DNS zone, with their own records.
Why does www answer but the bare name does not?
Usually an A record is missing on the bare name, or the old value is still cached. Compare the dig output for www and for the bare name, then wait for the TTL to expire.
Do I need to change the DNS servers at my registrar?
Only if the zone is managed by another provider. In that case the name servers of the domain must point to that provider, otherwise your records are never read.