V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
AlphaTauriHonda
V2EX  ›  宽带症候群

用 WireGuard 和 iptables 给宽带公网 IP

  •  2
     
  •   AlphaTauriHonda · 74 天前 · 2972 次点击
    这是一个创建于 74 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用 VPS 的公网 IP 给只有内网 IP 的宽带开放端口。
    适合 T-Mobile 5G Home Internet, Starlink, Verizon 5G Home Internet, 其他 5G CPE 或者大内网移动宽带。

    先在 VPS 上装 WireGuard
    https://github.com/angristan/wireguard-install

    启用 BBR
    https://wiki.crowncloud.net/?How_to_enable_BBR_on_Ubuntu_20_04

    添加一个新用户
    我选择的 IP 是 172.22.0.2/32 ,VPS 地址用 11.22.33.44 作为例子
    cat wg-client-TEST.conf
    [Interface]
    PrivateKey =
    Address = 172.22.0.2/32
    DNS = 1.1.1.2,1.0.0.2

    [Peer]
    PublicKey =
    PresharedKey =
    Endpoint = 11.22.33.44:55
    AllowedIPs = 0.0.0.0/0,::/0

    添加 iptables 转发
    iptables -F
    iptables -t nat -F
    iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 11.22.33.44 也可以用 MASQUERADE
    iptables -t nat -A PREROUTING -p tcp --dport 2026 -d 11.22.33.0/24 -j DNAT --to-destination 172.22.0.2
    iptables -t nat -A PREROUTING -p udp --dport 2026 -d 11.22.33.0/24 -j DNAT --to-destination 172.22.0.2

    在电脑上连上 WireGuard ,qBittorrent 设置端口为 2026


    效果


    ping.pe 测试也是全部通的
    https://tcp.ping.pe/11.22.33.44:2026

    在墙内不要用 WireGuard ,换成 AmneziaWG 或者其他协议
    https://docs.amnezia.org/documentation/amnezia-wg/
    12 条回复    2025-06-06 11:28:17 +08:00
    wuruxu
        1
    wuruxu  
       74 天前
    墙内用 WireGuard 翻好几年了,一直都很稳
    yianing
        2
    yianing  
       74 天前 via Android
    和 frp 那种内外穿透的区别是什么?多了 udp 的 qos ?
    likooo125802023
        3
    likooo125802023  
       74 天前
    都行,就是要多付费 VPS 的宽带流量费不爽。
    MrLonely
        4
    MrLonely  
       74 天前
    这个端口是一个一个开嘛?用 VXLAN over WireGuard 技术,直接把整个内网二层桥到带公网的 VPS 上去,一下子所有的端口就都有了。
    aa51513
        5
    aa51513  
       74 天前 via Android
    AmneziaWG 好东西,找了很久类似软件
    ysc3839
        6
    ysc3839  
       74 天前 via Android
    建议把手写 iptables 规则换成使用 firewalld ,手写 iptables 规则太复杂,用 firewalld 配置端口转发比较简单。而且一些新的系统已经改用 nftables 了,可能不兼容 iptables 。
    JensenQian
        7
    JensenQian  
       74 天前
    https://github.com/fosrl/pangolin

    突然想到这个方案
    类似于 cf tunnel 吧,也是基于 wg 的
    AlphaTauriHonda
        8
    AlphaTauriHonda  
    OP
       73 天前 via iPhone
    @yianing 和 frp 完全不一样,frp 不能用 qBittorrent 。

    @likooo125802023 我之前是搭配 T-Mobile 5G Home Internet 还有 Starlink 用的,对比之下 VPS 几乎不要钱。

    @MrLonely 你这样更方便,或者
    iptables -t nat -A PREROUTING -p tcp --dport 1024:65535 -d 11.22.33.0/24 -j DNAT --to-destination 172.22.0.2
    iptables -t nat -A PREROUTING -p udp --dport 1024:65535 -d 11.22.33.0/24 -j DNAT --to-destination 172.22.0.2
    也不是不行
    我有几个设备要开放端口,所以要这么配置。

    @JensenQian 看起来底层是一样的

    @aa51513 类似的还有 xt_wgobfs ,还没试过
    qiaosiren
        9
    qiaosiren  
       73 天前
    厉害。学习了。
    Lambdua
        10
    Lambdua  
       73 天前
    但是这个收到 vps 带宽影响
    GhZicE
        11
    GhZicE  
       70 天前
    QB 那边的流量相当于都是 VPS 的?
    AlphaTauriHonda
        12
    AlphaTauriHonda  
    OP
       62 天前 via iPhone
    @GhZicE VPS 的流量是这个两倍以上
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3584 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:34 · PVG 18:34 · LAX 03:34 · JFK 06:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.