Containers not getting ipv4 via DHCP

I am using Ubuntu 22.04.01 host and am not able to get IPv4 addresses on the containers via DHCP. The containers do get IPv6 assigned. The setup was working without any issues. I have tried following steps but still not working for me.

  • I cleaned all networks/images/profiles etc and have reinitialized the configuration of LXD with default parameters

  • I was using LXD 5.8 and have now upgraded to LXD 5.9/stable

  • I followed the link LXD containers w ubuntu images get ipv6 dhcp addresses but not ipv4, alpine does get ipv4 but the my problem seems to be different.

  • Have tried to do IP assignment using command but it just waits for dhcp.
    $ lxc exec cont-name -- dhclient eth0

  • I tried running the dnsasq with debugging on but i doesn’t receive any requests.

$ sudo dnsmasq -d --interface=lxdbr0 --listen-address=10.54.101.1 --dhcp-authoritative \
--bind-interfaces --except-interface=lo \
--dhcp-leasefile=/var/snap/lxd/common/lxd/networks/lxdbr0/dnsmasq.leases \
--dhcp-range 10.54.101.2,10.54.101.254,1h \
--interface-name _gateway.lxd,lxdbr0 -S /lxd/ -u lxd -g lxd

Any help in this regard would be appreciated.

Check that lxd has started dnsmasq and its listening using the “ss -ulpn” command.

Then also consult How to configure your firewall - LXD documentation as its often the host firewall or docker blocking it.

Thankyou for your quick response. It was the firewall.
This fixed the issue:

sudo ufw allow in on lxdbr0
sudo ufw route allow in on lxdbr0
sudo ufw route allow out on lxdbr0

I am not sure why and how it was working before and now it doesnt with firewall enabled. Will try to figure it out.

1 Like