How to forward local DNS queries to a VM when macOS is in offline mode? For a project I need to intercept/redirect DNS queries to a VM, which in turn runs dnsmasq. This VM is hosted by xhyve and when connected to the network, the setup works well; I have an file in /etc/resolver.conf/test.io which has:


nameserver 192.168.64.20
search_order 1


Doing dig node.test.io @192.168.64.20 or dig node.test.io give the expected results.

But when going offline, there is a problem. It seems that when macOS is not connected to a network, it only allows /etc/resolver.conf/* entries to work when they use 127.0.0.1.

I tried setting up a port-forwarding, like:


$ echo "                           
rdr pass inet proto udp from any to 127.0.0.1 port 53 -> 192.168.64.20 port 53
" | sudo pfctl -ef -


and changing /etc/resolver.conf/test.io to:


nameserver 127.0.0.1
search_order 1


However, the domain test.io can not be found when I try to do a nslookup or dig node.test.io @localhost. The VM is still reachable as dig node.test.io @192.168.64.20 still gets resolved.

scutil --dns gives the following:


resolver #9
  domain   : test.io
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)
  order    : 1


Note: nslookup does not seem to handle resolver well, so I have also tried to use curl/wget and the browser to see if queries got resolved correctly. Also, no difference with dns-sd. All failed...
In disconnected mode there is no DNS query going at all... We solved this by adding a TUN/TAP device to the macOS node and 'pretend' with this that it is connected.