Score:0

dnsmasq and NetworkManager DNS

mp flag

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 8.8.8.8, 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
nameserver IP_MANDATED_BY_NETWORK_MANAGER

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 IP_MANDATED_BY_NETWORK_MANAGER
nameserver MAINPC_IP
David avatar
cn flag
Do you have 2 DNS servers you question is not clear.
mp flag
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.
Score:0
mp flag

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
[main]
# Don't write /etc/resolv.conf, but will write /run/NetworkManager/resolv.conf
dns=none

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
nameserver 127.0.0.53

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
resolv-file=/run/NetworkManager/resolv.conf

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.