Routed NIC dynamic reconfigure

should routed NICs be dynamically (re)configurable? I’m trying to attach an extra IP without restarting the container as part of a failover scenario, and I always end up with default route and all IPs wiped out,but after I reconfigure manually within a container, it all works OK

[root@gcpa ~]# lxc launch ubuntu:22.04 test -d eth0,ipv4.address=172.18.1.8
Creating test
Starting test

[root@gcpa ~]# ping -c 2 172.18.1.8
PING 172.18.1.8 (172.18.1.8) 56(84) bytes of data.
64 bytes from 172.18.1.8: icmp_seq=1 ttl=64 time=0.067 ms
64 bytes from 172.18.1.8: icmp_seq=2 ttl=64 time=0.060 ms
--- 172.18.1.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1041ms
rtt min/avg/max/mdev = 0.060/0.063/0.067/0.008 ms

so far so good, but:

[root@gcpa ~]# lxc config device set test eth0 ipv4.address=172.18.1.7,172.18.1.8
[root@gcpa ~]# ping -c 2 172.18.1.8
PING 172.18.1.8 (172.18.1.8) 56(84) bytes of data.
^C^[[A
--- 172.18.1.8 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1023ms
[root@gcpa ~]# ping -c 2 172.18.1.7
PING 172.18.1.7 (172.18.1.7) 56(84) bytes of data.
From 169.254.0.1 icmp_seq=1 Destination Host Unreachable
From 169.254.0.1 icmp_seq=2 Destination Host Unreachable
--- 172.18.1.7 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1057ms

[root@gcpa ~]# lxc exec test -- bash -i
root@test:~# ip a  
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
43: eth0@if44: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:79:65:21 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::216:3eff:fe79:6521/64 scope link 
       valid_lft forever preferred_lft forever
root@test:~# ip r s

ok, network is not there but can be reconfigured manually

root@test:~# ip a a 172.18.1.7/32 dev eth0
root@test:~# ip a a 172.18.1.8/32 dev eth0
root@test:~# ip r a 169.254.0.1 dev eth0
root@test:~# ip r a default via 169.254.0.1
root@test:~#   exit

[root@gcpa ~]# ping -c 2 172.18.1.7
PING 172.18.1.7 (172.18.1.7) 56(84) bytes of data.
64 bytes from 172.18.1.7: icmp_seq=1 ttl=64 time=0.079 ms
64 bytes from 172.18.1.7: icmp_seq=2 ttl=64 time=0.067 ms
--- 172.18.1.7 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1008ms
rtt min/avg/max/mdev = 0.067/0.073/0.079/0.006 ms
[root@gcpa ~]# ping -c 2 172.18.1.8
PING 172.18.1.8 (172.18.1.8) 56(84) bytes of data.
64 bytes from 172.18.1.8: icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from 172.18.1.8: icmp_seq=2 ttl=64 time=0.058 ms
--- 172.18.1.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1045ms
rtt min/avg/max/mdev = 0.058/0.058/0.058/0.000 ms

At the moment you must manually specify the IP addresses (using ipv4.address and/or ipv6.address ) before the instance is started (https://documentation.ubuntu.com/lxd/en/latest/reference/devices_nic/#nictype-routed). So they do not reconfigure dynamically.

If this is something you require please open an issue on Github and we can discuss there whether it is feasible. Thanks :slight_smile:

oki, opened https://github.com/canonical/lxd/issues/12119

1 Like