[lxc-users] Making sure that you can actually "dig mycontainer.lxd" from the server, etc.

Simos Xenitellis simos.lists at googlemail.com
Thu Mar 30 16:55:00 UTC 2017


Hi All,

I just figured out that it is possible, and available by default, to
use the domain names of the LXD containers FROM the server.
It has been quite confusing, and could not get it working, so I am
documenting this here.

Let's get a list of the containers and try to access by DNS the
hostname of the container,

$ lxc list
+-------------+---------+---------------------+--------------------------+------------+-----------+
|    NAME     |  STATE  |        IPV4         |    IPV6    |    TYPE
 | SNAPSHOTS |
+-------------+---------+---------------------+------------------------+------------+-----------+
| mycontainer | RUNNING | 10.0.185.211 (eth0) |          | PERSISTENT
| 0         |
+-------------+---------+---------------------+----------------------------+------------+-----------+
$ host mycontainer.lxd
mycontainer.lxd has address 10.0.185.211
$ _

The way this works, is that there is a special configuration file (for
"dnsmasq"),
that instructs our Ubuntu's caching nameserver (dnsmasq) to use LXD's
caching nameserver (another instance of dnsmasq), for the name
resolution of *.lxd domains.

If you looked into the file /etc/dnsmasq.d/lxd, you would be looking
at the wrong place.

The correct place to look at, can be found from Ubuntu's caching
nameserver process:

 3136 ?        S      0:00 /usr/sbin/dnsmasq --no-resolv
--keep-in-foreground --no-hosts --bind-interfaces
--pid-file=/var/run/NetworkManager/dnsmasq.pid
--listen-address=127.0.1.1 --cache-size=0 --conf-file=/dev/null
--proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq
--conf-dir=/etc/NetworkManager/dnsmasq.d

and it is: /etc/NetworkManager/dnsmasq.d

In there, there is a 'lxd' file with content similar to

server=/lxd/10.60.117.1
server=/117.60.10.in-addr.arpa/10.60.117.1

This means that for domains with the .lxd suffix, consult the DNS
server at IP address 10.60.117.1 (LXD's caching nameserver, and DHCP
server). Also, do reverse lookups.

The problem is that this file, /etc/NetworkManager/dnsmasq.d/lxd, is
most probably generated while running "lxd init". At least on my
system, it has NOT been regenerated after the subsequent invocations
of "lxd init". That is, I had such a file with a June 2016 timestamp,
with obviously wrong contents.

A cursory grep in the source of LXD did not reveal where this
/etc/NetworkManager/dnsmasq.d/lxd is generated from. It is possible
that it is not generated anymore, and a small chance that it never got
generated by "lxd init".

The documentation at
https://help.ubuntu.com/lts/serverguide/lxc.html#lxc-network provides
some hints, but does not mention the case of having NetworkManager
installed.

Simos


More information about the lxc-users mailing list