NAT 无法与 LXC 配合使用

NAT 无法与 LXC 配合使用

我有一台专用服务器,正在尝试创建 NAT。我的虚拟主机是 LinuX 容器,我只有一个公共 IP 地址,我正在尝试通过 LXC 连接到互联网。

在我的主机上,我可以访问互联网的默认接口是 eno1,并且我在其上创建了一个桥接器:

auto lxc-nat-bridge
iface lxc-nat-bridge inet static
    bridge_ports none
    bridge_fd 0
    bridge_stp off
    address 192.168.1.1
    netmask 255.255.255.0
    post-up echo 1 > /proc/sys/net/ipv4/ip_forward

这是我的 LXC 的网络配置:

# Network configuration
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxc-nat-bridge
lxc.network.ipv4 = 192.168.1.2/24
lxc.network.ipv4.gateway = 192.168.1.1
lxc.network.veth.pair = vethWeb

然后我输入了这个 iptables 规则来创建一个伪装:

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eno1 -j MASQUERADE

当我启动容器时,我可以从主机 ping 它,但是当我加入容器并执行 apt update 时(这是我用来检查互联网访问的命令,因为没有安装 ping):

root@web_container:/# apt update
Err:1 http://deb.debian.org/debian stretch InRelease                 
  Temporary failure resolving 'deb.debian.org'
Err:2 http://security.debian.org stretch/updates InRelease           
  Temporary failure resolving 'security.debian.org'
Reading package lists... Done                                        
Building dependency tree       
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/dists/stretch/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
root@web_container:/#

它不起作用:(

以下是在容器中执行的 ifconfig:

root@web_container:/# /sbin/ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255
    inet6 fe80::7c2c:37ff:fe50:ab0e  prefixlen 64  scopeid 0x20<link>
    ether 7e:2c:37:50:ab:0e  txqueuelen 1000  (Ethernet)
    RX packets 11  bytes 786 (786.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 60  bytes 4623 (4.5 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

大家请帮帮我,我已经被这个问题困扰好几天了!

相关内容