We use WireGuard to connect to various endpoints with dynamic IP addresses. However, VyOS does not currently support hostname addresses and requires a static IP (Example: 1.2.3.4 below).
In addition to a wireguard config like you have in your post I use this script to update the tunnel with the dynamically assigned IP address, which is pointed to by a dynamically assigned DNS entry using a service like DynDNS:
/config/scripts$ cat update-wg0.sh
#!/bin/sh
sudo wg set wg0 peer <public key> endpoint <dynamic dns hostname>:<port num>
and I have a scheduled task in the normal config that runs this script every minute:
Never considered directly altering the wg peer. I wrote a script that modifies the VyOS config without “talking behind its back” … it gets called on startup. I could also add to task-scheduler but these IPs rarely change. Any suggestions to improve greatly appreciated.
/config/scripts/wg-peer-111.script
#!/bin/vbash
if [ "$(id -g -n)" != 'vyattacfg' ] ; then
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
fi
source /opt/vyatta/etc/functions/script-template
newIP=$(getent hosts remote-host.example.com | awk '{ print $1 }')
oldIP=$(run show interfaces wireguard wg111 endpoints | awk '{ print $2 }' | awk -F ':' '{ print $1 }')
echo $newIP
echo $oldIP
if [ $newIP != $oldIP ]
then
configure
set interfaces wireguard wg111 peer location1 address $newIP
commit
save
fi
/config/scripts/vyos-postconfig-bootup.script
#Call local scripts
/config/scripts/wg-peer-111.script