I have a small network of computers that can be moved between sites.

These computers are connected to a switch, and one of them acts as DHCP server and DNS server via dnsmasq for this network, let's call it MAINPC.

The DNS is used only to provide name resolution between these computers, and if you add another computer to the LAN, it will be added to the DNS via dnsmasq.

The rest of DNS names have to be handled by secondary DNS server, here comes my problem.

I don't want to hard code a secondary DNS server like, because sometimes you will plug this whole network inside another network, with its own DNS server. I want dnsmasq to give as secondary DNS the NetworkManager provided DNS.

What I've done is set dns=default in a conf file in /etc/NetworkManager/conf.d/. This causes NetworkManager to write the DHCP mandated DNS to /etc/resolv.conf, which is read by dnsmasq. This solves most of the problems.

The PC's that are using MAINPC as DNS server work fine, they direct their queries to MAINPC, which answers from the local domain if possible, and if not redirects to the DNS mandated by NetworkManager.

But MAINPC itself is only using the DNS mandated by NetworkManager, and is unable to resolve the other PCs in the network. In a nutshell, it is not using it's own DNS server as primary.

How can this be achieved? Basically I just need that my /etc/resolv.conf looks like:

# Generated by NetworkManager
search internal_domain other_domain
nameserver MAINPC_IP

Currently I managed to have it like, by forcing the MAINPC DNS server in a /etc/netplan/ file:

# Generated by NetworkManager
search internal_domain other_domain
nameserver MAINPC_IP
  • 1
    Do you have 2 DNS servers you question is not clear.
    – David
    Feb 17, 2022 at 18:00
  • The small portable network of pcs has a dns. Imagine it like the pcs of a Autonomous car. They have an internal dns for finding each other. You can connect the car network to another network via wifi, and in this case, non local domain names should be redirected to the dns provided by the wifi.
    – Victor
    Feb 17, 2022 at 19:07

1 Answer 1


I believe I managed to solve it.

NetworkManager will write the DNS information it receives to /run/NetworkManager/resolv.conf in addition to /etc/resolv.conf

First I disable the writing to /etc/resolv.conf by:

$ cat /etc/NetworkManager/conf.d/disable-resolv-conf.conf
# Don't write /etc/resolv.conf, but will write /run/NetworkManager/resolv.conf

I replace /etc/resolv.conf with a file containing a localhost IP to use dnsmasq as DNS server.

$ cat /etc/resolv.conf 
search my-private.lan

Finally, I instruct dnsmasq to read /run/NetworkManager/resolv.conf instead of /etc/resolv.conf.

cat /etc/dnsmasq.d/networkmanager-dns.conf
# NetworkManager will write here the DNS obtained from the networks it connects to
# We will use these as secondary DNS

And in my machine I had to change permissions of /run/NetworkManager directory, as the default would not let other users read it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .