我正在尝试为 CGNAT 后面的 NAS 设置一个 wireguard 隧道。我参考了这份有用的指南: https:

但是我正在使用 VPS 作为 wireguard 服务器来设置站点到站点 VPN。在客户端,我按照上述指南进行设置。

客户端wg0.conf:

[Interface]
Address = 10.13.13.2
PrivateKey = 
ListenPort = 51820
DNS = 10.13.13.1

PostUp = iptables -t nat -A POSTROUTING -o wg+ -j MASQUERADE; iptables -t nat -A PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 172.20.0.2:5000
PreDown = iptables -t nat -D POSTROUTING -o wg+ -j MASQUERADE; iptables -t nat -D PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 172.20.0.2:5000

[Peer]
PublicKey = 
PresharedKey = 
Endpoint = <server-ip>:51820
AllowedIPs = 0.0.0.0/0

然后运行:

docker exec --privileged qbittorrent ip route del default
docker exec --privileged qbittorrent ip route add default via 172.20.0.50

docker exec --privileged qbittorrent ip route add 192.168.0.0/24 via 172.20.0.1

在服务器上我也在 docker 中运行 wireguard:

services:
  wireguard:
    image: lscr.io/linuxserver/wireguard:latest
    container_name: wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE #optional
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - SERVERURL=<server-ip> #optional
      - SERVERPORT=51820 #optional
      - PEERS=1 #optional
      - PEERDNS=auto #optional
      - INTERNAL_SUBNET=10.13.13.0 #optional
      - ALLOWEDIPS=0.0.0.0/0 #optional
      - PERSISTENTKEEPALIVE_PEERS= #optional
      - LOG_CONFS=true #optional
    volumes:
      - /home/ajit/.config/appdata/wg:/config
      - /lib/modules:/lib/modules #optional
    ports:
      - 51820:51820/udp
      - 5000:5000
      - 5000:5000/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped

[Interface]
Address = 10.13.13.1
ListenPort = 51820
PrivateKey = 
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth+ -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth+ -j MASQUERADE


PreUp = iptables -t nat -A PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 10.13.13.2:5000
PostDown = iptables -t nat -D PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 10.13.13.2:5000
PreUp = iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -o wg0 -j MASQUERADE

[Peer]
# peer1
PublicKey = 
PresharedKey = 
AllowedIPs = 10.13.13.2/32

中获得了第二组 iptable 路由,对此我表示怀疑。

有效的方法:

  • qbittorrent 流量通过 wireguard 路由到远程 VPS
  • 可以在本地访问 qbittorrent webUI
  • 在线端口检查器报告我的端口为开放,但是没有实际的连接!

如果我在 qbitorrent 容器中运行:nc -l 5000

和我的电脑:curl --connect-timeout 5 <server-ip>:5000

curl: (28) Failed to connect to <ip> port 5000 after 5003 ms: Timeout was reached

因此,没有真正的联系!

欢迎任何反馈。

更新:我相信我已经解决了这个问题。。我必须添加更多 iptable 规则。我使用 chatgpt 来帮助解决这个问题 🙂 成功了!

我尝试在 qbittorrent 容器内运行nc -l 5000和,并且都成功接收。这是 singularity 的又一次胜利 :0nc -ul 5000

如果有人对配置感兴趣请告诉我…

尽管 qBittorrent 仍然显示防火墙,但我相信随着连接的建立它会变成绿色。

0