我有一个专用服务器,我正在尝试创build一个NAT。 我的虚拟主机是LinuX容器,我只有一个公共IP地址,我试图连接到我的LXC内的互联网。
在我的主机上,我有一个互联网访问的默认界面是eno1,我创build了一个桥梁:
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的networkingconfiguration:
# 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
然后我input这个iptables规则来创build一个伪装:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eno1 -j MASQUERADE
当我启动容器时,我可以从主机ping它,但是当我join容器并执行apt更新(这是我用来检查因特网访问的命令,因为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
请帮帮我,我一直坚持这个好几天!