dnsmasq quits with "abort"

I had the same symptoms that were described in the question as well as a new and stale PID file in /var/run/dnsmasq.pid every 10 seconds. I am working with dnsmasq 2.77 installed via Homebrew, and macOS 10.12.5. I had 29,000+ hosts defined in /etc/hosts, which was fine until some point - upgrading macOS or dnsmasq, perhaps.

I made a backup of /etc/hosts and then removed all lines from the hosts file except as follows.

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

255.255.255.255 broadcasthost

After trying it with the minimal hosts file, I found dnsmasq working.

ps aux | grep dnsmasq
sudo lsof -n -i4TCP:53 | grep 'LISTEN'

But I didn't lose the definitions of hosts to block. They were migrated to the dnsmasq configuration file. A host definition in /etc/hosts looks like the following sample.

0.0.0.0 analytics.google.com

The corresponding definition in dnsmasq.conf looks like the following sample.

address=/analytics.google.com/0.0.0.0

Encouraged, I then added back to the hosts file all of my own definitions for my home LAN, my work LAN, some remote host nicknames, and local virtual hosts.


Christopher's answer set me on the right path: the problem was indeed /etc/hosts.

After some trial and error I determined that dnsmasq would crash if /etc/hosts contains a domain name with more than 49 characters.

Since I didn't really want to use /etc/hosts in the first place, I was able to fix the problem by simply adding -h to the command line, or uncommenting the line that says no-hosts in /usr/local/etc/dnsmasq.conf


The launch daemon is restarted because you forgot the initial step to create a dnsmasq.conf file. The conf file is referenced in the plist!

Solution:

sudo brew services stop dnsmasq
cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

Modify the config file (e.g listening port/interfaces/domain names etc). Then I recommend to copy and launch the launch daemon plist manually - this step has to be executed only once:

sudo cp /usr/local/opt/dnsmasq/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons/
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist 

I have no explanation why the process is aborted starting it manually!