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

  1. Check current DNS:
cat /etc/resolv.conf
  1. Test resolution:
dig example.com
nslookup example.com
  1. With systemd-resolved:
resolvectl status
  1. Edit netplan or NetworkManager for persistent settings.

Tips

  • Use public resolvers like 8.8.8.8 or 1.1.1.1 for troubleshooting.
  • dig +trace follows the full resolution chain.
  • Check /etc/hosts for local overrides before DNS.

Common issues

  • resolv.conf overwritten: configure the network manager or use a symlink to systemd-resolved.
  • DNS caching: flush with resolvectl flush-caches.