Benyamin Limanto

Just Random Thought from myself

DNS in systemd land using resolvectl : Temporary set, get, status, and clear cache

Total Views

211 views

This is a pretty simple post/notes from my experience with DNS on linux using Fedora/EL based or any systemd-resolved based DNS client. With windows, we have ipconfig command to control the cache of the dns also netsh command to control IP. Most of the time, we can clean the cache just using ipconfig /flushdns, but how do we do it on linux? Well, we can use resolvectl. This command line interface, is a command that help us working with systemd-resolved. Some argue we can just edit /etc/resolv.conf, but it’s not permanent, and sometimes broke the system.

It’s quite fascinating how fragmented the tools on Linux for long time, until Red Hat standardized it. Tbh, for IP/DNS client control and automation, we already has nmcli, but it require us to make the interface turned off then on in order to apply new config. It (up/down interface) doesn’t clear the DNS cache that already present. So I start tinkering more with my beloved search engine bing (now days, Bing is better for me than google, imho). I tried to find tools that in par with ipconfig, and resolvectl is the one I need.

With resolvectl, you can also check the DNS server address, and even set temporary DNS server address as you need, or even clean up the DNS cache. So in short there are several useful command, that I think we can use for these type of task, such as :

  1. Clear Cache
    We can use resolvectl flush-caches

  2. Get status
    We can use resolvectl status, or resolvectl status {interface}, eg. resolvectl status wlp3s0

  3. Get DNS Server Address
    We can use resolvectl dns, or resolvectl dns {interface}, eg. resolvectl dns wlp3s0

  4. Set DNS Server Address
    We can use resolvectl dns {ip}, or resolvectl dns {interface} {ip}, eg. resolvectl dns wlp3s0 1.1.1.1. You MUST use IP for the DNS server address, no domain name can be used for the DNS server address.

This command isn’t permanent, as we know that nmcli/network manager control the whole config, and will override it when the connection is restarted/disconnected. I hope this is useful for some people, because in my case, I need to set my local BIND9 for spoofing mailing server mx record on 2 VMs on my laptop, I tried to deploy mailu.io mail server for local test. So BIND9 need to be set on the computer, in order to be used by the virt/KVM VMs. With temporary set the DNS Server, I can introduce non-existent domain using BIND9 local DNS Server.

There are notable source that’s useful, such as
[1] https://unix.stackexchange.com/a/334475/356335
[2] https://wiki.archlinux.org/title/Systemd-resolved#Manually
[3] resolvectl -h or man resolvectl


Comments

Leave a Reply. I will come back and maybe we can have some conversation 🙂

This site uses Akismet to reduce spam. Learn how your comment data is processed.