Error: The device doesn't exist setting ipv4 address

I’m having some trouble setting an ipv4 address on a container. I must be missing something simple here.

eth0 is defined in the default profile. But not on the container directly.

# lxc config device set centos-7-base eth0 ipv4.address 192.168.10.2
Error: The device doesn't exist

# lxc profile show default
config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: virbr0
    type: nic
  root:
    path: /
    pool: default_dir
    type: disk
name: default
used_by:
- /1.0/instances/centos-7-base


# lxc config show centos-7-base
architecture: x86_64
config:
  image.architecture: amd64
  image.description: Centos 7 amd64 (20201210_07:08)
  image.os: Centos
  image.release: "7"
  image.serial: "20201210_07:08"
  image.type: squashfs
  image.variant: default
  volatile.base_image: 444a84562e2f7ff3facf4086cd87138bc0700d91905b82b4f5317e678ba10f3a
  volatile.eth0.host_name: veth7c4c36b3
  volatile.eth0.hwaddr: 00:16:3e:ef:6f:03
  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
  volatile.uuid: 1aa55389-e336-47d4-bc89-e93c459cd026
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

# lxc config show --expanded centos-7-base
architecture: x86_64
config:
  image.architecture: amd64
  image.description: Centos 7 amd64 (20201210_07:08)
  image.os: Centos
  image.release: "7"
  image.serial: "20201210_07:08"
  image.type: squashfs
  image.variant: default
  volatile.base_image: 444a84562e2f7ff3facf4086cd87138bc0700d91905b82b4f5317e678ba10f3a
  volatile.eth0.host_name: veth7c4c36b3
  volatile.eth0.hwaddr: 00:16:3e:ef:6f:03
  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
  volatile.uuid: 1aa55389-e336-47d4-bc89-e93c459cd026
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: virbr0
    type: nic
  root:
    path: /
    pool: default_dir
    type: disk
ephemeral: false
profiles:
- default
stateful: false
description: ""


Inside container
# ip addr show
1: lo:  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
18: eth0@if19:  mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:ef:6f:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:feef:6f03/64 scope link
       valid_lft forever preferred_lft forever

When a device is in a profile but not on container config, you can use lxc config device override instead which will copy it to the container config with the changes you’re requesting.

Further changes can then be done with lxc config device set.

Ok this makes sense. So I try and set an address. It shows up in the config. But not in the container or in the output of lxc list

I can add the address inside the container and that works fine but it seems I’m missing something with the lxc command.

This is centos 7 with a centos 7 container. virbr0 is a bridge set up outside of LXD.

# lxc config device set centos-7-base eth0 ipv4.address 192.168.10.2
# lxc list
+---------------+---------+------+------+-----------+-----------+
|     NAME      |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+---------------+---------+------+------+-----------+-----------+
| centos-7-base | RUNNING |      |      | CONTAINER | 0         |
+---------------+---------+------+------+-----------+-----------+
[root@dal ~]# lxc config show centos-7-base
architecture: x86_64
config:
  image.architecture: amd64
  image.description: Centos 7 amd64 (20201210_07:08)
  image.os: Centos
  image.release: "7"
  image.serial: "20201210_07:08"
  image.type: squashfs
  image.variant: default
  volatile.base_image: 444a84562e2f7ff3facf4086cd87138bc0700d91905b82b4f5317e678ba10f3a
  volatile.eth0.host_name: veth77e2b697
  volatile.eth0.hwaddr: 00:16:3e:ef:6f:03
  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
  volatile.uuid: 1aa55389-e336-47d4-bc89-e93c459cd026
devices:
  eth0:
    ipv4.address: 192.168.10.2
    name: eth0
    nictype: bridged
    parent: virbr0
    type: nic
ephemeral: false
profiles:
- default
stateful: false
description: ""

# lxc exec centos-7-base /bin/bash
[centos-7-base ~]# ip addr show
1: lo:  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
9: eth0@if10:  mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:ef:6f:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:feef:6f03/64 scope link
       valid_lft forever preferred_lft forever

[centos-7-base]# ip add add 192.168.10.2/24 dev eth0
[centos-7-base]# ping 192.168.10.1
PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=0.118 ms
64 bytes from 192.168.10.1: icmp_seq=2 ttl=64 time=0.051 ms
^C
--- 192.168.10.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.051/0.084/0.118/0.034 ms

The static allocation that LXD sets up is a static DHCP allocation, so the container must still request IPs via DHCP to get its static allocation.

Can you confirm the container is doing this?

Confirmed the attempt is made and fails. Could this have anything to do with the parent device being a bridge not managed by LXD?

[centos-7-base]# ifup eth0

Determining IP information for eth0…

failed.
[rcentos-7-base]#

Yes that is certainly the issue. Setting static IP address in LXD only works if the NIC’s parent is a managed LXD bridge with DHCP enabled.

That did the trick!

systemctl reload snap.lxd.daemon was starting the system dnsmasq instead of the one included in the snap at /var/lib/snapd/snap/lxd/18324/bin/dnsmasq though. Removing it worked.

Is there an LXD way of enabling STP on that bridge?