Create a new nic of container

I wanna create a new nic eth1 of my container, and I use
lxc config device add r1 eth1 nic nictype=bridged parent=R2R3
the eth1 can be seen in the container by ifconfig
BUT it doesn’t have an IPv4 address

By the way, I create the R2R3 network by
lxc network create R1R2 ipv6.address=none ipv4.address=23.23.23.1/24 ipv4.nat=true

What’s wrong?

Hi!

If you run

lxc network list

on the host, you will see whether the network is managed (by LXD) or unmanaged.

If it is managed (by LXD), then it is LXD’s fault that the container is not getting an IP address.
If it is unmanaged, then it is your task to setup a DHCP server on that interface to give DHCP leases to the containers.

But in my container, eth0 works and the rest of the interfaces cannot get the IP address

Could you post your profile file? or you can copy your default profile with another name for test purpose and in there just add eth1 device like eth0.
And you will also define the eth1 interface in the container as well.

The default LXD images only have DHCP configured inside the container on eth0. So if you’re adding a new NIC as eth1, then you’ll also need to update the container’s network config to do DHCP on that interface.

Then what the use of this command?
And when I config an IPv4 address by myself:

lxc config device add r1 eth1 nic nictype=bridged parent=R2R3 ipv4.address=23.23.23.111

the eth1 also not obtain an IP address

what is the command of creating a new profile file?

The use of that command is to assign a static DHCP lease in the LXD DHCP server for managed networks such that when the container starts and requests a DHCP address using its interface’s MAC address it always gets the same statically leased address.

lxc profile copy default test, here default copied to the test profile. Then you can edit the test profile as you imagine, you can copy something like that for the eth1 device to the test profile as you wish. Even you can arrange another network with different values.
devices:
eth0:
nictype: bridged
parent: lxdbr0
type: nic
eth1:
nictype: bridged
parent: lxdbr0
type: nic
Regards.

But when I do not use the device add command
and only config eth1 to DHCP in my container, it also works.

I’m not understanding you I’m afraid. Your original post said you didn’t get any IPv4 addresses on your eth1 interface.

You would need to post the output of lxc config show <container> --expanded and ip a inside the container to clarify the situation.