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?
Best Answer
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:
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:
but after a few seconds (up to 40 seconds in my environment) it should be populated:
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.