2

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.

  • same problem on Mojave/10.14.6 – febeling Sep 6 at 12:32
5

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.

  • Wouldn't it be the job of the .plist launchd configuration in ~/Library/LaunchAgents to declare as which user this server should run? – febeling Sep 6 at 12:34
  • Sounds like a security risk, but the answer here talks about a solution that uses /Library/LaunchDaemons instead. – ebelisle Sep 11 at 3:24
  • it only works if you use elevated privileges, so why would using the feature that launchd provide for doing that be security risk? – febeling Sep 11 at 10:47
  • It sounds like a security risk because you're granting root permissions to a configuration. As to whether it actually is a security risk, I leave that as an exercise for the reader. – ebelisle Sep 12 at 19:03

You must log in to answer this question.

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