To learn, I am writing my own caching DNS server (à la dnsmasq, but in Python instead). From DHCP, NetworkManager obtains upstream nameservers and places them in /etc/resolv.conf. My system also looks in /etc/resolv.conf to find nameservers to query.

I need to place my own DNS server ( in /etc/resolv.conf so my system will query it, but NetworkManager will overwrite the file. If I disallow/configure NetworkManager not to overwrite /etc/resolv.conf, my DNS server will not be able to find caching nameservers because NetworkManager doesn't write them there.

It seems that /etc/resolv.conf symlinks to /var/run/NetworkManager/resolv.conf, so I guess I could have my DNS server find upstream servers there? I'd just chattr -i /etc/resolv.conf to prevent NetworkManager from overwriting it. Is this how I'm supposed to do it, or is there a better way?


chattr will work. It tells NM to leave resolv.conf alone. Alternatively, seerc-manager in man NetworkManager.conf.

NM will always write to it's internal resolv.conf in var/run, so you could scrape that. Or you use nmcli -f all device show, or use a dispatcher script (man NetworkManager).

Finally, you could write your own DNS plugin. But that requires you to rebuild NM from source, and the plugin API is not public/stable either.

  • Thanks for mentioning so many good options! Reading about rc-manager in man networkmanager.conf, I see it will always write to the runtime directory regardless of what it does with /etc. That's exactly what I needed and the easiest option. I didn't think of trying to get it from nmcli, and I didn't know NM has dispatcher scripts. And that explains how dnsmasq does it, since NM has a specific dnsmasq setting (i.e. must be a plugin). Thanks again!
    – Luc
    Apr 12 '17 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.