如何在 Linux 上自动重新解析 Wireguard 中的 DNS
在 Linux 上安装 wireguard-tools 时,它包含一个名为 reresolve-dns.sh 的脚本。这将负责自动重新解析。
根据其文档,你应该每 30 秒左右运行一次。
所以我们可以创建一个 systemd 计时器每 30 秒运行一次。
简单方法
使用我们的脚本
install_reresolve_dns.sh
wget -qO- https://techoverflow.net/scripts/install-wireguard-reresolve-dns.sh | sudo bash /dev/stdin现在你需要**为每个相关接口单独启用它,**例如对于 wg0:
enable_wg_reresolve_timer_example.sh
systemctl enable --now [email protected]困难方法
手动执行我们脚本所做的事情。
创建 /etc/systemd/system/[email protected]:
wg-reresolve-dns.service
[Unit]
Description=wg-reresolve-dns@
[Service]
Type=oneshot
ExecStart=/usr/share/doc/wireguard-tools/examples/reresolve-dns/reresolve-dns.sh %i创建 /etc/systemd/system/[email protected]:
wg-reresolve-dns.timer
[Unit]
Description=wg-reresolve-dns@ timer
[Timer]
Unit=wg-reresolve-dns@%i.service
OnCalendar=*-*-* *:*:00,30
Persistent=true
[Install]
WantedBy=timers.target现在你需要**为每个相关接口单独启用它,**例如对于 wg0:
enable_wg_reresolve_timer.sh
systemctl enable --now [email protected]Check out similar posts by category:
Networking, Systemd, VPN, Wireguard
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow