Community discussions

MikroTik App
 
Woudanator
just joined
Topic Author
Posts: 7
Joined: Sat Feb 03, 2018 11:27 pm

Help with script to change SRC address in l2tp client

Fri May 28, 2021 11:17 am

Hi Guys

My scripting skills on Mikrotik is limited and need some assistance to, hope this is the right place for this if not please feel free to point me in the right direction
I have 2 l2tp tunnels that need to push over 2 different interfaces using 2 different public IP's to force them to go over the right routes i use the SRC address field to force
them to use that IP in that interface to get out and I have a dedicated route to each l2tp server route distance lower than that of default routes

These connect to a controller that manages the WAN connections and monitors if they up or down etc

This seems to work well sofar

My problem is that the 2 interfaces run DHCP so I need a script for DHCP that will change the SRC IP in the client when the IP changes
so that the l2tp clients can connect via the new addresses I cant do this from the controller unfortunately so I need to try do this via the dhcp-client script feature or the scheduler

Is there any easy way to script this and is it even possible and does anyone have a magic script for me to do this
 
Woudanator
just joined
Topic Author
Posts: 7
Joined: Sat Feb 03, 2018 11:27 pm

Re: Help with script to change SRC address in l2tp client  [SOLVED]

Fri May 28, 2021 1:25 pm

Hi Guys

so after some more work and figuring out the scripting language I have a solution that seems to work for me I am sure there are shorter ways of writing this but this is getting the job done


:global currentSrc1 [/interface l2tp-client get [find where name=ControllerLink-1] value=src-address ]
:global currentSrc2 [/interface l2tp-client get [find where name=ControllerLink-2] value=src-address ]
:global iface1 [/interface get [find where comment="WAN-1"] value=name ]
:global iface2 [/interface get [find where comment="WAN-2"] value=name]
:global dhcpIp1 [/ip address get [find where interface=$iface1] value=address]
:global dhcpIp2 [/ip address get [find where interface=$iface2] value=address]
:if ($currentSrc1 != [:pick $dhcpIp1 0 [:find $dhcpIp1 "/"]]) do={
   /interface l2tp-client set src-address= [:pick $dhcpIp1 0 [:find $dhcpIp1 "/"]] [find where name="ControllerLink-1"]
   :log info "IP for controller one session has changed"
}
:if ($currentSrc2 != [:pick $dhcpIp2 0 [:find $dhcpIp2 "/"]]) do={
  /interface l2tp-client set src-address= [:pick $dhcpIp2 0 [:find $dhcpIp2 "/"]] [find where name="ControllerLink-2"]
  :log info "IP for controller two session has changed"
}

Who is online

Users browsing this forum: Speedr and 20 guests