example.com into IP addresses your system can route traffic to. On Linux, name resolution follows a layered order: the system checks /etc/hosts for local overrides first, then queries the DNS resolvers listed in /etc/resolv.conf (or managed by systemd-resolved on modern Ubuntu). Understanding this stack lets you override specific names locally, point your system at fast public resolvers, and quickly diagnose why a hostname is not resolving as expected.
Configuring /etc/resolv.conf
/etc/resolv.conf tells the system which DNS servers to query and which domain suffixes to append to short names.
On systems running
systemd-resolved, /etc/resolv.conf is typically a symlink to a file managed automatically by the service. Editing it directly may result in your changes being overwritten. Configure DNS through Netplan or resolvectl instead to ensure persistence.systemd-resolved
Most modern Ubuntu installations usesystemd-resolved as the local DNS stub resolver. It listens on 127.0.0.53 and caches responses to improve lookup speed.
nameservers block to your Netplan configuration:
sudo netplan apply for the change to take effect.
Local Overrides with /etc/hosts
/etc/hosts is checked before any DNS query is made. Use it to define local hostname mappings or override public DNS for specific names.
DNS Lookup Tools
- dig
- nslookup
- host
dig is the most powerful DNS query tool available on Linux. It gives you full control over record type, resolver, and output format.Reverse DNS Lookups
Reverse DNS maps an IP address back to a hostname. This is useful for auditing logs, verifying mail server identity, and network diagnostics.Flushing the DNS Cache
If you have recently changed a DNS record or/etc/hosts and need the system to pick up the new value immediately, flush the local cache:
Common DNS Record Types
| Record | Purpose |
|---|---|
| A | Maps a hostname to an IPv4 address |
| AAAA | Maps a hostname to an IPv6 address |
| CNAME | Alias that points one hostname to another |
| MX | Specifies mail servers for a domain |
| TXT | Stores arbitrary text; used for SPF, DKIM, and domain verification |
| NS | Identifies the authoritative nameservers for a domain |
| PTR | Reverse lookup — maps an IP address to a hostname |