如何为 LXC 容器的第二个网络接口分配 IPv4 地址?

如何为 LXC 容器的第二个网络接口分配 IPv4 地址?

我正在运行一个 lxc 容器,我想将其连接到两个不同的网桥(br0br1)。当我配置容器的配置文件(/var/lib/lxc/testcontainer/config)时(如下所示),只有第一个接口被分配了 IP 地址:

lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:e6:16:c5

lxc.network.type = veth
lxc.network.link = br1
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:c5:16:c5

可以使用以下方法确认lxc-ls

NAME              STATE   AUTOSTART GROUPS IPV4          IPV6 
testcontainer     RUNNING 1         -      192.168.1.6   -    

ifconfig并从容器内部使用:

eth0      Link encap:Ethernet  HWaddr 00:16:3e:e6:16:c5  
          inet addr:192.168.1.6  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:fee6:16c5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:440 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:48388 (48.3 KB)  TX bytes:1576 (1.5 KB)

eth1      Link encap:Ethernet  HWaddr 00:16:3e:c5:16:c5  
          inet6 addr: fe80::216:3eff:fec5:16c5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2796 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:521109 (521.1 KB)  TX bytes:648 (648.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

切换配置文件中的网络接口的顺序会导致另一个接口(之前未分配)显示 IPv4 地址。

在第二个接口上分配 IPv4 需要什么?

答案1

虽然晚了几年,但你可以添加以下另一行:

lxc.network.ipv4 = XXX.XXX.XXX.XXX

相关内容