Quantcast
Channel: fixx.co.za » Networking
Viewing all articles
Browse latest Browse all 2

Updating a remote host (connect-to) value of an l2tp connection to a dynamic host on Mikrotik

$
0
0

Mikrotik is a very powerful router operating system with an excellent scripting mechanism for performing all kinds of tasks.

Recently I added a l2tp VPN between Cape Town and Johannesburg for one of my clients using two RB750 Series routers. One small problem though is that the Johannesburg branch (as well as Cape Town) are on ADSL connections with dynamic IP address which means every time their ADSL connections reset, so to would the public IP address.

How Mikrotik handles hostnames when making VPN (and many other) remote connections is by immediately resolving the IP address when the hostname is specified as the remote host for the connection. So when I initially created the client side (Cape Town) l2tp-client, the Mikrotik on that side would resolve the current IP of the Johannesburg branch and use that as the IP of the remote host, but as explained in the paragraph above, when the Johannesburg ADSL resets, it would be issued a new IP address by the ISP.

In order work around this little issue I found a nifty script on the scripting examples page of the Mikrotik wiki which guided me in the right direction. This script will run every 5 minutes on the Cape Town (client) router and will check if the currently resolved hostname for Johannesburg is the same as what is currently configured in the l2tp-client interface as the remote host, and if it does not match, it will then update the l2tp-client details with the currently resolved IP address.

Once the l2tp-client interface has been updated with the correct IP address, the l2tp-client interface automatically reconnects.

/ip dns cache flush
:local jhbIP [:resolve “jhbbranch.mydomain.co.za”];
:local currentIP [/interface l2tp-client get [/interface l2tp-client find name=l2tp-to-jhb] connect-to];

:if ($currentIP != $jhbIP) do={
/interface l2tp-client set connect-to=$jhbIP [/interface l2tp-client find name=l2tp-to-jhb];
/log info “The IP address of the Johannesburg Branch has changed, updating the l2tp connection”;
}


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images