On this pageWhen the hosts file is enough
Once you run more than a couple of servers, IP addresses start leaking into everything: database connection strings, backup scripts, monitoring targets, firewall rules. Change one address and you hunt through all of them. Private DNS replaces those addresses with names that only your servers can resolve, such as db1.fleet.internal. This guide builds it for a small fleet: a WireGuard network between the servers, Unbound on the hub answering for an internal zone, and clients that send only internal names to it.
When the hosts file is enough
/etc/hosts on each server |
Private DNS | |
|---|---|---|
| Servers | Two or three | Four and more, or changing often |
| A changed address | Edit every server | Edit one file on the resolver |
| Reverse lookups | Only if you add them everywhere | One PTR entry |
| Works for containers and tools that ignore hosts files | Rarely | Yes |
| Moving parts | None | A resolver that must stay up |
If the left column describes you, keep using /etc/hosts, managed from one copy with whatever deploys your configuration. The rest of this guide is for the right column.
The design
Servers at a cloud provider usually talk to each other over their public addresses, so the first step is a private overlay network. WireGuard fits well: each server gets an address in 10.8.0.0/24, and the hub at 10.8.0.1 also runs the resolver. Because the overlay runs over public addresses, it works the same whether the servers share one region or spread across several of CloudSat's 13 regions. Setting up the tunnels themselves is covered in IPsec, SSL VPN or WireGuard.
web1 10.8.0.11 ─┐
db1 10.8.0.21 ─┼── WireGuard ── hub 10.8.0.1 (Unbound: fleet.internal)
mon1 10.8.0.31 ─┘
Pick the zone name first
Names are hard to change later, so choose carefully:
| Name | Verdict |
|---|---|
fleet.internal |
Good. ICANN reserved .internal for private use in 2024, so it will never be a public domain |
int.example.com, under a domain you own |
Good. It also allows publicly trusted certificates through the DNS challenge |
home.arpa |
Meant for home networks (RFC 8375) |
.local |
Avoid. It belongs to multicast DNS, and Apple devices and Avahi treat it specially |
| A made-up top-level domain | Avoid. It can become real: .dev, once a popular invented name for development machines, is now a public top-level domain whose sites browsers only load over HTTPS |
This guide uses fleet.internal.
Set up Unbound on the hub
sudo apt install unbound # sudo dnf install unbound on the RHEL family
Create /etc/unbound/unbound.conf.d/fleet.conf:
server:
interface: 127.0.0.1
interface: 10.8.0.1
ip-freebind: yes
access-control: 127.0.0.0/8 allow
access-control: 10.8.0.0/24 allow
local-zone: "fleet.internal." static
local-data: "hub.fleet.internal. IN A 10.8.0.1"
local-data: "web1.fleet.internal. IN A 10.8.0.11"
local-data: "db1.fleet.internal. IN A 10.8.0.21"
local-data: "mon1.fleet.internal. IN A 10.8.0.31"
local-data-ptr: "10.8.0.11 web1.fleet.internal"
local-data-ptr: "10.8.0.21 db1.fleet.internal"
local-data-ptr: "10.8.0.31 mon1.fleet.internal"
What each part does:
interfacelines bind Unbound to the loopback and the WireGuard address only. Binding specific addresses also avoids a clash with the systemd-resolved stub that Ubuntu runs on127.0.0.53.ip-freebind: yeslets Unbound start even ifwg0comes up a moment later at boot.access-controlanswers queries from the hub itself and the overlay. Everything else is refused, so the resolver is never open to the internet.local-zone ... staticmakes Unbound the authority forfleet.internal: names listed withlocal-dataresolve, and any other name in the zone returns NXDOMAIN instead of being sent out to the internet.- Names outside the zone are resolved normally, so the hub can also serve as the fleet's general resolver.
On the RHEL family, Unbound reads extra files from /etc/unbound/conf.d/ instead; the include: lines in /etc/unbound/unbound.conf show which directory your package uses. Check the configuration, start the service and test:
sudo unbound-checkconf
sudo systemctl enable --now unbound
dig @10.8.0.1 db1.fleet.internal +short
dig @10.8.0.1 -x 10.8.0.21 +short
Allow DNS on the tunnel interface only, for example with UFW: sudo ufw allow in on wg0 to any port 53.
Point the clients at it, for internal names only
The clean way on systems that use systemd-resolved, the default on Ubuntu and Fedora and an optional package on Debian, is a routing domain: queries for fleet.internal go to the hub over wg0, and everything else keeps using the server's normal resolvers. If the hub is down, only internal names fail.
sudo resolvectl dns wg0 10.8.0.1
sudo resolvectl domain wg0 '~fleet.internal'
The ~ marks a routing-only domain: it decides where queries go without adding a search suffix. Those settings disappear when the interface goes down, so attach them to the tunnel in each client's /etc/wireguard/wg0.conf:
[Interface]
Address = 10.8.0.11/24
PrivateKey = <web1-private-key>
PostUp = resolvectl dns %i 10.8.0.1; resolvectl domain %i '~fleet.internal'
[Peer]
PublicKey = <hub-public-key>
Endpoint = 203.0.113.10:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25
wg-quick also has a DNS = line, but it relies on a resolvconf program that Ubuntu does not install by default, and it cannot express "internal names only". The PostUp line avoids both problems. Verify on a client:
resolvectl status wg0
resolvectl query db1.fleet.internal
getent hosts db1.fleet.internal
getent resolves the way applications do, so if it answers, your database clients and scripts will too.
On systems without systemd-resolved, skip the routing domain and list the hub, and a second resolver if you run one, as the nameservers in /etc/resolv.conf or in NetworkManager's DNS setting. Unbound resolves public names as well, so nothing else breaks, but every lookup now depends on the tunnel being up.
Containers need to be told
Docker does not follow systemd-resolved's routing domains. When the host uses the local stub, Docker hands containers the list of upstream servers instead, so a container may ask a public resolver for db1.fleet.internal and get NXDOMAIN. Give containers the hub directly in /etc/docker/daemon.json, then restart Docker:
{
"dns": ["10.8.0.1"]
}
Containers then send every query to the hub, which answers internal names itself and resolves the rest.
Keep it running
- Add a second resolver. Run the same Unbound configuration on another server in the overlay, and list both addresses in
resolvectl dns. Keep one copy offleet.confin version control and deploy it to both. - Change addresses in one place. Edit
fleet.conf, rununbound-checkconf, thensudo systemctl restart unbound, orsudo unbound-control reloadwhere remote control is enabled. - Keep internal names out of public DNS. If you use a subdomain of your real domain, publish the internal records only on the private resolver, so your public zone does not advertise your internal layout.
If you prefer a web interface over configuration files, Technitium DNS Server does the same job with zone management in the browser, and CloudSat lists it as a one-click app.
FAQ
Why not put private addresses in public DNS?
It works, and private addresses are useless to outsiders, but it publishes your internal layout to anyone who asks, and the names point nowhere for machines outside the overlay. A private resolver keeps the zone private and the answers correct for its audience.
What happens if the resolver goes down?
With a routing domain, only fleet.internal lookups fail; public names keep resolving through the normal resolvers. A second Unbound instance listed on every client removes even that gap.
Can I get TLS certificates for internal names?
Public certificate authorities do not issue certificates for .internal names. Either use a subdomain of a domain you own and the DNS challenge, or run a small internal certificate authority and install its root certificate on the machines that connect.
Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.




