8

I'm running dnsmasq on a 2016 MBP running Mac OS Sierra (10.12.1) but I'm unable to ping any .dev addresses despite having what I believe is the proper config. Running dig does return sane output.

/usr/local/etc/dnsmasq.conf

resolv-file=/usr/local/etc/resolv-dnsmasq.conf
address=/.dev/127.0.0.1

/etc/resolver/dev

nameserver 127.0.0.1

/usr/local/etc/resolv-dnsmasq.conf

nameserver 8.8.8.8
nameserver 8.8.4.4

My DNS server list in System Preferences has only one entry pointing to 127.0.0.1.

When I run dig on a .dev address I get the following output:

; <<>> DiG 9.11.0-P1 <<>> test.dev
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36126
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;test.dev.          IN  A

;; ANSWER SECTION:
test.dev.       0   IN  A   127.0.0.1

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Dec 19 23:13:20 PST 2016
;; MSG SIZE  rcvd: 42

I'm able to load external sites like google.com perfectly but if I try accessing a local web server or even pinging a .dev address it fails.

Help would be appreciated!

  • Thanks for the suggestion. I've removed the line but it still doesn't work unfortunately. – Steve Dec 20 '16 at 10:13
  • Which method do you use to assign host names? The /etc/hosts or /usr/local/etc/hosts/ file method? – klanomath Dec 20 '16 at 10:23
  • I'm not using either of those files. I've configured dnsmasq in such a way that it should be routing all traffic which matches the .dev pattern to localhost. This means I shouldn't have to manually enter every domain I want to reroute in my hosts file. – Steve Dec 20 '16 at 10:28
  • Please add this part of the dnsmasq.conf file to your question. – klanomath Dec 20 '16 at 10:29
  • 1
    I had the same experience as @ortonomy – Chris Carson Dec 14 '17 at 22:22
5

Your dnsmasq daemon isn't properly configured.

Your external resolver is working: all queries to non-dev hosts/domains are forwarded to 3rd-party DNS servers with the resolv-file=/usr/local/etc/resolv-dnsmasq.conf line - in your case the configured file contains two public Google DNS servers.

Your internal resolver doesn't resolve internal names though.

The line address=/.dev/127.0.0.1 or better address=/dev/127.0.0.1 will redirect any *.dev query to the host 127.0.0.1. An internal resolver is not needed then and the internal name server defined in /etc/resolver/dev is useless.

Compare this with the example in the dnsmasq.conf file:

# Add domains which you want to force to an IP address here.
# The example below send any host in double-click.net to a local
# web-server.
#address=/double-click.net/127.0.0.1

Any query for *.double-click.net will be redirected to 127.0.0.1 and to an arbitrary website served at localhost.

I strongly recommend to define a hosts.config file and enter/define all necessary hosts there:

Add a line addn-hosts=/usr/local/etc/hosts/hosts.conf in dnsmasq.conf. Then add a folder with sudo mkdir /usr/local/etc/hosts and create a file hosts.conf

sudo nano /usr/local/etc/hosts/hosts.conf

with the following content:

127.0.0.1   localhost
127.0.0.1   test.dev
127.0.0.1   test2.dev
...

After saving the file reload your dnsmasq daemon.

If you want to use different IPs for your host names e.g.:

127.0.0.1   localhost
127.0.0.2   test.dev
127.0.0.3   test2.dev
...

you'd have to add additional IPs with:

sudo ifconfig lo0 alias 127.0.0.2 up
sudo ifconfig lo0 alias 127.0.0.3 up
...
  • 1
    I understand your point about the internal resolver being useless but don't understand the need for the hosts.conf file. If dnsmasq was behaving correctly it should direct all dev addresses to localhost. Having to hardcode all the domains and subdomains in a host file takes away the benefit of using dnsmasq. – Steve Dec 20 '16 at 22:48
  • @Steve I don't know your setup but often (web-)developers use several different hostnames on the local machine and/or additional hosts in VMs or on other real machines. Then you need an easy to configure and lightweight DNS/DHCP server like dnsmasq. IMHO the purpose of dnsmasq is not to resolve local-only hostnames to localhost. This can be done easier by editing /etc/hosts directly with sudo nano ... or with a GUI like Gas Mask. – klanomath Dec 20 '16 at 23:06
  • 1
    The issue with the host file approach is that it breaks down if your web application relies on dynamically generated subdomains like the one I'm working on does. dnsmasq has been able to achieve my goal of redirecting everything with "dev" on machines running Linux in the past with the same config. – Steve Dec 21 '16 at 8:21
  • @Steve 1. DNS resolution is known to be wonky in OS X. 2. I don't think that the "black hole" name resolution approach follows an RFC standard. 3. In my test VM "name resolution" worked with your config for various virtual apache hosts (test.dev, test2.dev etc), but IIRC also ping. I may test the ping-thing again, I returned to a saved VM snapshot without dnsmasq installed though and it takes some time to set it up again to further investigate the issue. – klanomath Dec 21 '16 at 12:23
  • I'm not sure what changed but after installing an update to Mac OS dnsmasq appears to be working as it should. – Steve Dec 22 '16 at 5:31

You must log in to answer this question.

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