How to enable lxd hostname resolution from the lxd host?
After creating the below container:
>>> lxc launch ubuntu: container
Creating container
Starting container
>>> lxc list
+-----------------+---------+----------------------+------+------------+-----------+
| container | RUNNING | 10.240.38.157 (eth0) | | PERSISTENT | 0 |
+-----------------+---------+----------------------+------+------------+-----------+
It can be reached using the IP address but not using the hostname:
>>> ping 10.240.38.157 -c 3
PING 10.240.38.157 (10.240.38.157) 56(84) bytes of data.
64 bytes from 10.240.38.157: icmp_seq=1 ttl=64 time=0.082 ms
64 bytes from 10.240.38.157: icmp_seq=2 ttl=64 time=0.053 ms
64 bytes from 10.240.38.157: icmp_seq=3 ttl=64 time=0.041 ms
--- 10.240.38.157 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2044ms
rtt min/avg/max/mdev = 0.041/0.058/0.082/0.019 ms
>>> ping container
ping: unknown host container
How to enable the lxd containers to be reached by hostname from the lxd host?
LXD sets up for you a DHCP & DNS server (
dnsmasq
) that only listens on thelxdbr0
interface. That's the DHCP server that lets containers have hostnames likec1.lxd
,mycontainer.lxd
and so on. And it works only within the containers, because the containers are autoconfigured with that LXD's DNS server.If you want the host to understand those
c1.lxd
,mycontainer.lxd
hostnames, you need to configure your host's DNS client service to also consult LXD's DNS server.This is an easy way to temporarily add the LXD DNS server to your host machine.
First, add the DNS server of
lxdbr0
.Second, make sure all requests to
*.lxd
are sent to that DNS server.After this, any requests to
containername.lxd
will be resolved to the container IP address. Make sure to add.lxd
to the hostname.Note that this config will be forgotten after a reboot.