【发布时间】:2021-08-19 13:10:59
【问题描述】:
我设置了一个 SSTP 客户端容器 (172.17.0.3),它通过ppp0 接口与一个 SSTP 服务器容器 (172.17.0.2) 通信。来自 SSTP 客户端容器的所有流量都通过其ppp0 接口路由,如在 SSTP 客户端容器上使用 netstat 所见(192.168.20.1 是 SSTP 服务器容器的ppp0 IP 地址):
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.20.1 0.0.0.0 UG 0 0 0 ppp0
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.20.1 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
现在,我有一个 HTTP 服务器容器 (172.17.0.4) 正在运行,我想使用另一个客户端容器(例如,一个运行 Apache Benchmark ab 的容器)通过SSTP 服务器容器。为此,我在ab 客户端容器上使用--net=container:sstp-client,因此它使用SSTP 客户端容器的网络。然而,ab 客户端容器似乎无法访问 HTTP 服务器容器,尽管 它能够对 Internet 上的服务器进行基准测试(例如,8.8.8.8)。再举个例子,如果我从一个容器通过 SSTP 客户端容器执行traceroute 到8.8.8.8:
docker run -it --name alpine --net=container:sstp-client alpine ash
/ # traceroute -s 192.168.20.2 google.com
traceroute to google.com (142.250.65.206) from 192.168.20.2, 30 hops max, 46 byte packets
1 192.168.20.1 (192.168.20.1) 1.088 ms 1.006 ms 1.077 ms
2 * * *
3 10.0.2.2 (10.0.2.2) 1.710 ms 1.695 ms 0.977 ms
4 * * *
...
我终于可以联系到 Google。
但如果我 traceroute 到我的 HTTP 服务器容器:
/ # traceroute -s 192.168.20.2 172.17.0.4
traceroute to 172.17.0.4 (172.17.0.4) from 192.168.20.2, 30 hops max, 46 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
...
失败了。
我怀疑 SSTP 服务器容器上的路由配置不正确,但我不确定如何修复它以使其正常工作。我的目标是能够到达外部世界和内部容器。我已经搞砸了iptables 和route 很多,但仍然无法使其工作。这是我当前对 SSTP 服务器容器的配置:
/ # netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.20.0 172.17.0.2 255.255.255.255 UGH 0 0 0 eth0
192.168.20.0 172.17.0.2 255.255.255.0 UG 0 0 0 eth0
192.168.20.2 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
/ # iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -i ppp+ -j ACCEPT
-A FORWARD -j ACCEPT
-A OUTPUT -o ppp+ -j ACCEPT
我已经看到许多关于如何通过 VPN 容器路由到 Internet 的在线解决方案,但对其他容器却一无所知。在这个领域非常新手。欢迎任何建议!谢谢。
【问题讨论】:
标签: docker networking containers