Domain Resolving To Wrong IP Using DNSMASQ

1

2

I have two VMs, one with my application which talks to the other vm running asterisk (and centos). The config for the application server needs to point to the asterisk box. To avoid having to change my config every time I move between the office and my house or coffee shop, I want to use dnsmasq.

I’m running dnsmasq on my mac (per http://ramonnogueira.wordpress.com/2013/02/09/resolving-vm-hostnames-with-dnsmasq/comment-page-1/#comment-9).

In Virtual Box, I have vboxnet1 set to 10.203.175.1. And my vm is definitely getting its IP from from dnsmasq; Its IP is in the range I specified.

But if I ping asterisk.vm, it resolves to 10.203.175.1 instead of the vm’s IP. Any idea what I could be doing wrong?

Here's my dnsmasq.conf

# Set this to the name of your VirtualBox host-only interface.
# dnsmasq will listen for DHCP and DNS requests on this interface as
# well as the loopback:
interface=vboxnet1

# This option will be forced anyway on OS X so set here to avoid a warning:
bind-interfaces

# Enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
# Select a range from the address and netmask shown in VirtualBox's
# host-only network configuration dialog:
dhcp-range=10.203.175.10,10.203.175.20,12h

# The default directory does not exist on OSX and this cause an 
# error when enabling DHCP, set an alternative location here:
dhcp-leasefile=/var/lib/dnsmasq.leases

# Assume anything in the .vm domain is local
#local=/vm/

# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
expand-hosts

# Set the domain for dnsmasq. this is optional, but if it is set, it
# does the following things.
# 1) Allows DHCP hosts to have fully qualified domain names, as long
#     as the domain part matches this setting.
# 2) Sets the "domain" DHCP option thereby potentially setting the
#    domain of all systems configured by DHCP
# 3) Provides the domain part for "expand-hosts"
domain=vm

# This must be the address of you host on the vboxnet0 network
# find this in the VirtualBox host-only network preferences
address=/asterisk.vm/10.203.175.1

Brad Rhoads

Posted 2014-04-09T23:11:58.883

Reputation: 145

Answers

2

address=/asterisk.vm/10.203.175.1

dnsmasq is doing exactly what you told it, responding to requests for asterisk.vm with the IP 10.203.175.1. That line should instead reference the IP of your VM.

Kromey

Posted 2014-04-09T23:11:58.883

Reputation: 4 377

OK, I was confused about how this was supposed to work. So in the case where you need 1 vm, setting dhcp-range=10.203.175.10,10.203.175.10 will work for sure. And in most cases specifying a range (to support multiple vms) should be fine because the vms will usually get the same IP. – Brad Rhoads – 2014-04-10T18:46:42.513

If you want your VM to get the same IP, either assign it statically to the VM itself, or assign a static DHCP lease in the dnsmasq configuration, either with dhcp-host directive or via the ethers file. Here's an example to get you started: https://wiki.archlinux.org/index.php/dnsmasq#DHCP_server_setup

– Kromey – 2014-04-10T19:29:33.497

Actually, you could statically assign an IP in the VM itself, then use the hosts file on the host itself and take dnsmasq out of the picture entirely. – Kromey – 2014-04-10T19:34:28.923