0

I installed 4 Ubuntu VMs on my laptop and added for each of them extra network adapter with static ips for private network. I configured one of them to be the internal DNS server, added his IP to the resolvconf base file for each of the VMs and restarted the resolvconf and the networking services.

In the resolv.conf file I saw 2 DNS servers:

  1. my home router (I didn't add it in the resolvconf file)

  2. the one I added.

For some reason my internal DNS (the second in the resolv.conf file) does not work.

I didnt add in the dhcp.conf and interface file anything.

What is generating the router DNS IP to the file and why it is doesnt work if the internal DNS is second? (it is working if I manually switch between them)

1

On Ubuntu, NetworkManager automatically sets resolv.conf, and the latter will get overridden by NetworkManager after every connection reset. If you want to set the order of nameservers used and make it permanent, do the following:

  • Backup resolv.conf: sudo cp /etc/resolv.conf /etc/resolv.conf.backup
  • Remove resolv.conf in case it is a symlink: sudo rm -vf /etc/resolv.conf
  • Create a new resolv.conf: sudoedit /etc/resolv.conf and populate it with the following:
nameserver <IP_OF_YOUR_PRIMARY_DNS>
nameserver <IP_OF_YOUR_SECONDARY_DNS>

Since you want your internal DNS server to be the first one queried, <IP_OF_YOUR_PRIMARY_DNS> should be the IP address of that server.

  • Lock (set immutable bit on) resolv.conf against changes by NetworkManager: sudo chattr +i /etc/resolv.conf
  • Restart NetworkManager: sudo systemctl restart NetworkManager

References

  • Quoting from the resolv.conf manpage:

If there are multiple servers, the resolver library queries them in the order listed.

https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html

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.