1

I have a MacBook Pro running macOS 10.14.6 that is frequently connected to a privacy-focused VPN that tunnels all non-local traffic and handles all DNS requests. However there is one hostname that I would like my local network's DNS server to handle (as specified by the local DHCP server). The reason is that depending on which local network my MacBook Pro is connected to this hostname may resolve to a local IP address, and in that case I don't want traffic to it to be tunneled through the VPN.

I've learned that I can override what DNS server is used to resolve a domain name by creating a file at /etc/resolver/hostname.domain and with the contents nameserver [ip address] where hostname.domain is the fully qualified domain name. However that only works if the IP address of the DNS server I want to use remains consistent. What I want it to do is use whatever DNS server is served by my local network's DHCP server.

Is there any way I can accomplish this using existing features of macOS or third party software?

In case it's relevant, the VPN's DNS server is provided and setup at connection time, and is not guaranteed to be the same IP address every time.

(I could write a script to do this by having it run whenever the network connection changes, checking the system's current local IP address, and then changing the /etc/resolver/hostname.domain file to point to the correct server but I'm trying to avoid having to do that work if possible!)

2
  • Would a (local) dnsmasq installation be an option for you? It's quite simple to set up, yet could give you the required flexibility.
    – not2savvy
    Nov 12, 2019 at 7:13
  • 1
    @not2savvy I've never used dnsmasq before but I'm certainly willing to consider it
    – Bri Bri
    Nov 12, 2019 at 7:15

1 Answer 1

3

You could configure dnsmasq to

  • use your local DNS as an upstream server for the domain in question
  • use the VPN's DNS as the upstream for all other requests

This can be achieved by configuring a domain dependent upstream server in /etc/dnsmasq.conf, for example:

server=/hostname.domain/dns.server.local

Then change the VPN configuration to use your dnsmasq setup as its DNS server.

dnsmasq can be easily installed with Homebrew as follows:

brew install dnsmasq

Note that, in such a setup, the configuration file is located in $(brew --prefix)/etc/dnsmasq.conf. This post about using dnsmasq on macOS for local development may be provide you with some additional hints.

3
  • The VPN's DNS server is provided at connection time and is not guaranteed to be the same IP address each time I connect to it. Will it be possible to make use of dnsmasq in that case?
    – Bri Bri
    Nov 12, 2019 at 16:35
  • How is the DNS server of the VPN determined? If it is a domain that resolves to changing IP addresses, it's not a problem. If other than that, I wonder where it comes from?
    – not2savvy
    Nov 12, 2019 at 17:15
  • There's no hostname for the DNS server. The VPN is an OpenVPN server and the DNS IP address is pushed from the VPN server
    – Bri Bri
    Nov 12, 2019 at 18:16

You must log in to answer this question.

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