Issues with reaching the internet from LXC - DNS issue

I am having issues reaching the internet from created LXC containers. In an Alpine container “apk add” gives an error, but after - echo "" >> /etc/hosts – it works. Any suggestion of how to fix the DNS error.

~ # apk update
ERROR: temporary error (try again later)

1 errors; 11111 distinct packages available
~ # nslookup
nslookup: can’t resolve ‘(null)’: Name does not resolve

~ # echo “” >> /etc/hosts
~ # apk update
v20190925-3000-g9fcc748e66 []
v20190925-3014-g8f8945adaa []
OK: 11121 distinct packages available


In my case, with default LXD configuration, it works.

$ lxc launch images:alpine/3.10 alpine
Creating alpine
Starting alpine
$ lxc shell alpine
alpine:~# apk update
v3.10.3-19-g7f993019c4 []
v3.10.3-13-g8068beb776 []
OK: 10336 distinct packages available

Can you show the output of the following? Assuming that your default profile (lxc profile show default) specifies the lxdbr0 managed interface).

lxc network show lxdbr0
~$ lxc network show lxdbr0
  ipv4.nat: "true"
  ipv6.address: fd42:758e:6455:e369::1/64
  ipv6.nat: "true"
description: ""
name: lxdbr0
type: bridge
- /1.0/containers/server
managed: true
status: Created
- none

And lxc profile
~$ lxc profile show default
config: {}
description: Default LXD profile
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
path: /
pool: default
type: disk
name: default
- /1.0/containers/server

Upon a reboot the DNS issue is still there, so it was’nt a firewall issue.

Your containers do not get a DHCP lease, therefore they do not get their network autoconfigured.

Most likely there is a DNS server already running on the host and does not allow the DNS/DHCP server from within LXD to work. Any other DNS server on your host should NOT bind on the lxdbr0 interface.
To verify whether this is the case, please run on the host:

sudo lsof -i :domain

I ran lsof -i :domain which indicated the unbound resolver that I had installed on the host was indeed the issue. I uninstalled unbound on the host, and now everything is now working.

Would it be possible to install unbound within a LXC container on the host, then use that as a DNS resolver for the host. ?

I haven’t tried this. The potential problem is that the host will not have DNS until after the container has started and is ready to serve requests. In addition, you would need to configure the container to use a DNS server other than the one provided by DHCP from LXD. If you have a test computer, you can experiment.

unbound, however, by default should not bind to other interfaces other than loopback, unless you specify those other network interfaces. If I were you, I would make sure that unbound does not bind to lxdbr0.