Two routed interfaces in container

ubuntu 20.04 lxd 4.6

lxc config device add mytest eth0 nic nictype=routed parent=eno1 ipv4.address=192.168.20.31
lxc start mytest

all works fine after little netplan config edit

lxc stop mytest

lxc config device add mytest eth1 nic nictype=routed parent=eno1 ipv4.address=192.168.20.32
lxc start mytest

Error: Failed to run: /snap/lxd/current/bin/lxd forkstart mytest /var/snap/lxd/common/lxd/containers /var/snap/lxd/common/lxd/logs/mytest/lxc.conf:
Try lxc info --show-log mytest for more info

In logfile:

lxc mytest 20200927174100.546 ERROR network - network.c:lxc_network_setup_in_child_namespaces_common:3464 - File exists - Failed to add ipv4 dest “169.254.0.1” for network device “eth1”
lxc mytest 20200927174100.546 ERROR network - network.c:lxc_setup_network_in_child_namespaces:3528 - File exists - Failed to setup netdev
lxc mytest 20200927174100.546 ERROR conf - conf.c:lxc_setup:3218 - Failed to setup network
lxc mytest 20200927174100.546 ERROR start - start.c:do_start:1224 - Failed to setup container “mytest”
lxc mytest 20200927174100.546 ERROR sync - sync.c:__sync_wait:41 - An error occurred in another process (expected sequence number 5)
lxc mytest 20200927174100.546 ERROR lxccontainer - lxccontainer.c:wait_on_daemonized_start:850 - Received container state “ABORTING” instead of “RUNNING”
lxc mytest 20200927174100.547 ERROR start - start.c:__lxc_start:1999 - Failed to spawn container “mytest”

What’s my mistake?

One for @tomp

I suspect the issue is that both try to setup the same default gateway.

@papageno @stgraber yes indeed that is the issue.

We could probably do a better job of validating that so it explains the issue more clearly. Issue for that https://github.com/lxc/lxd/issues/7943

Also there is a setting to disable trying to create the default route for certain NICs,

lxc config device set <instance> <device> ipv4.gateway=none

See https://linuxcontainers.org/lxd/docs/master/instances#nictype-routed

However that will likely need additional config inside the container to make the 2nd NIC usable. If you could explain what you are trying to achieve and why you feel that two NICs are required then I may be able to help further.