List and change DNS servers on Linux with resolvectl
resolvectl, systemd-resolve and netplan commands to show and change the DNS servers of a Linux system.
Quick reference to list and change the DNS servers used by a Linux system running systemd-resolved.
List the DNS servers in use
resolvectl status
resolvectl status | tail
# older systems
systemd-resolve --status
# stub resolver configuration
tail /etc/resolv.conf
Change the DNS settings
On a distribution using systemd-resolved (for example Arch Linux), set the DNS server and search domain per interface:
sudo systemd-resolve --interface wlp2s0 --set-dns 192.0.2.10 --set-domain server01.example.com
On Ubuntu with netplan, edit the netplan configuration and apply it:
sudo netplan apply
Notes
- Which tool manages DNS depends on the distribution (systemd-networkd, netplan, netctl...). Check which one is active before changing settings.
systemd-resolveis the older command name;resolvectlis its replacement.