I have couple of servers running in VirtualBox interconnected by hosted-only network. The parent system is Ubuntu running NetworkManager which manages the DNS according to the connected network so my resolv.conf contains


The VirtualBox is configured that the parent system has address and the virtual servers are statically configured to,

When I change network I always find (via nmcli) my actual nameserver and fill the value to each of the virtual servers. This is annoying as I frequently change the network and connect via different interfaces (wlan0, eth0).

My idea is to use the NetworkManager managed DNS server as server for the virtuals. But when I put nameserver in resolv.conf of the virtual servers the DNS is not resolved.

Clearly the DNS server managed by the NetworkManager is bound only to

I tried to add listen-interface= to /etc/NetworkManager/dnsmasq.d/<my-file> it works after NetworkManager restart but only when the Virtual Box is running and the vboxnet0 interface exists. When the Virtual Box is down the dnsmasq fails to start.

I also tried use bind-dynamic option to dnsmasq but it is incompatible with bind-interface added to dnsmasq command by NetworkManager.

Question: How can I make the NetworkManager to bind dnsmasq to after vboxnet0 interface appears? Or how to make it to start another instance of dnsmasq forwarding request to

Additional info:

# ifconfig
vboxnet0  Link encap:Ethernet  HWaddr 0a:00:27:00:00:00  
inet addr:  Bcast:  Mask:


# ps aux|grep dnsmasq
nobody    1252  0.0  0.0  52976  4108 ?        S    dub10   0:00 
/usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts
--bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid 
--listen-address= --cache-size=0 --conf-file=/dev/null 
--proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq 


#netstat -antp|grep ':53'
tcp 0 0* LISTEN 1252/dnsmasq


# nslookup google.com

Non-authoritative answer:
Name:   google.com
Address: 64.233.164


# nslookup google.com
;; connection timed out; no servers could be reached

This can be resolved (heh) with a wrapper script for dnsmasq to replace --bind-interfaces with --bind-dynamic, but for some reason NetworkManager hardcodes its search path, so first the original binary has to be moved out of the way (on dpkg-based systems, use a command like dpkg-divert --local --rename --divert /usr/local/sbin/dnsmasq --add /usr/sbin/dnsmasq).

Then create a new /usr/sbin/dnsmasq:


for (( i=0; i<${#args}; ++i )); do
    case "${args[i]}" in

exec /usr/local/sbin/dnsmasq "${args[@]}"

Change /usr/local/sbin/dnsmasq as needed to point to the original binary, mark the script as executable (chmod +x /usr/sbin/dnsmasq), and add whatever interface= lines to a file in /etc/NetworkManager/dnsmasq.d.


  1. Use of /usr/local/sbin might break if NetworkManager is updated to honor the PATH environment variable. If this is a concern, move the real executable to a non-PATH location such as /usr/lib (but see #2 below).
  2. Use of a location that isn't before /usr/sbin in $PATH will cause --bind-interfaces (-z) to be replaced when manually invoking dnsmasq on the command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.