Question about network attach vs attach-profile

I want to give my containers fixed IPv4 addresses. I found the following suggestion in a post in this forum:

lxc stop c1
lxc network attach lxdbr0 c1 eth0 eth0
lxc config device set c1 eth0 ipv4.address
lxc start c1

This works well.

The help page for lxc network reads:

  attach         Attach network interfaces to containers
  attach-profile Attach network interfaces to profiles

Does attach need to be called because otherwise there’s no container-specfic entry under which to store the ipv4.address property? I ask because it would seem the bridge is already attached to any given container by default (due to the default profile).

Correct, you don’t want to set ipv4.address on the profile itself as all containers would then get the same IP, so you need to add a container-specific entry instead.

Note that with LXD 3.0 or higher you should be able to just do lxc config device override NAME eth0 ipv4.address= which will then copy that eth0 device from the profile into container-specific settings and set the ipv4.address key.

1 Like