9

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!

8
  • Thanks for the suggestion. I've removed the line but it still doesn't work unfortunately.
    – Steve
    Commented Dec 20, 2016 at 10:13
  • Which method do you use to assign host names? The /etc/hosts or /usr/local/etc/hosts/ file method?
    – klanomath
    Commented Dec 20, 2016 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
    Commented Dec 20, 2016 at 10:28
  • Please add this part of the dnsmasq.conf file to your question.
    – klanomath
    Commented Dec 20, 2016 at 10:29
  • 1
    I had the same experience as @ortonomy Commented Dec 14, 2017 at 22:22

2 Answers 2

6

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
...
5
  • 3
    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
    Commented Dec 20, 2016 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
    Commented Dec 20, 2016 at 23:06
  • 2
    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
    Commented Dec 21, 2016 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
    Commented Dec 21, 2016 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
    Commented Dec 22, 2016 at 5:31
2

The .dev TLD is no longer usable by developers as a private TLD. I ran into this, and had to change things to use ".priv" or something else instead. The ".dev" TLD is no longer a private thing, as it now belongs to Google, and is treated in a special way by Chrome and other browsers.

Following is a clip from the following article: https://www.tomshardware.com/news/google-enforces-https-tld-hsts,35564.html

"Google announced that 45 of the top-level domains (TLDs) it recently purchased, including .dev, .app, .eat, and so on, will enforce HTTPS security, guaranteeing that all connections to sites using those TLDs will be over encrypted channels."

1
  • ths .test tld is great for local, and in fact designed for exactly this case!
    – djeikyb
    Commented Oct 10, 2022 at 20:21

You must log in to answer this question.

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