Static IP-address Containers

Is there a way to assign static IP addresses to machines (easily)?
lxc CTNAME set --ip x.x.x.x for example?

I would like to use containers with public IP addresses, but can not find a good explanation/guide to start with.
DHCP is not necessary for me.

lxd-1:~$ lxc version
Client version: 3.0.1
Server version: 3.0.1

You can get LXD to assign an IP address to a container as long as LXD is managing the specific network.

However, it you want to set a public IP address to a container, then LXD is not managing that network, and you have to set that address manually.
Have a look at
on how to do that. There are a few more steps to automate the process described there, but the instructions should be able to get you going.

You may find helpful the rest of the set at The LXD tutorials of Simos

1 Like

Thanks! It is still a bit too complicated in my opinion, but certainly a solution.

How can I disable DHCP on the containers with public ip access? And is it possible to remove the LXD bridge with this solution?

You can change the network settings of an existing container with the appropriate lxc network command, the restart the container to enable the new configuration.

Alternatively, you can set the network configuration in a profile, then assign the profile to an existing container. Finally, restart the container.

All is quite easy. To get the best help, try to write here what you understood from all this and which are your current commands so that we can help more.

Thanks for your quick reply.

Is a virtual mac address required (for providers like OVH etc.)? How can I assign a virtual-mac address to the container for internet access? Not sure about this (Using host mac or a virtual mac?). I followed your guide for the setup without success.

Update: lxc config set c1public volatile.eth0.hwaddr xx:xx:xx:xx
It works now.

Better option to set a static virtual mac-address?

You could attach a nic device directly to the container (rather than through a profile) which would then let you set the hwaddr property to the MAC, but in the end, it’s effectively the same as setting the volatile key, so whatever works best for you.

1 Like