Ideas for getting Wireguard to work with hostname instead of IP address

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: below).

wireguard wg110 {
        description remote network
        mtu 1420
        peer xxxxx.tld {
            allowed-ips ::/0
            persistent-keepalive 10
            port 51820
            preshared-key ****************
            public-key ****************
        port 51822
        private-key xxxxxx

Until this feature gets developed, is there a way in VyOS to write a script to update the IP (resolve hostname to IP address) at reboot?

How would the script execute – is there a config command to call a script on boot, for example? Or a way to call it with cron?

Where should the script be saved so it survives system upgrades?

What would the script update (config.boot?) and how should the updated configuration be loaded?

And lastly, what technique might one use to “find and replace” the old IP address under the wg peer, and update it with the new one?

Happy to write something like this for the community, but not sure how best to apply it to VyOS.

Hi @ajgnet,

you can check our document page that will guide you across your questions, i think most of them are answered there!

please read carefully there are some thing that you need to include in the scripts for them to work properly.


That’s great, thank you! Any resources for sample scripts?

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

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:

    task-scheduler {
        task update-wg0 {
            executable {
                path /config/scripts/
            interval 1

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.



if [ "$(id -g -n)" != 'vyattacfg' ] ; then
    exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
source /opt/vyatta/etc/functions/script-template

newIP=$(getent hosts | awk '{ print $1 }')
oldIP=$(run show interfaces wireguard wg111 endpoints | awk '{ print $2 }' | awk -F ':' '{ print $1 }')

echo $newIP
echo $oldIP

if [ $newIP != $oldIP ]
        set interfaces wireguard wg111 peer location1 address $newIP


#Call local scripts