Sub topic 9
Configuring DNS Servers and Search Domains
This chapter assumes you can use a Linux shell, edit configuration files, run commands with sudo, and understand IPv4 addresses and default gateways. It focuses on the resolver: the part of the operating system that turns names such as db01.example.com into IP addresses.
What DNS servers and search domains do
A DNS server answers questions about names and addresses. For example, when an application connects to repo.example.com, the resolver sends a DNS query to one of the configured DNS servers. The answer might be an IPv4 address such as 203.0.113.20.
A search domain is a suffix that the resolver tries when a program supplies an unqualified name. An unqualified name has no dot, such as db01. With example.com as the search domain, a lookup can try db01.example.com.
| Setting | Purpose | Example |
|---|---|---|
| DNS server | Answers name queries | `192.168.1.1` |
| Search domain | Completes short names | `example.com` |
| Resolver order | Selects the system lookup path | `/etc/nsswitch.conf` |
A search domain does not create DNS records. The DNS server must already know the completed name. Avoid search domains that could cause queries for private names to be sent to a public DNS provider.
How a Linux name lookup works
Applications usually use the system name service switch rather than sending DNS packets directly. The configuration in /etc/nsswitch.conf commonly contains a line like this:
hosts: files mdns4_minimal [NOTFOUND=return] dnsThe hosts line defines the order for hostname lookups. files means /etc/hosts is checked first. dns means the configured resolver service is used afterward. Other entries can support multicast DNS, LDAP, or other sources.
The resolver service may be systemd-resolved, NetworkManager, or another service. Inspect the active state before changing it:
resolvectl status
cat /etc/resolv.conf
grep '^hosts:' /etc/nsswitch.confOn a system using systemd-resolved, /etc/resolv.conf is often a symbolic link to a local stub resolver. Seeing 127.0.0.53 there is normal. It means applications send queries to the local service, which then forwards them to the configured upstream DNS servers.
Configure DNS with Netplan
Netplan stores network configuration in YAML files under /etc/netplan/. DNS settings belong under the interface that owns the address:
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [192.168.1.1, 9.9.9.9]
search: [example.com]The addresses list contains DNS server IP addresses. The search list contains domains appended to short names. Use DNS servers that your network permits and that have the records your server needs. A public resolver may resolve Internet names but usually cannot resolve your organization's private names.
Protect the file because Netplan can warn when its permissions expose network details:
sudo chmod 600 /etc/netplan/01-static.yaml
sudo netplan try
sudo netplan applynetplan try applies the configuration temporarily and can roll it back if you do not confirm it. Use it first during a remote change.
Configure DNS with NetworkManager
NetworkManager stores settings in connection profiles. First identify the profile:
nmcli connection showThen set the DNS servers and search domain on the correct profile:
sudo nmcli connection modify "Wired connection 1" \
ipv4.dns "192.168.1.1 9.9.9.9" \
ipv4.dns-search example.com
sudo nmcli connection up "Wired connection 1"If DHCP should no longer provide DNS settings, set ipv4.ignore-auto-dns yes. Otherwise, DHCP-provided values may still be used according to the connection configuration.
Verify and troubleshoot
Test the resolver through several paths:
resolvectl query example.com
getent hosts example.com
resolvectl statusresolvectl query tests the resolver service directly. getent hosts follows the system name service switch, so it also reveals whether /etc/hosts or another source supplies the result.
Common symptoms point to different causes:
- An IP address works but a hostname fails: check DNS servers,
/etc/resolv.conf, andnsswitch.conf. - A short name fails but its full name works: check the search domain.
- Public names work but private names fail: use the organization's internal DNS server.
- Queries time out: check the route, firewall rules, and UDP or TCP port 53 access.
- A stale address appears: inspect local caches and DNS record TTLs before changing configuration.
Exercise
getent hosts db01 fails, but getent hosts db01.example.com succeeds. What should you check first?
Show answer
Check that example.com is configured as the active search domain for the interface or resolver service, then verify the setting with resolvectl status or nmcli device show.