zer

[内网穿透] VPS 部署 Wireguard,本地 Openwrt 主路由如何保证客户端互相访问?

  •  
  •   zer · Jul 10, 2023 · 3478 views
    This topic created in 1062 days ago, the information mentioned may be changed or developed.

    目前在 VPS 部署了一个 Wireguard 服务,姑且称之为服务端,10.88.88.1/24 。
    Openwrt 的 peer 设置为 VPS ,为 Openwrt 分配到 10.88.88.3/24 。
    此时 OP 和 VPS 都能互相 ping 通 Wireguard 的 IP 。
    Openwrt 的 Lan 是 192.168.1.0/24 ,通过配置静态路由和防火墙,实现了 Lan 下的内网可以访问 10.88.88.1
    静态路由

    10.88.88.0/24 via 10.88.88.1 dev Wireguard proto static
    

    防火墙

    config zone
    	option name 'WG'
    	option input 'ACCEPT'
    	option output 'ACCEPT'
    	option network 'Wireguard'
    	option forward 'ACCEPT'
    	option masq '1'
    

    现在问题就是 VPS 和 Wireguard 的其他 peer 无法访问 192.168.1.0/24 的设备。
    尝试在 VPS 上添加路由,无效。

    ip route add 192.168.1.0/24 via 10.88.88.3 dev wg0
    

    应该如何解决这个问题呢?

    Supplement 1  ·  Jul 10, 2023

    已解决,感谢大家的帮助!
    VPS的Wireguard配置需要为Peer加上指定网段到AllowedIPs

    AllowedIPs = 10.88.88.3/32,192.168.1.0/24
    
    7 replies    2023-07-11 00:05:53 +08:00
    yuchenr
        1
    yuchenr  
       Jul 10, 2023
    vps 上有开 ip 转发吗?
    ranaanna
        2
    ranaanna  
       Jul 10, 2023
    这个好像要添加网络地址转换解决, 比如通过 ip
    iptables -t nat -A POSTROUTING -s 10.88.88.0/24 ! -d 10.88.88.0/24 -j SNAT --to-source 192.168.140.1
    或通过网络接口
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    oott123
        3
    oott123  
       Jul 10, 2023
    wg 加 AllowedIPs
    zer
        4
    zer  
    OP
       Jul 10, 2023
    @yuchenr 基本的转发是有的
    iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    yuchenr
        5
    yuchenr  
       Jul 10, 2023
    vps:
    sysctl -w net.ipv4.ip_forward=1

    allowedips 192.168.1.0/24
    zer
        6
    zer  
    OP
       Jul 10, 2023
    @yuchenr 确实可以了,我在 VPS 的 wg0.conf 里的 10.88.88.3 这个 peer 下,给 AllowedIPs 加上了 192.168.1.0/24 。
    他自动创建了一条路由
    192.168.1.0/24 dev wg0 scope link
    f14g
        7
    f14g  
       Jul 11, 2023 via Android
    试试 OSPF
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2713 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 12:05 · PVG 20:05 · LAX 05:05 · JFK 08:05
    ♥ Do have faith in what you're doing.