Network Card; Public Domain;
Network Card; Public Domain;

Yesterday, I set up an LXD container on a dedicated server; however, my container was not getting an internal IPv4 address.

After trying a few things, I realized the Plesk firewall was to blame. Since the Plesk firewall does not allow advanced setups, I decided to disable it entirely.

Then, of course, LXD networking worked. But I can’t just keep a public server without a firewall, right? So, I decided to enable UFW.

Of course, if you’re working over SSH, you’ll want to allow SSH in UFW before enabling it, to not lock yourself out (also add rules for other things you need).

Now that we have UFW enabled, we have to fix LXD networking, as you might find networking will again not be working in LXD.

⚠️ This guide assumes your LXD bridge is called lxdbr0, adjust accordingly!

Fixing getting IPv4

The first thing we’ll have to do, is make sure the container gets an IPv4 address. We do this by allowing DHCP traffic to lxdbr0:

ufw allow in on lxdbr0 to any port 67 proto udp comment 'LXD DHCP Server'

Fix container DNS

Now you have an IP, and should be able to ping, but you can’t do DNS. For this, we need another rule:

ufw allow in on lxdbr0 to any port 53 proto udp comment 'LXD DNS Server'

Fix container traffic

Now we have IPv4, we can ping and we can resolve hostnames. But you might find you can’t actually connect anywhere!

For this, we have to allow traffic from/to lxdbr0 like this:

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

Final Notes

If you find your container is still not getting internet, try restarting it.

I run this blog in my free time. If I helped you out, consider donating a coffee! :D