Running your own DNS server is a good way to understand it. It can give names to lab machines and cache answers for them. Do this on a test machine, not on a network other people rely on.
Choosing software
- BIND (
named) is a full-featured server that can be authoritative or recursive. - dnsmasq is small and easy, offering DNS forwarding, caching and DHCP.
- Unbound is mainly a recursive, caching resolver.
A small dnsmasq server
Install it with sudo apt install dnsmasq or sudo dnf install dnsmasq. Then create /etc/dnsmasq.d/lab.conf:
listen-address=127.0.0.1
bind-interfaces
host-record=web.lab.test,192.168.50.10
no-resolv
server=192.168.1.1host-record defines a name and address. server is the upstream resolver for everything else, so use one that is valid on your network. Without no-resolv, dnsmasq would also use the servers listed in /etc/resolv.conf. Debian and Ubuntu read this directory by default. Elsewhere, make sure /etc/dnsmasq.conf has a conf-dir= line that includes it.
Port 53 conflicts
Only one program can listen on a given address and port. On Ubuntu, systemd-resolved already uses 127.0.0.53. Without bind-interfaces, dnsmasq tries to claim the wildcard address and can fail with "Address already in use". See who is listening:
$ sudo ss -lntup 'sport = :53'Check, start, test
$ dnsmasq --test --conf-file=/etc/dnsmasq.d/lab.conf
dnsmasq: syntax check OK.
$ sudo systemctl restart dnsmasq
$ dig @127.0.0.1 web.lab.test +short
192.168.50.10The @127.0.0.1 part sends the query to your new server, whatever the system default is.
To serve other machines, listen on the server's network address too, allow UDP and TCP port 53 through the firewall, and point clients at it. Never leave a recursive resolver open to the whole internet, since attackers abuse open resolvers to amplify traffic.
BIND zones
BIND is packaged as bind9 on Debian and bind on Fedora and RHEL. Configuration paths differ between them. A zone is declared in the configuration and its records live in a zone file. Validate both before reloading:
$ sudo named-checkconf
$ named-checkzone lab.test db.lab.test
zone lab.test/IN: loaded serial 1
OKnamed-checkconf prints nothing when all is well. Increase the SOA serial when you edit a zone, so secondary servers notice the change.
Try it
- Build the dnsmasq example in a virtual machine.
- Add a second
host-record, restart, and query it withdig @127.0.0.1. - Stop the service and run the query again to see the failure.
Check your understanding
DNS Setup
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.