1

I have read all the answers I can find about setting up dnsmasq as a local DNS server for development. But I can't make it work for my case. Most out there want 127.0.0.1 to be resolved for names in the .dev domain.

In my case I have a VirtualBox virtual machine running windows in my MacBook Air. This Windows runs SQL server express. It is set up with two interfaces - a network bridge - to share the external wifi interface and be a peer on my local network when I am on line. I also have VirtualBox set up a host-only network. The subbnet is 192.168.56.0/24 with my Mac being .1 and the Windows virtual machine being .2.

dnsmasq running on the MacBook support this and from a Windows perspective it does everything perfectly, on-line and off. Using its ability to assign complete domains an address it gives .rab to 192.168.56.1 and .tig to 192.168.56.2

On the Mac itself I am developing a nodejs application, which is a web server (so it needs a domain name - lets say abc.rab - my Mac is called Rabbit) and to acccess the Windows machine's database (called abc.tig - Windows machine is called Tigger). Here things don't seem to work.

I wrote a small nodejs program to test DNS lookup

'use strict';
const dns = require('dns');
dns.lookup('abc.tig',(err,add,family) =>{
    console.log('addresses:',add);
});

and it can't find the address. Yet on the terminal this DNS lookup works

alan@rabbit:~/Documents$nslookup abc.tig
Server:     127.0.0.1
Address:    127.0.0.1#53

Name:   abc.tig
Address: 192.168.56.2

alan@rabbit:~/Documents$

In a web browser abc.rab also tells me it can't find the domain name.

As I said, I had set up dnsmasq to run on all interfaces. In the network properties for my Wi-Fi interface I have set nameservers as 127.0.0.1 and 8.8.8.8

In /etc/resolver I created a file called literally 'whatever' (the answer that I read about this didn't make it clear if it literally had to be called that or it was just an example) with

nameserver 127.0.0.1
domain .

in it

Obviously there are two name resolution processes in place. The mDNSResponder and dnsmasq are both shown running in my activity panel. I presume different ones are being used by the terminal and by my application

What am I doing wrong here? (writing and testing this I am currently online)

(PS I have a similar setup working on my home development machine running linux working perfectly - I just want to be able to develop on the move).

2

mDNSResponder and dnsmasq have to run both: dnsmasq is the lightweight DNS-server (and DHCP/Router) and mDNSResponder is responsible for all local queries.


To set up dnsmasq in OS X in your environment properly do the following:

Remove any DNS-server in the network preferences of the dnsmasq host (your MacBook Air) except 127.0.0.1.

Remove any DNS-server in the network preferences of the VMs in use and replace them by the IP-address of the VM-host (your MacBook Air).

Remove any file in /etc/resolver/. Usually they aren't necessary. You may keep them but then they probably should have this form:

/etc/resolver/rab with the content

nameserver    127.0.0.1

/etc/resolver/tig with the content

nameserver    127.0.0.1

The logic behind this is mentioned in resolver(5):

domain
    Domain name associated with this resolver configuration. This option is normally not     required by the Mac OS X DNS search system when the resolver configuration is read from a     file in the /etc/resolver directory. In that case the file name is used as the domain name.     However, domain must be provided when there are multiple resolver clients for the same     domain name, since multiple files may not exist having the same name. See the SEARCH     STRATEGY section for more details.

Then edit /usr/local/etc/dnsmasq.conf and add/modify

server=/rab/192.168.0.2 #your main IP-address or 127.0.0.1
server=/tig/192.168.0.2 #your main IP-address or 127.0.0.1
server=8.8.8.8 #forwarder
addn-hosts=/usr/local/etc/hosts/hosts.conf

Now add the hosts.conf file in /usr/local/etc/hosts/ with the content:

127.0.0.1   localhost
192.168.56.1    abc.rab
192.168.56.2    abc.tig

Then restart dnsmasq with launchctl to load the new conf files.


Since your Windows VM already is in the bridged Wi-Fi network you can completely dump the host-only network and modify /usr/local/etc/hosts/hosts.conf:

127.0.0.1   localhost
192.168.0.2 abc.rab #IP-address of the MacBook Air Wi-Fi interface
192.168.0.3 abc.tig #IP-address of the Windows bridge interface
  • Actually - although I just about understand the logic of what you suggest, you DO have to have an entry in /etc/resolver - and my one using domain . as the second line gives you much more flexibility. It is necessary for offline mode as although all the terminal requests for the domain worked, my node test program didn't until I added back in my whatever file. I found an issue with my original dnsmasq.conf where I was limiting dns services to localhost and local host. I am not sure if it was that or your addn-hosts directive that made it all work – akc42 Feb 9 '16 at 21:21
  • @akc Hmm In OS X the resolver files usually are not needed (source). I didn't test my config with your nodejs program though. I added an explanation in the resolver part of my answer. – klanomath Feb 9 '16 at 21:36
  • If you switch off ALL your interfaces and then you do not see a resolver unless you add the domain . line -see serverfault.com/questions/22419/… the accepted answer with the 17th July update – akc42 Feb 9 '16 at 21:49
  • @akc42 Hmm I tested my answer in a Parallels environment. If I switch off all ifs the host-only and the nat interface of Parallels are also gone (which would render the whole env useless). Probably I didn't really get what offline in your question meant... ;-). BTW why do you go offline or what does "offline" really mean? – klanomath Feb 9 '16 at 22:10
0

If you want to do away with all the setting up of DNS - just choose static IP for all your virtual machines and have your apps connect to the host names provided by xip.io

$ host 192.168.56.2.xip.io
192.168.56.2.xip.io has address 192.168.56.2

If you really need abc.tig to resolve, you can overload your /etc/hosts file with sudo -e /etc/hosts and point things as follows:

abc.tig       192.168.56.2.xip.io

Hopefully someone with dnsmasq advice will see your post and offer some guidance, but for my time - just using IP via xip.io is far easier to debug, maintain, setup and grok. Spend your energy on the app and not the infrastructure to setup VM if your vm doesn't handle all the networking for you like docker and xhyve are working to automate (but aren't there yet IMO).

  • does this work when I am offline? – akc42 Feb 9 '16 at 16:31
  • 1
    @akc42 no - it's live, actual network/real-world DNS. Caching might help for a while, but this isn't an isolated tool. You might also look at implementing mdns if you want your tools to work without a DNS server. node/npm has a nice mdns package to use that instead of DNS. – bmike Feb 9 '16 at 17:58
  • I don't really need another too. dnsmasq works great normally (I have it powering my home network not problem). Its the relationship between it and the mac dns lookup mechanisms that is the problem here. I thought I had followed all the right instructions, but apparently not because it doesn't work – akc42 Feb 9 '16 at 18:10
  • Sounds good - I +1 your question in hopes that a dnsmasq expert has debugging info. Please post an answer if you find out what to do - it will help others :-) – bmike Feb 9 '16 at 18:12

You must log in to answer this question.

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