我正在运行来自 VPS 提供商的 Wireguard 服务器。我想要实现的是能够将特定的互联网流量(端口 10000:11000 设置为接受来自 VPS 防火墙的流量)从 VPN 路由到我在家庭服务器上的 Docker 容器。
[Internet] <-> [Wireguard 10.100.0.1] <-> [家庭服务器 10.100.0.2(Docker 容器)]
细节:
Wireguard 服务器操作系统:Ubuntu 20.04.2 LTS
iptables 从 wg0.conf 发布向上/向下规则:
iptables -A FORWARD -i eth0 -j ACCEPT;
iptables -t nat -A PREROUTING -p tcp --dport 10000:11000 -j DNAT --to-destination 10.100.0.2;
iptables -w -t nat -A POSTROUTING -o eth0 -j MASQUERADE;
sysctl -p:
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
家庭服务器操作系统:Ubuntu 20.04.2 LTS(桌面)
systemd-networkd(wireguard 接口的.network 文件)配置:
[Match]
Name = wguard
[Network]
Address = 10.100.0.2/32
[RoutingPolicyRule]
From = 10.200.0.0/16
Table = 250
[Route]
Gateway = 10.100.0.2
Table = 250
[Route]
Destination = 0.0.0.0/0
Type = blackhole
Metric = 1
Table = 250
我在 10.200.0.0/16 中创建了一个 Docker 网络,容器正在使用这个网络。当我使用 curl 检查时,Docker 容器会返回 VPN ip 地址。
家庭服务器通过简单的 curl 查询返回我的家庭 IP 地址;但它通过wireguard接口返回VPN IP地址。
我的问题:
- 我无法从家庭服务器 ping VPN 主机,但我可以 ping 其他 VPN 客户端。我也可以从容器内 ping VPN 主机,这很奇怪。
- 从 VPN 到容器的端口转发无法正常工作。
码头工人撰写示例:
version: "3.7"
services:
rutorrent:
container_name: rutorrent1
image: romancin/rutorrent:latest
networks:
- wireguard0
ports:
- "10010:51415"
- "10011:80"
- "10012:443"
environment:
- PUID=1000
- PGID=1000
volumes:
- /home/user/Downloads/rutorrent/config:/config
- /home/user/Downloads/rutorrent/downloads:/downloads
networks:
wireguard0:
external: true
如果您至少能指出我做错的部分,我将不胜感激。我认为我的 iptables 规则缺少行,但我找不到好的参考资料或书籍来完全理解如何正确设置它。
谢谢