Using dnsmasq for accessing multiple nameservers assigned by DHCP

Posted by Ash on Server Fault See other posts from Server Fault or by Ash
Published on 2012-05-31T03:57:41Z Indexed on 2012/05/31 4:42 UTC
Read the original article Hit count: 527

Filed under:
|
|

At my work desktop running openSUSE 11.4, I have a local network which gets its address, domain (work.site) and nameservers (10.100.1.1, 10.100.1.2) info through DHCP - which get written into /etc/resolv.conf

I get to access the internet using the work network, and these 2 nameservers end up returning the entries for any public domain name lookups on the internet.

I also have a private VPN that I end up connecting. The nameserver (10.111.1.1) and domain (private.site) are rarely bound to change for this network, but currently they're pushed by the openVPN client into networkmanager, and which also gets merged with the existing /etc/resolv.conf

My resolv.conf ultimately ends up looking like this:

search private.site work.site
nameserver 127.0.0.1
nameserver 10.111.1.1
nameserver 10.100.1.1

As you can see the 2nd nameserver from my work network was pushed out because of the max 3 entry limitations. It is fine still, but would be a problem if that nameserver goes down for maintenance or something.

So I found out that dnsmasq could help me here, and hence I setup dnsmasq just as a local DNS resolver without any DHCP support.

So right now this is my /etc/dnsmasq.conf:

resolv-file=/etc/resolv.conf
server=/private.site/10.111.1.1
server=/1.111.10.in-addr.arpa/10.111.1.1
listen-address=127.0.0.1
bind-interfaces
log-queries

I've made dnsmasq get the list of nameservers from /etc/resolv.conf since NetworkManager seems to be updating this list correctly (for a max of 3 nameservers). I'm able to resolve the host names in both the networks correctly.

So these are the questions I have:

  1. Is there a way I can make either NetworkManager or dhclient write out the list of nameservers somewhere else which I can make dnsmasq use as resolv-file ?
  2. How do I make dnsmasq use certain nameservers as the default for all queries ? Right now I notice that lookups for public domains on the internet are usually sent to both the nameservers - the one on work.site as well as private.site. It would be good if I can limit this only to work.site.

© Server Fault or respective owner

Related posts about dns

Related posts about vpn