V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
guanyin9cn
V2EX  ›  Linux

关于 wireguard server 和 client 在同一台服务器上, 无法连接问题。

  •  
  •   guanyin9cn · 2021-09-16 13:02:14 +08:00 · 1182 次点击
    这是一个创建于 925 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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

    第 1 条附言  ·  2021-09-16 15:05:18 +08:00

    解决了,跟 iptables 没关系。

    问题出现在 route 表策略。

    ip rule add from centos_public_ip  table main
    
    

    非常奇怪的问题。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5406 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:41 · PVG 16:41 · LAX 01:41 · JFK 04:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.