0

I have a Mac that I do web development on. I have my projects set up to be accessible at addresses like project1.dev, project2.dev, etc. I got tired of updating my "/etc/hosts" file, though, so I installed Dnsmasq. It works great! Now I can run ping doesnotexist.dev and get replies from 127.0.0.1, which is exactly what I want.

The Mac also has a Windows XP VirtualBox virtual machine installed on it. I'd like for that virtual machine to also be able to ping doesnotexist.dev and get replies, but I want the replies to come from the Mac's LAN IP instead of 127.0.0.1. As I understand it, this is possible with Dual DHCP DNS Server. I installed it on the virtual machine and edited the "DualServer.ini" file. I simply uncommented the "DNS" line of the "[SERVICES]" section and added *.dev=192.168.1.50 to the "[SERVICES]" section. That didn't work, though. I saw this thread and decided to install the Microsoft Loopback Adapter, but I didn't know how to go about configuring it. So now I'm stuck.

How do I set up Dual DHCP DNS Server so that pinging doesnotexist.dev gets replies from the Mac's LAN IP?

3 Answers 3

0
+100

You should use dnsmasq's parameter -A. From dnsmasq's documentation:

   -A, --address=/<domain>/[domain/]<ipaddr>
          Specify  an IP address to return for any host in the given domains.  Queries in the
          domains are never forwarded and always replied to with  the  specified  IP  address
          which  may  be IPv4 or IPv6. To give both IPv4 and IPv6 addresses for a domain, use
          repeated -A flags.  Note that /etc/hosts and DHCP leases override this for individ-
          ual names. A common use of this is to redirect the entire doubleclick.net domain to
          some friendly local web server to avoid banner ads. The domain specification  works
          in  the same was as for --server, with the additional facility that /#/ matches any
          domain. Thus --address=/#/1.2.3.4 will always return  1.2.3.4  for  any  query  not
          answered  from  /etc/hosts or DHCP and not sent to an upstream nameserver by a more
          specific --server directive.

So either adding --address=/dev/192.168.1.50 to dnsmasq command line or adding address=/dev/192.168.1.50 to dnsmasq's config file and restarting should do the trick.

Also, if you can't have your windows virtual-machine connect to the dnsmasq on the mac for dns queries, you could try to replicate the same behaviour on pDNS using wildcards...

3
  • pDNS looked much simpler for what I'm trying to do, so I tried it out and it worked! I would vote you up, but I don't have a high enough reputation. I will likely accept your answer and award the bounty, but I'll hold off for now in case somebody comes up with some other answer that's somehow better. I don't see a way for pDNS to just run silently in the background, though. Is running it with Hidden Start a bad idea?
    – Nick
    Commented Jul 10, 2013 at 22:56
  • You should be able to set it up as a service on Windows XP.
    – GnP
    Commented Jul 12, 2013 at 0:04
  • I saw that too, but I think that might be for the pro version or perhaps a different program altogether. Running pnds /? shows these switches: /ns, /po, /ca, /noca, /resolveall, /ho, and /log.
    – Nick
    Commented Jul 12, 2013 at 1:42
2

Overview of My Solution

I ended up using pDNS, as suggested by gnp. This is the entire contents of the hosts.txt file I used:

192.168.1.50 *.dev

I didn't like that I needed to always have a command window open, though, so I installed the free version of 4t Tray Minimizer, keeping the default hot key of Shift+Esc to minimize the active application to the tray. I wanted to automate the Shift+Esc part, so I wrote an AutoIt script that runs pDNS and immediately minimizes it to the tray. The script runs when Windows starts.

The Specific Steps

  1. Download and extract pDNS. I chose to put the extracted files in "C:\Applications\pDNS".
  2. Edit pDNS' hosts.txt file, making it look like what I have in the overview of my solution.
  3. Download and install the free version of 4t Tray Minimizer. Be sure to keep the "Launch 4t Tray Minimizer at Windows startup" checkbox checked. Also be sure to keep the "Minimize to tray" checkbox checked and the hot key set to "Shift+Esc". If you want to change the hot key, you'll have to also change the AutoIt script.
  4. Download and install AutoIt. When asked to select a default option for *.au3 files, be sure to keep the "Run the script" radio button selected.
  5. Set your preferred DNS server to 127.0.0.1.
  6. Create the following AutoIt script (I called mine "pDNS.au3") and put it in your "Startup" folder ("%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup"). Feel free to replace the OpenDNS IP with something else.

Run("C:\Applications\pDNS\pdns.exe /ns:208.67.222.222", "C:\Applications\pDNS")
WinWaitActive("C:\Applications\pDNS\pdns.exe")
Send("+{ESC}")
0

If your running a DNS server, then simply bridge your virtual network adapter in Virtualbox (Its set to NAT by default which is the opposite of what you need) and configure the VM's internal DNS to point to your server.

6
  • I actually already have it set up to be bridged. One issue with just pointing the VM's internal DNS to the Mac is the Mac would reply with 127.0.0.1, which would make the VM think that the websites are hosted on itself, which isn't correct. I could make it reply with its actual LAN IP instead of 127.0.01, but the problem is this Mac is a laptop and I take it with me places sometimes, so my IP address isn't always 192.168.1.50. I would like to only have to change the IP in one place when I go somewhere, and I imagine that would be in the "DualServer.ini" file.
    – Nick
    Commented Jul 6, 2013 at 2:54
  • hmmm. Well keep in mind you are running a server and its standard practice to use static addresses. The part about your mac replying to your VM with 127.0.0.1 is a little confusing. What is the output on the VM when you ping your Mac by hostname?
    – Scandalist
    Commented Jul 6, 2013 at 3:00
  • Dnsmasq (on the Mac) is configured to say that the address for anything-you-want.dev is 127.0.0.1. When I'm on the Mac and I ping foo.dev, Dnsmasq reports that the IP address is 127.0.0.1, which happens to be correct for the Mac. But if the VM is using the Mac for DNS, pinging foo.dev will, as usual, cause Dnsmasq to report that the IP address is 127.0.0.1. So if I go to foo.dev in a browser on the VM, the VM will expect that foo.dev is hosted on itself (since that's what Dnsmasq reported), but that's not correct. Do you know how to configure Dual DHCP DNS Server to do what I want?
    – Nick
    Commented Jul 6, 2013 at 3:29
  • You'll need to configure dnsmasq to point foo.dev to its ip address. This way when you type foo.dev into a VM browser it will map to the server on the host. When you take your laptop to another location you will need to release this address. Alternatively on your home network you could setup your router so your server always gets the same address
    – Scandalist
    Commented Jul 6, 2013 at 3:36
  • My router is set up to always give the Mac the 192.168.1.50 IP address. The thing is, if I take the Mac somewhere, I would have to reconfigure Dnsmasq (which may require a restart, but I'm not sure about that) and update the VM's DNS address. That's two places to change the IP, possibly requiring a restart. If I can get Dual DHCP DNS Server configured properly then I would only have to update the IP address in one place.
    – Nick
    Commented Jul 6, 2013 at 4:13

You must log in to answer this question.

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