Public static IP without manual adjustments

Im quite new to LXD but i read a lot of posts on how to create networks and assign IPs to your containers. But my problem is, i don’t know hot to assign a IP-Address to a container without manually changing the interfaces file in the container. I would like to run a script to assign a specific IP to a container which is public accessible.
So my question is: how do i assign a specific public ip to a container using only lxd (or at least only cli) commands?

Thanks for the help.

See Give public ip one container with custom bridge

It also covers the issue of doing all the tasks outside of the container.

I have written this tutorial that shows how to make LXD containers to get an IP address from the local LAN. They get the IP address from the local LAN DHCP server (i.e. home router).
You can set up a static IP address for the container in the home router, in order to get static IPs.


Yes, this is the approach I took, as well. I create the container on a network that is bridged to my LAN, see what IP address it gets, and then set a permanent lease for the MAC address on my DHCP server.

I now found out that this was an issue with Hyper-V because i “simulated” the host as a Hyper-V VM. I had to enable MAC-Address spoofing in the advanced settings of the virtual network card in my VM. But thank you for the help :slight_smile:

But i still wanted to ask if there is a possibility to configure the IP address outside of the container without having to push a file to the container and to do it only with cli commands?

You can get your containers to obtain their IP addresses from the external network (the same DHCP server that the host is using!) by using the macvlan interface. This does not require any editing in the containers. You just specify a LXD profile when you create the container. If your containers are already created, you can attach them to the new LXD profile. I meant to show that in my article as well, but forgot :-).