Trying to create multiple routed nic fails


I am trying to use OVH “failover” IP addresses in “routed” mode to allow a container to have its own IP adress independent from the host.
To add the routed NIC I use the following command

lxc config device add $CONTAINER eth2 nic nictype=routed ipv4.address=$FAILOVER_IP

It works fine when this command is launched once, however the container needs to own multiple IP addresses, so I need to add another routed IP:

lxc config device add $CONTAINER eth3 nic nictype=routed ipv4.address=$FAILOVER_IP_2

The second command fails with the following error:

Error: Invalid expanded devices: Device validation failed for “eth2”: Existing NIC “eth3” already uses “ipv4.gateway” in auto mode

(BTW it seems the eth numbers 2 & 3 are inverted in the error message)

I tried to declare IP aliases in the container network conf (eth0:0) but it won’t work, meaning the alias is not reachable from the outside once the container is running.

How can mutiple “routed” NIC be added to a single container and/or how can IP aliases be allocated to a container?

Answering to myself, the following seems to work:

lxc config device add $CONTAINER eth2 nic nictype=routed name=eth2 ipv4.address=$IP_1,$IP_2,$IP_3

I am still not clear whether in this setup eth0 linked to default lxdbr0 bridge is needed or not, if someone cares to explain if I can remove eth0 and add the routed NIC as eth0 that would be great.

You cannot add multiple routed NICs to an instance that both have ipv{n}.gateway=auto (which is the default if not specified). See Instance configuration - LXD documentation

This is because otherwise each NIC would try and add another default gateway via its own NIC interface, which would cause much confusion :slight_smile:

If you truly need a 2nd routed NIC and are going to manage the routing manually inside the instance, then you can do lxc config device set <instance> <device> ipv{n}.gateway=none.

Alternatively, as you have done, it is better and more correct, to just add multiple IPs to a single NIC.