Wireguard 未将流量路由回

Wireguard 未将流量路由回

我有 2 台 Ubuntu 服务器,上面安装了wireguard。一台服务器充当中间人。所以客户端流量被路由到中间服务器,中间服务器将它们路由到另一台服务器(我在这里称之为服务器1)。就我而言,流量完全从客户端路由到中间服务器,然后路由到服务器 1 。但它不会路由回中间服务器,因此当连接wireguard 时没有互联网。服务器 1 上的输出wg show如下:

interface: wg0
  public key: Public-Key
  private key: (hidden)
  listening port: 51880

peer: Public_key
  endpoint: [middle server ip:port]
  allowed ips: 10.0.0.0/24
  latest handshake: 1 minute, 21 seconds ago
  transfer: 7.34 KiB received, 372 B sent
  persistent keepalive: every 25 seconds

这是我的服务器和客户端配置:

服务器1配置:

[Interface]
PrivateKey = Private-Key
Address = 10.0.0.1/24
ListenPort = 51880
MTU = 1500

PostUp = iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ufw route allow in on wg0 out on eth0; ufw route allow in on eth0 out on wg0; ufw allow proto udp from any to any port 51880
PostDown = iptables -D FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ufw route delete allow in on wg0 out on eth0; ufw route delete allow in on eth0 out on wg0; ufw delete allow proto udp from any to any port 51880


[Peer]
PublicKey = middle server Public-Key
AllowedIPs = 10.0.0.2/24
EndPoint = [middle server ip:port]
PersistentKeepalive = 25

中间服务器配置:

[Interface]
PrivateKey = Private-Key
Address = 10.0.0.2/24
ListenPort = 52890
Table = 123
MTU = 1500

PreUp = ip rule add iif wg0 table 123 priority 456
PostUp = iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ufw route allow in on wg0 out on eth0; ufw route allow in on eth0 out on wg0; ufw allow proto udp from any to any port 52890
PostDown = iptables -D FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ufw route delete allow in on wg0 out on eth0; ufw route delete allow in on eth0 out on wg0; ufw delete allow proto udp from any to any port 52890; ip rule del iif wg0 table 123 priority 456

[Peer]
PublicKey = Server 1 Public-Key
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

[Peer]
PublicKey = Clint Public-key
AllowedIPs = 10.0.0.102/32

客户端配置(Windows客户端):

[Interface]
PrivateKey = Private-Key
Address = 10.0.0.102/32
DNS = 1.1.1.1, 1.0.0.1
MTU = 1480

[Peer]
PublicKey = middle server Public-Key
AllowedIPs = 0.0.0.0/1, 128.0.0.0/1
Endpoint = [Middle server ip:port]
PersistentKeepalive = 25

我尝试更改端口和地址,但没有成功。

相关内容