Make mDNSResponder use local DNS server?

I want to use dnsmasq when my Mac (Sierra) is not connected to a wifi network.

Configuring DNS servers in the Advanced Network Preferences dialogue box works fine for dig and nslookup, and I can see via tcpdump that these tools hit the local dnsmasq server.

It does not work for ping, curl and Golang binaries like the Cloud Foundry CLI. These are unable to resolve hosts, and don't attempt to communicate with the local nameserver. When I use dtruss for the cf Golang binary, I can see it opening /etc/hosts. I'm not sure how to spot it attempting to talk to name servers though.

If I stop the mDNSResponder and mDNSResponderHelper services, ping and curl take a little longer to fail with cannot resolve api.local.pcfdev.io: Unknown host, but still fail nonetheless, and without trying to hit the local name server.

Any ideas how on Earth I can get macOS to use my local name server when I'm offline?


I think mDNSResponder - with a running PCF Dev VirtualBox VM but no LAN/WLAN - is missing a default gateway or gets the wrong one. If your interfaces aren't connected or all interfaces are inactive then no default gateway exists.

You can check this with:

netstat -r -f inet
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
127                localhost          UCS             1        0     lo0
localhost          localhost          UH              5     1380     lo0
192.168.11         link#7             UC              4        0 vboxnet
224.0.0            link#1             UmCS            2        0     lo0
224.0.0.251        link#1             UHmWI           1        0     lo0

To circumvent this you can do the following:

Requirement: a proper configuration of dnsmasq as published in your q & my a. You may have to deactivate all interfaces.

Duplicate a Location profile in System Preferences > Network and rename it to e.g. pcdev with VLAN.

Choose an interface (e.g. Wi-Fi) in the left pane and hit the gear at the bottom of the left pane > Manage Virtual Interfaces. Hit the ⊞-button and add a "New VLAN...". Rename it to VLAN, choose 1 as tag and an interface.

Configure the interface: Manually with an arbitrary but unused IP e.g. 10.228.8.226/Mask 255.255.0.0/Router 10.228.0.1 and DNS-server 127.0.0.1. Apply the settings with the button Apply. IP (+ Mask) and Router have to be in the same network.

Check the routing table again. First it will look like this:

netstat -r -f inet
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
10.228/16          link#8             UC              2        0   vlan0
127                localhost          UCS             1        0     lo0
localhost          localhost          UH              4     1380     lo0
192.168.11         link#7             UC              2        0 vboxnet
224.0.0            link#1             UmCS            2        0     lo0
224.0.0.251        link#1             UHmWI           1        0     lo0

but after a few seconds (up to 40 seconds in my environment) it should be populated:

netstat -r -f inet
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            10.228.0.1         UGSc            3        0   vlan0
10.228/16          link#8             UCS             2        0   vlan0
10.228.0.1/32      link#8             UCS             2        0   vlan0
10.228.0.1         link#8             UHRLWIir        4        0   vlan0     18
10.228.8.226/32    link#8             UCS             2        0   vlan0
10.228.255.255     ff.ff.ff.ff.ff.ff  UHLWbI          1        3   vlan0
127                localhost          UCS             1        0     lo0
localhost          localhost          UH             26     1494     lo0
192.168.11         link#7             UC              3        0 vboxnet
192.168.11.11      8:0:27:35:78:e2    UHLWIi          2        3 vboxnet   1192
192.168.11.255     ff:ff:ff:ff:ff:ff  UHLWbI          1        3 vboxnet
224.0.0/4          link#8             UmCS            3        0   vlan0
224.0.0.251        1:0:5e:0:0:fb      UHmLWI          1        0   vlan0
239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI          1        3   vlan0
255.255.255.255/32 link#8             UCS             1        0   vlan0

Now try again to ping api.local.pcfdev.io/tcp.local.pcfdev.io/local.pcfdev.io.


While testing I got the impression that some arbitrary IP pinging (ping 192.168.11.11, ping 127.0.0.1 accelerated the reconfiguration).


If you are within reach of a known WLAN switch back to your common Location profile.


This is tested (and working) in a VMwareFusion Sierra VM and the nested pcfdev-ubuntu VirtualBox VM. In this environment I can't really simulate a missing Wi-Fi connection, because there is no Wi-Fi interface available. Instead I deactivated all interfaces (2 x Ethernet) in the Sierra VM.