8675bc86

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

  •  
  •   8675bc86 · Sep 8, 2023 · 3420 views
    This topic created in 1153 days ago, the information mentioned may be changed or developed.

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

    10 replies  •  2023-09-09 09:29:20 +08:00
    cq65617875
    cq65617875
    Sep 8, 2023
    1
    写个脚本做检测呗,不通了就重置服务
    maybeonly
    maybeonly
    Sep 8, 2023
    2
    写个脚本就好了,检查域名,如果有变化就重联
    手敲一段,请自行调试修改
    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 之类的比较笨重的东西让他给你做。
    Yishanshan
    Yishanshan
    Sep 8, 2023
    3
    win11 环境重连都不行,必须重新编辑一下 conf 文件
    haffner
    haffner
    Sep 8, 2023 via iPhone
    4
    PersistentKeepalive = 25
    一直用得挺好啊,无需手动断开重连,还是说我理解错楼主想表达的意思了?
    gaju
    gaju
    Sep 8, 2023 via Android
    5
    @maybeonly 鄙人写不出这样的脚本,就写了个定时每晚重启,稳定运行半年了。
    lcdtyph
    lcdtyph
    Sep 8, 2023
    6
    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
    8675bc86
    OP
    Sep 8, 2023
    7
    @lcdtyph 嗯,估计只能这么搞了。
    esile
    esile
    Sep 9, 2023
    8
    @haffner ddns 这种不行,必须断开重连才能解析到新 ip 上面去的
    yuchenr
    yuchenr
    Sep 9, 2023
    9
    用 networkmanager 呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2548 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 15:03 · PVG 23:03 · LAX 07:03 · JFK 10:03
    ♥ Do have faith in what you're doing.