How to configure DNS on Linux
· Category: Linux
Short answer
Configure DNS in /etc/resolv.conf or via systemd-resolved, and use dig or nslookup to test resolution.
Steps
- Check current DNS:
cat /etc/resolv.conf
- Test resolution:
dig example.com
nslookup example.com
- With systemd-resolved:
resolvectl status
- Edit netplan or NetworkManager for persistent settings.
Tips
- Use public resolvers like 8.8.8.8 or 1.1.1.1 for troubleshooting.
dig +tracefollows the full resolution chain.- Check
/etc/hostsfor local overrides before DNS.
Common issues
resolv.confoverwritten: configure the network manager or use a symlink tosystemd-resolved.- DNS caching: flush with
resolvectl flush-caches.