Resolving names of LXC containers on the host

1

On Ubuntu 16.04 server edition, after launching an LXC container, it can only be referred to by its IP address. Enabling the .lxc domain in dnsmasq doesn't seem to help, and tutorials available only seem to work for Ubuntu 14.04.

Not being able to use DNS names on the host is a major inconvenience.

From blog posts I gather LXD 2.9 solves some DNS problems, but it seems unclear how to install via PPA.

Steps to reproduce

Following instructions https://gauvain.pocentek.net/name-resolution-lxc-containers.html

  • installed dnsmasq
  • uncommented LXC_DOMAIN="lxc" in /etc/default/lxc-net
  • added server=/lxc/10.0.3.1 to /etc/dnsmasq.d/lxc
  • checked that /etc/resolv.conf contains DNS server 10.0.3.1

With sudo lsof -i :53 I checked that lxd, dnsmasq and lxc-dnsmasq seem to be bound to port 53.

However, - Querying dig mycontainer.lxc leads no results. - Querying dig @10.0.3.1 mycontainer.lxc leads no results. - Querying dig @10.0.3.1 google.com produces correct results.

Dragan Espenschied

Posted 2017-05-18T13:16:01.557

Reputation: 51

Answers

0

Have you tried with the full sample configuration given in your linked source? Note that just uncommenting LXC_DOMAIN="lxc" will not work.

Also, the rules used by lxc dnsmasq should be defined in its DHCP configuration file, which it is usually defined at the /etc/default/lxc-net config file as: LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf. This means that adding server=/lxc/10.0.3.1 to /etc/dnsmasq.d/lxc will not make any difference if that file is not the configured LXC_DHCP_CONFILE.

See also: https://askubuntu.com/questions/446831/how-to-let-built-in-dhcp-assign-a-static-ip-to-lxc-container-based-on-name-not#571095

atfornes

Posted 2017-05-18T13:16:01.557

Reputation: 101