WireGuard / wireguard-vyatta-ubnt

WireGuard for Ubiquiti Devices
https://www.wireguard.com/
GNU General Public License v3.0
1.45k stars 68 forks source link

Reresolve DNS Periodically #130

Open dshanske opened 1 year ago

dshanske commented 1 year ago

I have a dynamic IP address on one side of a site-to-site connection between two edgeos devices. Every so often, I get a new address...usually during an outage, and I have to manually cycle things. The endpoints are configured with a hostname that is updated via dyndns. I'd like a way for it to reresolve on some sort of schedule as an option.

dc361 commented 1 year ago

How about using the Edgerouter task scheduler? You could set it up something like this: (note .. I saw this method on the net the other day to do another task so I tweaked it for this issue...)

cat > /config/scripts/peer-update.sh <<'EOF'
#!/bin/bash
echo "sudo wg set wg0 peer z-whatever-peer-public-key= endpoint a-host.on-the.net:56789" > /tmp/peer-update-result.txt
EOF

chmod +x /config/scripts/peer-update.sh

configure
set system task-scheduler task peer-update executable path /config/scripts/peer-update.sh
set system task-scheduler task peer-update interval 20m
commit ; save ; exit

The first part of the script sets up the script file (only needs to be done once initially and every time you update EdgeOS).
The "configure" section creates a task to run the script which gets called every 20 minutes in this example. The task also creates an output file (/tmp/peer-update-result.txt) that you can check periodically to make sure the script is working.