LXC 容器,无 LAN - 互联网访问

LXC 容器,无 LAN - 互联网访问

我正在 openSuSE 42.1 主机上设置 LXC 容器。

主机具有完全的 Internet 访问权限,但容器却没有。容器可以 ping 通主机,但无法 ping 通 LAN 或 Internet 上的其他任何内容。

我认为问题可能是桥接器在主机上的配置方式,但我不知道如何解决这个问题。

主机有 eth0 和 br0。br0 已被分配静态 IP 地址等。

在 YAST 中,我的默认 IPv4 网关为 192.168.2.1,设备为 br0

这是主机的网络详细信息

route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway.localdo 0.0.0.0         UG    0      0        0 br0
192.168.2.0    *               255.255.255.0   U     0      0        0 br0

netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.2.1    0.0.0.0         UG        0 0          0 br0
192.168.2.0    0.0.0.0         255.255.255.0   U         0 0          0 br0

ifconfig -a
br0       Link encap:Ethernet  HWaddr 08:00:27:E5:C3:27  
          inet addr:192.168.2.197  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fee5:c327/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:266675 errors:0 dropped:0 overruns:0 frame:0
          TX packets:60989 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1391858642 (1327.3 Mb)  TX bytes:4049229 (3.8 Mb)

eth0      Link encap:Ethernet  HWaddr 08:00:27:E5:C3:27  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1259099 errors:0 dropped:5 overruns:0 frame:0
          TX packets:220712 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1449135910 (1382.0 Mb)  TX bytes:51279387 (48.9 Mb)

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:11033 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11033 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:968389 (945.6 Kb)  TX bytes:968389 (945.6 Kb)

vethYW604 Link encap:Ethernet  HWaddr FE:A8:5F:48:80:7E  
          inet6 addr: fe80::fca8:5fff:fe48:807e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:251 errors:0 dropped:0 overruns:0 frame:0
          TX packets:120979 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:75398 (73.6 Kb)  TX bytes:71086180 (67.7 Mb)

gateway.localdomain 解析为 192.168.2.1

容器配置文件是:

lxc.network.type = empty
lxc.rootfs = /var/lib/lxc/TestLXC/rootfs
lxc.include = /usr/share/lxc/config/opensuse.common.conf
lxc.arch = x86_64
lxc.utsname = TestLXC
lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0

lxc.network.hwaddr = 08:00:27:e5:c3:29
lxc.aa_allow_incomplete = 1

lxc.network.ipv4 = 192.168.2.221/24
lxc.network.ipv4.gateway = 192.168.2.197

其网络详细信息如下:

route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.2.197  0.0.0.0         UG    0      0        0 eth0
192.168.2.0    *               255.255.255.0   U     0      0        0 eth0

netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.2.197  0.0.0.0         UG        0 0          0 eth0
192.168.2.0    0.0.0.0         255.255.255.0   U         0 0          0 eth0

ifconfig -a
eth0      Link encap:Ethernet  HWaddr 08:00:27:E5:C3:29  
          inet addr:192.168.2.221  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fee5:c329/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:133802 errors:0 dropped:0 overruns:0 frame:0
          TX packets:280 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:78627055 (74.9 Mb)  TX bytes:82972 (81.0 Kb)

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:26 errors:0 dropped:0 overruns:0 frame:0
          TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2152 (2.1 Kb)  TX bytes:2152 (2.1 Kb)

有人能建议我如何让我的 LXC 容器拥有完整的网络和互联网访问吗?

谢谢

答案1

您配置了网桥,这意味着主机和容器位于同一子网。因此,容器应使用与主机相同的网关,但您确实将主机的 IP 设置为默认网关。将其设置为 192.168.2.1

相关内容