Static ip, how is possible;

Hi to all.
I use Ubuntu 20.04 and have snap lxd with a ZFS partition and bridged networking installed as per https://bayton.org/docs/linux/lxd/lxd-zfs-and-bridged-networking-on-ubuntu-16-04-lts/

I don’t like the containers change the lan ip every reboot, how to have them have static ip;

Thank you team!

Hi,

If you have your containers bridged onto an external network then you can either use the MAC address assigned to the container lxc config get <instance> volatile.eth0.hwaddr to setup static DHCP assignments on your network’s DHCP server.

Or you can setup the static IPs manually inside the container like you would a ‘real’ system.

1 Like

Most DHCP servers (i.e. LAN router) tend to give the same IP address to the same computer or container. They do so by keeping track of the MAC address of that computer or container to the IP address they gave the first time.

If somehow the MAC address of a computer or container changes when they are restarted, then the DHCP server will not be able to remember the old IP address allocation, and will assign a new IP address.

A container gets a MAC address from a special MAC address range that is meant for virtual machines and containers. In LXD containers, this MAC address does not change on every container restart. So, it is likely an issue with the router (DHCP server). The router may either be configured not to remember old DHCP allocations, or it may not remember DHCP allocations for those special MAC addresses for VMs/containers. You can look into these in the configuration of the router.

If you assign static IP address to the (bridged) containers, make sure you edit the router configuration to know about that. That is, let the router use DHCP for the range 192.168.0.[10-100] and assign statically to the containers from a different range, like 192.168.0.[150-200]. That should avoid unintended IP conflicts.

1 Like

Well thank you all, I got it working manually configuring the netplan file.