27.5.10

Using a dynamic dns name for a VPN server

The short of it

I’ve had a few times where I’ve wanted to make a secure tunnel between 2 locations but have only had connections with dynamic IP addresses to work with.
Sure it’s easy enough to setup a dynamic dns script for each router, but how about getting one to connect back to the other on its new IP address?
This little script can be used for just that.
:local "vpn-interface-name" "pptp-interface"
:local "vpn-dns-name" "your_dynamic_address"
:local "new-vpn-ip" [:resolve $"vpn-dns-name"]
:local "current-vpn-ip" [/interface pptp-client get $"vpn-interface-name" connect-to]
:if ($"current-vpn-ip" != $"new-vpn-ip") do={ /interface pptp-client set [find name=$"vpn-interface-name"] connect-to=$"new-vpn-ip"}

How it works

Firstly you need to
1. Create this as a new script, name it and setup a scheduler entry for how often you want it to run. I find 10 minutes works fine for me.
2. Change the variables in the script to suit (your_dynamic_address = the dns name for the remote router, pptp-interface = your pptp client interface name)

Thoughts

This sort of script works for more than just a pptp connection.
The same idea can be applied to EoIP tunnels, IPSec tunnels, etc etc.
The script will then check if the current IP for the dns name matches up with the IP you have set on the pptp client interface.
If it does match the script stops without doing anything (leaving the pptp connection intact)
If it does not match the script will update the interface to connect to the new IP address.

zte c300 trunk mode

  gpon   profile tcont PPPOE type 4 maximum 9900000   profile tcont 100M type 4 maximum 100000   profile tcont 50M-TRUNK type 4 maximum 5000...