[Solved]Static IP address to LXC container

Although, I see few posts related to setting static IP address to LXC container. In my case
I am not able to set it ? Appreciate if any help on this. I tried both on lxc 3 and 4.

  1. My containers are bridged to this bridge br0, i am on home LAN
iface br0 inet dhcp
    bridge_ports eth0
    bridge_stp off
    bridge_fd 0
    bridge_maxwait 0
iface br0 inet6 dhcp
  1. I edited in my alpine container /etc/interfaces to have manual. and then I have set like this
    lxc network attach br0 c1 eth0
    lxc config device set c1 eth0 ipv4.address xx.xx.xx.xx

after this change in “lxc list”, don’t see IPV4, container is running state.

Are you running LXC or LXD? You have used an LXD command example but categorised the post as LXC?

Please can you show the output of lxc config show <container> --expanded if using LXD?

Thanks for the reply. I am using LXD. Here is the output of lxc config show c1 --expanded output…Regards.

architecture: aarch64
config:
  image.architecture: arm64
  image.description: Alpine 3.11 arm64 (20200506_13:00)
  image.os: Alpine
  image.release: "3.11"
  image.serial: "20200506_13:00"
  image.type: squashfs
  volatile.base_image: 68d743f4c1e1e2c9049349751ed99a3b23e4afcc4dd3b5c6be0573c6f5f16c8e
  volatile.eth0.host_name: vethca122a77
  volatile.eth0.hwaddr: 00:16:3e:6b:a2:67
  volatile.eth0.name: eth0
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.last_state.power: RUNNING
devices:
  eth0:
    ipv4.address: 19x.16x.1.2xx
    nictype: bridged
    parent: br0
    type: nic
  root:
    path: /
    pool: default
    type: disk
ephemeral: false
profiles:
- default
stateful: false
description: ""

Please can you show the output of:

ip a and ip r on the host and in the container.

Thanks
Tom

Thanks again , here is the output:

----------on host ---------------

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq master br0 state DOWN group default qlen 1000
    link/ether dc:a6:32:4c:69:ad brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether dc:a6:32:4c:69:ae brd ff:ff:ff:ff:ff:ff
    inet 192.xxx.1.16/24 brd 192.xxx.1.255 scope global dynamic wlan0
       valid_lft 83959sec preferred_lft 83959sec
    inet6 xxxx::dea6:32ff:fe4c:69ae/64 scope link 
       valid_lft forever preferred_lft forever
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 36:da:a0:7b:b1:24 brd ff:ff:ff:ff:ff:ff
    inet6 xxxx::bca0:a6ff:fe54:adb2/64 scope link 
       valid_lft forever preferred_lft forever
5: lxdbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
    link/ether f6:78:d5:b7:f8:19 brd ff:ff:ff:ff:ff:ff
    inet 10.66.89.1/24 scope global lxdbr0
       valid_lft forever preferred_lft forever
    inet6 fd42:be77:66d0:7a0a::1/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 xxxx::f478:d5ff:feb7:f819/64 scope link 
       valid_lft forever preferred_lft forever
9: vethea3a7f93@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br0 state UP group default qlen 1000
    link/ether 36:da:a0:7b:b1:24 brd ff:ff:ff:ff:ff:ff link-netnsid 0
default via 192.xxx.1.1 dev wlan0 proto dhcp src 192.xxx.1.16 metric 600 


10.66.89.0/24 dev lxdbr0 proto kernel scope link src 10.66.89.1 
192.xxx.1.0/24 dev wlan0 proto kernel scope link src 192.xxx.1.16 
192.xxx.1.1 dev wlan0 proto dhcp scope link src 192.xxx.1.16 metric 600 


----------in container ---------------
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 00:16:3e:6b:a2:67 brd ff:ff:ff:ff:ff:ff
    inet6 xxxx::216:3eff:fe6b:a267/64 scope link 
       valid_lft forever preferred_lft forever

I’ve used the three backticks in markdown to clean up your posts for easier reading.

So looking at this, the LXD host has an IPv6 address on br0 and the container has an IPv6 address on eth0 too.

These are presumably being set via router advertisements or DHCPv6.

If you want a static IPv6 address for your container on eth0 then you cannot use:

lxc config device set c1 eth0 ipv4.address ...
lxc config device set c1 eth0 ipv6.address ...

The reason for this is that those settings only control the LXD DHCP server and because you are not using the lxdbr0 parent, but instead br0 none of those settings will apply.

Instead you can modify the network config files inside the container to set a static IP.

Thank you for your detailed explanation, will look into making change to network config files inside container…
Best.

Great, Lots of thanks to you for your help. It works now!!
I commented everything in container /etc/network/interfaces and added the following, my static IP is 192.16x.1.xxx, tested works fine.
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.16x.1.xxx
netmask 255.255.255.0
gateway 192.168.1.1