Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active September 29, 2023 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plembo/00d1e2e610fec6506612a1c9afbbf799 to your computer and use it in GitHub Desktop.
Save plembo/00d1e2e610fec6506612a1c9afbbf799 to your computer and use it in GitHub Desktop.
lxc, lxd, ufw. dhcp, apt, containers

lxc and ufw

Problem

Basic lxc allows you to spin up lightweight system containers for testing. But if you're running a host firewall you may find it prevents your containers from acquiring an IP address over DHCP for networking, and from connecting to external hosts (like distro package servers).

NOTE: I don't use lxc in production, and have purged it from all my machines after some experimentation. Diving deeper into Docker seemed a better use of my time.

Solution

If running ufw on Ubuntu you should be able to fix that with the following command:

$ sudo ufw allow in on lxcbr0
$ sudo ufw route allow in on lxcbr0
$ sudo ufw route allow out on lxcbr0

References

Thomas Parrott. "Lxd bridge doesn't work with IPv4 and UFW with nftables". Linux Containers, 11 Sept 2023, https://discuss.linuxcontainers.org/t/lxd-bridge-doesnt-work-with-ipv4-and-ufw-with-nftables/10034/17.

Ki9 (Keith). "LXD/LXC containers not getting IP from lxdbr0". Linux Containers, 12 July 2023, https://discuss.linuxcontainers.org/t/lxd-lxc-containers-not-getting-ip-from-lxdbr0/9357/3.

"Linux Containers: Firewall considerations". ArchLinux Wiki, https://wiki.archlinux.org/title/Linux_Containers#Firewall_considerations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment