dnsmasq not working oh Mac OS High Sierra

I have a service running on localhost on MacOS High Sierra.

curl foo.test 

does not work, but

curl localhost 

does.

To get to my setup, I installed dns using homebrew,

brew install dnsmasq

added my configuration to /usr/local/etc/dnsmasq.conf,

address=/test/127.0.0.1

and added a resolver file /etc/resolver/test:

nameserver 127.0.0.1

I've spent a day trying

  • dig foo.test
  • scutil --dns
  • dscacheutil -q host -a name foo.test

and nothing worked.

My eventual issue was not covered anywhere else, so I'm answering it here for someone else.


Solution 1:

tl;dr make sure you start dnsmasq as root.

To diagnose this problem, I used Console.app, and searched for dnsmasq.

  1. My first problem revealed in the logs:

    failed to create listening socket for 127.0.0.1: Address already in use
    FAILED to start up
    

To fix this, make sure dnsmasq is stopped:

brew services stop dnsmasq

then use Activity Monitor.app to kill any old dnsmasq processes.

After the socket conflict was removed, I attempted to start dnsmasq again:

brew services start dnsmasq # does not work

and now the logs in Console.app show

failed to create listening socket for 127.0.0.1: Permission denied
FAILED to start up

To fix this, I restarted the service as root:

brew services stop dnsmasq
sudo brew services start dnsmasq

Now

curl foo.test

works!

After this journey, I revisited all those dnsmasq help articles I read. The sudo was there all along and I skimmed over it. I'm posting this for the next person that forgets to start dnsmasq as root.