I am researching LXC. The thing I was unable to find is how to give a container public IP address?

Suppose we have a server with 5 IP addresses. Then we do 4 containers there and give somehow one address for each of them.

I saw there is "standard" way for LXD, but I found nothing for LXC.


What I do in LXC is to have the server interface being a bridge, so the server has IP1 set on the bridge, and the four container interfaces becomes part of that bridge. Just configure your container networking to be:

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = <your server bridge interface>
lxc.network.name = eth0

And then you set your container IP as usual in the container. You can also set the IP in the lxc config if you want:

lxc.network.ipv4 = <IP>/24
lxc.network.ipv4.gateway = <gw IP>

How you do that is up to you. There are also other network types, so please do read up on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.