Yosemite localhost resolver and dnsmasq fails offline
Asked Answered
F

3

10

Setup my local dev environment similar to this post and everything was working fine but recently I am unable to access my local dev domains when I am offline. When I am connected to the internet it works fine. I'm wondering if something changed with how resolver is used in Yosemite. It seems as if resolver rules are ignored if I'm offline.

dnsmasq.conf:

address=/.dev/127.0.0.1
listen-address=127.0.0.1

/etc/resolver/dev

 nameserver 127.0.0.1

When online:

ping -c 1 mydomain.dev
PING mydomain.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.038 ms

--- mydomain.dev ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.038/0.038/0.038/0.000 ms

scutil --dns
resolver #1
search domain[0] : nomadix.com
nameserver[0] : 203.124.230.12
nameserver[1] : 202.54.157.36
if_index : 4 (en0)
flags    : Request A records
reach    : Reachable

resolver #2
domain   : dev
nameserver[0] : 127.0.0.1
flags    : Request A records, Request AAAA records
reach    : Reachable,Local Address

when offline:

ping -c 1 mydomain.dev
ping: cannot resolve mydomain.dev: Unknown host

scutil --dns
No DNS configuration available
Fremont answered 10/11, 2014 at 9:44 Comment(0)
I
0

I've been checking this question for months hoping for an answer. I believe this will help when 10.10.4 drops: http://arstechnica.com/apple/2015/05/new-os-x-beta-dumps-discoveryd-restores-mdnsresponder-to-fix-dns-bugs/

Apple are replacing discoveryd with mDNSresponder (like it used to be)

Ictus answered 27/5, 2015 at 5:54 Comment(3)
Very interesting. This makes me wonder if this Ars article about how to manually replace discoveryd with mDNSresponder may be the only currently available solution to this problem. I will give it a shot and report back.Fremont
I would try it too but I don't have access to 10.9 files! I'll be interested to hear how you go.Ictus
So far this is the "solution" for me. El Capitan fixed the issue without any changes to my setup.Fremont
R
2

OSX Yosemite + resolver + dnsmasq offline === resolved !!

when you're offline every interface on your computer, but 127.0.0.1, goes down.

so if you want to have a dns resolution your dns server have to listen to 127.0.0.1. In my case it's dnsmasq I choose because you don't have to be a sys admin to make it work, and it does !

following those simple steps I got it working:

1) brew install dnsmasq

2) cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

if like me it's not properly installed in /usr/local/opt you should be able to read in the brew installation debug lines something like this :

make install PREFIX=/usr/local/Cellar/dnsmasq/2.72

in this case run the following command:

ln -s /usr/local/Cellar/dnsmasq/2.72 /usr/local/opt/dnsmasq

and then back to step 2

3) vi /usr/local/etc/dnsmasq.conf

and add your domains like this for exemple:

address=/foo.dev/192.168.56.101

where in that case every url ending with foo.dev (http://www.foo.dev, http://foo.dev, http://what.ever.you.want.foo.dev, etc...) will be resolved as 192.168.56.101 (this is the kind of ip you have using Virtualbox, 192.168.56.*)

4) sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

5) try it before putting it into the resolver

nslookup foo.dev 127.0.0.1

and expect this :

Server:  127.0.0.1
Address:     127.0.0.1#53
Name:    foo.dev
Address: 192.168.56.101

6) mkdir -p /etc/resolver

vi /etc/resolver/dev

add those two lines :

nameserver 127.0.0.1
search_order 1

7) ping foo.dev or hint http://foo.dev or http://so.cool.foo.dev in your browser address bar and you're good to go !!!

8) Be happy !! You can work offline AGAIN !!!!

Roney answered 7/11, 2015 at 12:32 Comment(2)
I'm not on Yosemite anymore but on El Capitan this is working. The only change I made was search_order 1 in /etc/resolver/dev. This works fine with dnsmasq still set to respond on address 127.0.0.1 so it works for local nginx or apache or whatever webserver you want to run not just vagrant/docker/virtualbox.Fremont
Apparently I spoke/accepted too soon. The setup in my question "just works" on El Capitan with no changes. I'll see if I can find a Yosemite box somewhere to test on or let others chime-in if this is indeed a solution on Yosemite.Fremont
I
0

I've been checking this question for months hoping for an answer. I believe this will help when 10.10.4 drops: http://arstechnica.com/apple/2015/05/new-os-x-beta-dumps-discoveryd-restores-mdnsresponder-to-fix-dns-bugs/

Apple are replacing discoveryd with mDNSresponder (like it used to be)

Ictus answered 27/5, 2015 at 5:54 Comment(3)
Very interesting. This makes me wonder if this Ars article about how to manually replace discoveryd with mDNSresponder may be the only currently available solution to this problem. I will give it a shot and report back.Fremont
I would try it too but I don't have access to 10.9 files! I'll be interested to hear how you go.Ictus
So far this is the "solution" for me. El Capitan fixed the issue without any changes to my setup.Fremont
R
-4

The problem is when you are offline you should specify a resolver for the root domain '.': When we search for www.google.com There is a "." (root domain) added automatically at the end like: www.google.com.

So all you have to do is :

Set all your network interface dns servers to 127.0.0.1:

networksetup -setdnsservers Ethernet 127.0.0.1

networksetup -setdnsservers Wi-Fi 127.0.0.1

...

Create a file /etc/resolver/whatever:

nameserver 127.0.0.1
domain .

See this question for more details

Renarenado answered 23/2, 2015 at 10:55 Comment(1)
This does not work at all on OS X 10.10. Not only that, it breaks DNS resolution when the network comes back online.Layne

© 2022 - 2024 — McMap. All rights reserved.