Skip to content

Update IP on Wireguard tunnel point-to-point with both dynamic public IP addresses

License

Notifications You must be signed in to change notification settings

lfanton/Mikrotik-Scripts

Repository files navigation

wireguard-peer-update

This script allows to automatically update the public IP router address in a site-to-site Wireguard VPN when both routers have a dynamic public IP address and one of the two changes (tipically after a reboot).
It can be used by creating a netwatch on both routers...

Below the explenation:

xxxxxxxx.sn.mynetname.net is the hostname of the remote router (You can enable it on /ip/cloud/ddns...);
wgX is the name of the wireguard tunnel interface, generally it's called wg0, in this example it's also the interface comment;
wgXold and wgXnew it's the respective variable with the old and new ip address;
x.x.x.x is the remote wireguard IP address, for example 172.17.0.2;

  
/tool/netwatch
add down-script=":global wgXnew [:resolve xxxxxxxx.sn.mynetname.net]
    #:global wgXold [/interface wireguard peers get [find comment=\"wgX\"] endpoint-address ]
    :global wgXold [/interface wireguard peers get value-name=endpoint-address [find interface=\"wgX\"]]
    
    :if (\$wgXold != \$wgXnew) do={
    /interface wireguard peers set endpoint-address=\"\$wgXnew\" [find interface=\"wgX\"]
    /log info \"Wireguard wgX ip updated\";
    }" host=x.x.x.x interval=2m
  

jumpcloud-radius-updateip

This script allows to automatically update the public IP via API to RADIUS Login system from JumpCloud(TM) service on Mikrotik(TM) RouterOS(TM).
Also, If you nead, it can send an e-mail with the new Public IP ...

About

Update IP on Wireguard tunnel point-to-point with both dynamic public IP addresses

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published