2
I am trying to use dnsmasq to resolve certain known domains using its configuration, but let the rest of the requests go through to the normal DNS server assigned by DHCP. I cannot get this to work. When I set DNS to 127.0.0.1 through the Network panel, I have to hardcode the DHCP assigned DNS servers to dnsmasq's configuration. However, when I'm on a different network, e.g. at work, at a client, these addresses are different. I have to reconfigure anytime I change networks.
How can I configure OS X to use 127.0.0.1 AND any DNS servers assigned through DHCP?
If that is not possible, then how can I tell dnsmasq to obtain upstream DNS servers through DHCP?
Here's what I know so far.
/etc/resolv.conf on OS X is dynamic, it changes according to what you set in the Network preferences, or using DHCP. It changes anytime you reconnect. It's even deleted when you go offline. So as soon as I use 127.0.0.1 this is reflected in /etc/resolv.conf and I don't know if there is any place where the formerly DHCP-assigned DNS addresses can be found.
OS X doesn't use /etc/resolv.conf.head.
OS X doesn't use /etc/dhclient.conf where you can prepend DNS servers to the DHCP provided list.
/etc/resolver/tld.conf is not a solution, because that tries to use a DNS server based on matching a tld (it's good if you use .dev or something).
Edit: There is a screenshot of the Network DNS setting here that looks like what I want, but I have no idea how the author of that article achieved.
I understand, thanks. And you don't think there's a way to write out the DHCP servers into a text file for dnsmasq when connecting to a network? – Michiel van Oosterhout – 2013-11-25T17:54:24.557
1@michielvoo: There is, but it would to be messy. You'd need a way to detect when the network config changed (tricky), then detect which network interface was the primary (also tricky, I don't think
networksetup
has a way to show the live service order; maybe usescutil
?), then use something likeipconfig getpacket en1 | grep domain_name_server
to find the DNS servers (that's the easy part), and finally set dnsmasq (also easy, AIUI). – Gordon Davisson – 2013-11-25T20:37:43.203