RT,
根据这个 reddit 讨论做的 ,www.reddit.com/r/WireGuard/comments/ekeprt/wireguard_to_wireguard_setup_im_sure_many_have
centos 7 中继。
数据流是 :wg client (openwrt ) --> wg server (centos7) --> wg client(centos7) ---> vps
server, wg0.conf 的配置
[Interface] PrivateKey = Address = 10.0.1.1/24 PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o ens192 -j MASQUERADE PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o ens192 -j MASQUERADE ListenPort = 443 MTU = 1420 FwMark = 51820 [PEER] PUBLICKEY = ALLOWEDIPS =
client , vpn-client.conf
[Interface] PrivateKey = Address = 10.0.2.11/32 MTU = 1420 FwMark = 51820 PostUp = iptables -t nat -A POSTROUTING -o vpn-client -j MASQUERADE PostDown = iptables -t nat -D POSTROUTING -o vpn-client -j MASQUERADE [Peer] PublicKey = Endpoint = PersistentKeepalive = 25 AllowedIPs = 0.0.0.0/0
server 和 client 的 FwMark 均设置为 51820 。
现状是 通过 openwrt 连接 server 时,可以通过 10.0.1.1 访问 centos7.
在 centos7 可以访问 ping 公网网关。 但是 在 本地 pc 上,或者其他 服务器上,无法 ping centos7 的 公网 ip,不通。
能从 wg client 的情况下 访问的原因,看了下 iptables 的 mangle 表 , 应该只允许了 udp 。
-A PREROUTING -p udp -m comment --comment "wg-quick(8) rule for vpn-client" -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff -A POSTROUTING -p udp -m mark --mark 0xca6c -m comment --comment "wg-quick(8) rule for vpn-client" -j CONNMARK --save-mark --nfmask 0xffffffff --ctmask 0xffffffff
@dndx
解决了,跟 iptables 没关系。
问题出现在 route 表策略。
ip rule add from centos_public_ip table main
非常奇怪的问题。