Ubuntu 16.04: Minor case of libvirt's NAT cannot resolve hostname

This article will describe a minor case of libvirt's NAT cannot resolve hostname.

1 /etc/resolv.conf

This article will mention two case of /etc/resolv.conf. The problem will happen with later case.

/etc/resolv.conf should be created by DHCP server. If creating /etc/resolv.conf manually (or setting static value), you need to change /etc/resolv.conf when changing network address.

1.1 Multiple nameserver for backup

This is a case of using primary DNS server and secondary DNS server.

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4
  • nameserver 8.8.8.8 is primary DNS server and it will use recursion query.
  • nameserver 8.8.4.4 is secondary DNS server and it will run when primary DNS server does not response.

1.2 Multiple nameserver for each domain

This is a case of using specific DNS server for resolving hostname for specific domain.

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.11.2
nameserver 192.168.11.1
search hiroom2.com
  • nameserver 192.168.11.2 is DNS server for hiroom2.com. It does not resolve hostname in other domain. It does not use recursive query.
  • nameserver 192.168.11.2 is DNS server for other domain. it uses recursive query.

2 VirtualBox's NAT can resolv hostname

VirtualBox's NAT provides DHCP server and provides DNS information from /etc/resolv.conf in host machine. When guest machine uses DHCP, /etc/resolv.conf in guest machine is same with /etc/resolv.conf in host machine.

If you want to resolve guest machine hostname, you need to register guest machine hostname to DNS server and write this DNS server to /etc/resolv.conf in host machine.

3 libvirt's NAT cannot resolv hostname

libvirt will run dnsmasq for DHCP server and DNS server. libvirt's dnsmasq will provides host machine's IP address as DNS information to guest machine.

When guest machine uses DHCP, the following /etc/resolv.conf will be generated automatically.

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.122.1

libvirt's dnsmasq will resolv hostname with /etc/hosts and /etc/resolv.conf in host machine.

If /etc/resolv.conf in host machine has multiple nameserver, when first name server cannot resolve hostname (return REFUSED), libvirt's dnsmasq will not send query to next nameserver.

The case of "Multiple nameserver for each domain" does not work. dnsmasq might support it, but libvirt's dnsmasq in Ubuntu 16.04 does not support it.

This will be imporoved by this commit.