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

wireguard ddns ip 变更后客户端要手动断开重连很烦

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

    MAC/Linux 下有没有比较好的方法,目前已知运营线变更公网 ip 时间不确定,从自己写的变更通知来看,有时候几天变更,有时候一天变更几次。

    10 条回复    2023-09-09 09:29:20 +08:00
    cq65617875
        1
    cq65617875  
       232 天前
    写个脚本做检测呗,不通了就重置服务
    maybeonly
        2
    maybeonly  
       232 天前
    写个脚本就好了,检查域名,如果有变化就重联
    手敲一段,请自行调试修改
    domain=ddns.yourdomain.com
    lastip=
    while [ ture ]
    do
    newip=$(dig "${domain}" +short A | grep -E '^[0-9\.]+$' | head -1)
    # v6: $(dig "${domain}" +short AAAA | grep -E '^[0-9a-f\:\.]+$' | head -1)
    if [ "${newip}" != "${lastip}" ]
    then
    if [ -n "${lastip}" ]
    then
    # reconnect here
    fi
    lastip="${newip}"
    fi
    sleep 60
    done
    或者呢
    用 openvpn 之类的比较笨重的东西让他给你做。
    Baymaxbowen
        3
    Baymaxbowen  
       232 天前
    win11 环境重连都不行,必须重新编辑一下 conf 文件
    haffner
        4
    haffner  
       232 天前 via iPhone
    PersistentKeepalive = 25
    一直用得挺好啊,无需手动断开重连,还是说我理解错楼主想表达的意思了?
    gaju
        5
    gaju  
       232 天前 via Android
    @maybeonly 鄙人写不出这样的脚本,就写了个定时每晚重启,稳定运行半年了。
    lcdtyph
        6
    lcdtyph  
       232 天前
    linux 下 wireguard-tools 里有一个 reresolve-dns.sh 脚本就是用来动态更新域名 endpoint 的,你可以把它加在 crontab 里定时运行就行了,唯一参数是 wireguard interface 对应的配置文件
    macOS 下也可以用这个脚本,但是可能得改改,我没在 mac 上用过

    如果找不到的话可以直接去官方 repo 下载 https://git.zx2c4.com/wireguard-tools/tree/contrib/reresolve-dns/reresolve-dns.sh
    里面还有一些别的很趁手的脚本

    windows 下我就不知道了
    8675bc86
        7
    8675bc86  
    OP
       232 天前
    @lcdtyph 嗯,估计只能这么搞了。
    esile
        8
    esile  
       231 天前
    @haffner ddns 这种不行,必须断开重连才能解析到新 ip 上面去的
    yuchenr
        9
    yuchenr  
       231 天前
    用 networkmanager 呢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2888 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:10 · PVG 15:10 · LAX 00:10 · JFK 03:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.