NAT伪装第二个容器网络

NAT伪装第二个容器网络

我有 1 个公共 IP,想与运行 Centos 的 LXC 容器共享互联网连接(在此设置中),主机运行 proxmox(基于 debian)。如果我理解正确的话,我需要 NAT 伪装,问题是,我创建的第二个容器无法访问网络。

主机上的设置:

ifconfig 命令:

eth0      Link encap:Ethernet  HWaddr 0c:c4:7a:d9:1f:e8
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:15789748 errors:0 dropped:3170 overruns:0 frame:0
          TX packets:6323926 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:13693916365 (12.7 GiB)  TX bytes:1077829250 (1.0 GiB)

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:11041 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11041 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:3907254 (3.7 MiB)  TX bytes:3907254 (3.7 MiB)

veth104i0 Link encap:Ethernet  HWaddr fe:b4:26:dc:aa:ac
          inet6 addr: fe80::fcb4:26ff:fedc:aaac/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:663 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10100 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:62852 (61.3 KiB)  TX bytes:883353 (862.6 KiB)

veth105i0 Link encap:Ethernet  HWaddr fe:69:8f:16:a3:40
          inet6 addr: fe80::fc69:8fff:fe16:a340/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:447158 errors:0 dropped:0 overruns:0 frame:0
          TX packets:401684 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:46903237 (44.7 MiB)  TX bytes:5625117349 (5.2 GiB)

vmbr0     Link encap:Ethernet  HWaddr 0c:c4:7a:d9:1f:e8
          inet addr:*public IP* Bcast:*****  Mask:255.255.0.0
          inet6 addr:**** Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:503891 errors:0 dropped:0 overruns:0 frame:0
          TX packets:527129 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5637105768 (5.2 GiB)  TX bytes:61721641 (58.8 MiB)

vmbr1     Link encap:Ethernet  HWaddr fe:69:8f:16:a3:40
          inet addr:10.10.10.254  Bcast:10.10.10.255  Mask:255.255.255.0
          inet6 addr: fe80::b42e:2eff:fe1a:5640/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:447158 errors:0 dropped:0 overruns:0 frame:0
          TX packets:401684 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:40643025 (38.7 MiB)  TX bytes:5625117349 (5.2 GiB)

iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  10.10.10.0/24       !10.10.10.0/24
MASQUERADE  all  --  10.10.10.0/24        anywhere
MASQUERADE  all  --  10.10.10.0/24       !10.10.10.0/24

/etc/网络/接口

auto lo
iface lo inet loopback

iface eth0 inet manual

auto vmbr0
iface vmbr0 inet dhcp
        netmask 255.255.255.0
        gateway 143.169.254.254
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0

auto vmbr1
iface vmbr1 inet static
        address 10.10.10.254
        netmask 255.255.255.0
        network 10.10.10.0
        broadcast 10.10.10.255
        bridge_ports none
        bridge_stp off
        bridge_fd 0
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up         iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE
        post-up         iptables -t nat -A POSTROUTING -s '10.10.10.0/24' ! -d '10.10.10.0/24' -o vmbr0 -j MASQUERADE
        post-down       iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE

路线-n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         *public gateway* 0.0.0.0         UG    0      0        0 vmbr0
10.10.10.0      0.0.0.0         255.255.255.0   U     0      0        0 vmbr1
xxx.xxx.0.0     0.0.0.0         255.255.0.0     U     0      0        0 vmbr0

在两个容器上(私有IP不同):

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.10.10.254    0.0.0.0         UG    0      0        0 eth0
10.10.10.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1031   0        0 eth0

是否配置

eth0      Link encap:Ethernet  HWaddr 2E:15:95:39:D1:17
          inet addr:10.10.10.4  Bcast:10.10.10.255  Mask:255.255.255.0
          inet6 addr: fe80::2c15:95ff:fe39:d117/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12437 errors:0 dropped:38 overruns:0 frame:0
          TX packets:665 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1106036 (1.0 MiB)  TX bytes:63024 (61.5 KiB)

/etc/sysconfig/网络脚本/ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.10.10.4
NETMASK=255.255.255.0
GATEWAY=10.10.10.254

我如何让网络连接到两个容器?系统管理员如何才能找出这里出了什么问题?我可以从第一个容器 ping 到主机。但不能从第二个容器 ping 到主机或邻居。

答案1

在 proxmox 界面中有一个选项,可以设置指向哪个虚拟桥。这个设置是错误的:

在此处输入图片描述

相关内容