ghostwwg

wireguard 布网故障

  •  
  •   ghostwwg · Apr 12, 2024 · 3843 views
    This topic created in 937 days ago, the information mentioned may be changed or developed.

    场景: 我是在 A ( lan 192.168.1.0/24 ) B(192.168.88.0/24) 两处都部署了 wiregurd 希望从外网可以链接 A B 的局域网。

    现象: 我节点 C 在外网是可以顺利链接 A B 任意一个的 lan 都是没有问题的。 BUT !!! 节点 B 内网无法访问 节点 A 反之也是!!!!

    求问: 这该咋排查。。。

    Supplement 1  ·  May 8, 2024
    很南评,自己好了。期间没有做过有效操作。

    无效排错:

    1 ) A & B 各自再拉起一个 wg 对链测试,A --> B 正常,B --> A 异常。

    2 ) 删除了 B 节点中网络的静态路由。 当然,正常后我重新加回去了,测试也正常。

    3 ) 时间点在 1 ) 2 ) 之前,测试抓包,A <--> B 互不通。 抓不到包。在压根没打到对面。
    28 replies  •  2024-04-26 09:24:29 +08:00
    Jimmyisme
    Jimmyisme
    Apr 12, 2024
    1
    一般都是 allowips 的锅
    ghostwwg
    ghostwwg
    OP
    Apr 12, 2024
    2
    @Jimmyisme 应该木有问题,外网 C 是能顺利访问的。附上我的 allowips 配置

    节点 A:
    ---
    配置节点 B 的信息:
    AllowedIPs = 10.252.1.1/32, 192.168.88.0/24
    ----

    节点 B:
    ---
    配置节点 A 的信息:
    AllowedIPs = 10.252.1.2/32, 192.168.1.0/24
    ----
    Damn
    Damn
    Apr 12, 2024 via iPhone
    3
    还有路由表。OpenWrt 有一个选项可以自动添加,点点点即可,非 OpenWrt 可能需要手动添加路由。
    bobryjosin
    bobryjosin
    Apr 12, 2024 via Android
    4
    在哪个系统部署的,配置文件贴出来
    csdreamdong
    csdreamdong
    Apr 12, 2024
    5
    C 节点,要开 ip_forward ,以及 C 上面的要有去 A 和 B 的路由
    Ipsum
    Ipsum
    Apr 12, 2024
    6
    如果 c 可以访问到 ab ,那 c 的 postrouting 添加出 wg 接口的伪装。因为 ab 没有对方的路由表
    ghostwwg
    ghostwwg
    OP
    Apr 12, 2024
    7
    @bobryjosin

    节点 A
    --------------
    root@j1900:~# cat /etc/wireguard/wg0.conf
    # peer_201# Address updated at:    2022-08-13 02:04:21.28015476 +0000 UTC
    # Private Key updated at: 2022-08-12 11:34:22.54225801 +0000 UTC
    [Interface]
    Address = 10.252.1.2/32
    ListenPort = 52320
    PrivateKey = xxx
    MTU = 1450
    PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
    PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o br0 -j MASQUERADE
    # ID:          phone
    # Name:        peer_C1
    # Email:
    # Created at:  2022-08-13 02:03:42.226570346 +0000 UTC
    # Update at:    2022-08-13 02:03:42.226570346 +0000 UTC
    [Peer]
    PublicKey = xxx
    AllowedIPs = 10.252.1.3/32
    # ID:          yoga
    # Name:        peer_C2
    # Email:
    # Created at:  2022-08-13 02:04:00.216322658 +0000 UTC
    # Update at:    2022-08-13 02:04:00.216322658 +0000 UTC
    [Peer]
    PublicKey = xxx
    AllowedIPs = 10.252.1.4/32
    # ID:          business tmp
    # Name:        peer_C3
    # Email:
    # Created at:  2023-05-30 02:04:00.216322658 +0000 UTC
    # Update at:    2023-05-30 02:04:00.216322658 +0000 UTC
    [Peer]
    PublicKey = xxx
    AllowedIPs = 10.252.1.5/32
    # ID:          dev_ub2004
    # Name:        peer_C4
    # Email:
    # Created at:  2023-05-30 02:04:00.216322658 +0000 UTC
    # Update at:    2023-05-30 02:04:00.216322658 +0000 UTC
    [Peer]
    PublicKey = xxx
    AllowedIPs = 10.252.1.6/32
    # ID:          cbrgd76jimivehamds2g
    # Name:        peer_403
    # Email:
    # Created at:  2022-08-13 02:04:12.49288016 +0000 UTC
    # Update at:    2022-08-13 05:02:27.105906129 +0000 UTC
    [Peer]
    PublicKey = xxx
    AllowedIPs = 10.252.1.1/32, 192.168.88.0/24
    Endpoint = ddnsXXX.space:52320
    PersistentKeepalive = 25
    --------------
    节点 B
    -------------
    # peer_403

    # Address updated at: 2022-08-13 02:04:21.28015476 +0000 UTC
    # Private Key updated at: 2022-08-12 11:34:22.54225801 +0000 UTC
    [Interface]
    Address = 10.252.1.1/32
    ListenPort = 52320
    PrivateKey = XXXX
    MTU = 1450
    PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
    PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o br0 -j MASQUERADE


    # ID: phone
    # Name: peer_C1
    # Email:
    # Created at: 2022-08-13 02:03:42.226570346 +0000 UTC
    # Update at: 2022-08-13 02:03:42.226570346 +0000 UTC
    [Peer]
    PublicKey = XXXXXX
    AllowedIPs = 10.252.1.3/32

    # ID: yoga
    # Name: peer_C2
    # Email:
    # Created at: 2022-08-13 02:04:00.216322658 +0000 UTC
    # Update at: 2022-08-13 02:04:00.216322658 +0000 UTC
    [Peer]
    PublicKey = xxx
    AllowedIPs = 10.252.1.4/32

    # ID: business tmp
    # Name: peer_C3
    # Email:
    # Created at: 2023-05-30 02:04:00.216322658 +0000 UTC
    # Update at: 2023-05-30 02:04:00.216322658 +0000 UTC
    [Peer]
    PublicKey = xxx
    AllowedIPs = 10.252.1.5/32

    # ID: dev_ub2004
    # Name: peer_C4
    # Email:
    # Created at: 2023-05-30 02:04:00.216322658 +0000 UTC
    # Update at: 2023-05-30 02:04:00.216322658 +0000 UTC
    [Peer]
    PublicKey = xxxxx
    AllowedIPs = 10.252.1.6/32

    # ID: xxxxxxx
    # Name: peer_201
    # Email:
    # Created at: 2022-08-13 02:04:12.49288016 +0000 UTC
    # Update at: 2022-08-13 05:02:27.105906129 +0000 UTC
    [Peer]
    PublicKey = xxxx
    AllowedIPs = 10.252.1.2/32, 192.168.1.0/24
    Endpoint = ddnsxxxxA.space:52320
    PersistentKeepalive = 25

    ------------
    ghostwwg
    ghostwwg
    OP
    Apr 12, 2024
    8
    @csdreamdong 节点 C 就是 PC ,能正常访问 A B 两个节点的局域网,但 AB 局域网无法互相访问。。
    ghostwwg
    ghostwwg
    OP
    Apr 12, 2024
    9
    @Ipsum 有

    节点 A
    -----------
    root@j1900:~# ip r|grep 88
    192.168.88.0/24 dev wg0 scope link
    -----------


    节点 B
    ----------------
    root@wuwg-EQ:~# ip r|grep 1.0
    169.254.0.0/16 dev br0 scope link metric 1000
    192.168.1.0/24 dev wg0 scope link

    ---------------
    ghostwwg
    ghostwwg
    OP
    Apr 12, 2024
    10
    @Damn 路由是有的
    Ipsum
    Ipsum
    Apr 12, 2024
    11
    ddnsXXX.space:52320 这是节点 c ?
    Ipsum
    Ipsum
    Apr 12, 2024
    12
    试试
    把 iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
    改成
    iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
    ghostwwg
    ghostwwg
    OP
    Apr 12, 2024
    13
    @Ipsum
    带 ddns 的是节点 A 和节点 b

    节点 C ( pc )走外网是能链接节点 A\B 的局域网的(捂脸
    Ipsum
    Ipsum
    Apr 12, 2024 via Android
    14
    sysctl -a |grep forward 看看
    guanzhangzhang
    guanzhangzhang
    Apr 12, 2024
    15
    节点 c 的 wg 写

    peer A
    allowIPs= A 的局域网

    peerb
    allowIPs= B 的局域网

    要开 forward 和 snat
    Qetesh
    Qetesh
    Apr 12, 2024
    16
    用 wg 看下,很大可能 A-B 不通
    Dzsss
    Dzsss
    Apr 12, 2024
    17
    OSPF 解君愁。A B 都上 MikroTik ,然后 A B 跑 OSPF 。
    fuckshiter
    fuckshiter
    Apr 12, 2024
    18
    把 wg-quick interface 搞上来看看
    ghostwwg
    ghostwwg
    OP
    Apr 12, 2024
    19
    @Qetesh 现在就是节点 A <--> B 不通,但作为对外服务的 wg 节点(AB),我的客户端 C ( pc )是可以链接 AB 两个节点的.
    Qetesh
    Qetesh
    Apr 12, 2024
    20
    @ghostwwg wireguard 是类似 Mesh 网络,全连接的状态。怀疑 AB 之间的认证的公私钥等有问题
    wxhwz
    wxhwz
    Apr 13, 2024
    21
    描述有点模糊没看明白,假设节点 a 、b 之间能互相访问,但下面内网 a 其余机器无法访问内网 b
    因为流量从 br0 到节点 a ,然后通过 wg0 传到 b ,现在是断在这一步
    所以 a 主机在原基础上需要加一个
    iptables -t nat -I POSTROUTING -o wg0 -j MASQUERADE
    ghostwwg
    ghostwwg
    OP
    Apr 13, 2024
    22
    @wxhwz 接点 A B 是有公网 IP 对外提供接入服务的,
    - 节点 C 是客户端( PC )链接后能访问 A \ B 的局域网,
    - 但是! 节点 A 和节点 B 无法互相访问(捂脸哭泣。。。
    Ipsum
    Ipsum
    Apr 13, 2024
    23
    @ghostwwg AB 上 sysctl -a |grep forward 看看
    wxhwz
    wxhwz
    Apr 13, 2024
    24
    @ghostwwg #22
    A 配置文件中
    [Interface]
    Address = 10.252.1.1/32
    改成
    Address = 10.252.1.1/24
    B 主机同理

    如果还是不行的话,检查下密钥有没有配错
    Andy1989
    Andy1989
    Apr 15, 2024
    25
    @ghostwwg #2 我觉得你好像需要在你的节点 A AllowedIPs 里面加上 192.168.1.0/24 , 然后在节点 B 的 AllowedIPs 里面加上 192.168.88.0/24 吧。
    ghostwwg
    ghostwwg
    OP
    Apr 25, 2024
    26
    @guanzhangzhang 节点 C (客户端)是这么写的,是可以链接 A B 的,但 A B 互相不通。。
    ghostwwg
    ghostwwg
    OP
    Apr 25, 2024
    27
    @Andy1989 这个有的,节点 C 能访问 A B 我判断 A B 的 wg 服务是正常能对外提供链接的,但 AB 又不能互联,我 check 了他们( AB )的配置文件。。。又没找到什么问题。。
    guanzhangzhang
    guanzhangzhang
    Apr 26, 2024
    28
    @ghostwwg #26 ping 的时候抓包看看
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1277 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 19:28 · PVG 03:28 · LAX 11:28 · JFK 14:28
    ♥ Do have faith in what you're doing.