I’m in desperate need of a scripting God to help me with a script. I have six VDSL lines bridged to a RB1100AHx2 which does the PPPoE connections to the ISP (pppoe1, pppoe2, pppoe3, etc). I use PCC load balancing but my gateway IPs are dynamic and change whenever there is a disconnection and this can happen at any given time (due to power failures, reboots, ISP disconnects etc.). So I’m need of a script that will fetch the gateway ip of each of the connections and then apply the appropriate route in the /ip route list (XXX.XXX.XXX.XXX%pppoe1, etc). If anyone already has a similar script that he can share or can at least point me at the right direction, would be very much appreciated!
I’ve been trying to write the script myself but I ran into some problems
First this is the script I have
:global WAN1GatewayIP
:global WAN1LastGatewayIP #Grab current Gateway IP on WAN1
:global WAN1GatewayIP [ /ip address get [/ip address find interface=“pppoe-wan1” ] network ]
:if ([:typeof $WAN1LastGatewayIP ] = nil ) do={ :global WAN1LastGatewayIP “0” } #Check if Gateway IP has changed and apply rules
:if ($WAN1GatewayIP != $WAN1LastGatewayIP) do={
/ip route
remove [/ip route find comment=RuleWAN1-1]
remove [/ip route find comment=RuleWAN1-2]
add check-gateway=ping comment=RuleWAN1-1 distance=1 gateway=$WAN1GatewayIP%pppoe-wan1 routing-mark=to_WAN1
add check-gateway=ping comment=RuleWAN1-2 distance=1 gateway=$WAN1GatewayIP%pppoe-wan1
:global WAN1LastGatewayIP $WAN1GatewayIP
}
The idea is that I get the network ip of the interface, compare it with the previous value and if it is different then run the rest of the script in which I remove two rules (which I find having them commented) add the new ones and at the end renew the value of the LastGatewayIP so it has the latest value.
The thing is that if I run the first part of the script (#Grab current Gateway IP on WAN1) everything seems to be ok (or at least I think so, I get the variables and their respective values in the Environment tab). I added the second line (:if ([:typeof $WAN1LastGatewayIP ] = nil ) do={ :global WAN1LastGatewayIP “0” }) to make sure I get a value when I run the script for the fisrt time (remember I am not script savvy!)
When I run the whole thing (including the second part (#Check if Gateway IP has changed and apply rules)) nothing seems to happen, not even the values of the first part appear so I suppose the script breaks somewhere but I don’t know where.
Notes: pppoe-WAN1 is the name of my interface and RuleWAN1-1 and RuleWAN1-2 are the comments I added on the rules I want to be able to find
If pppoe-outX [name of pppoe dialer] is being dialed from the RB itself, then why you are trying to hardcode the gateway IP,
Just create Static Route with ‘ppoe-outX’ [name of pppoe dialer] as gateway.
The RB is dialing the pppoe, all ok till that point but load balancing seems to have problems. I’ve read (correct me if I’m mistaking) that if you want to do load balancing through the same gateway you have to have the routes’ gateways in the form of XXX.XXX.XXX.XXX%pppoe-wan1, XXX.XXX.XXX.XXX%pppoe-wan2 etc., where XXX.XXX.XXX.XXX is the gateway IP of each of the pppoe connections. My problem is that XXX.XXX.XXX.XXX is not static but changes from time to time (eg reboot) and not all connections share the same gateway each time (among 6 connections I might have 2 to 4 different gateway IPs so some connections always have the same gateway IP). If for example wan1, wan2 and wan5 share one gateway, wan3 and wan6 share another and wan5 has yet another gateway the routes should be in that form
where XXX.XXX.XXX.XXX, YYY.YYY.YYY.YYY and ZZZ.ZZZ.ZZZ.ZZZ are the gateway IPs of each connection
So what I’m trying to do is to automate the procedure of adding the gateway IP of each of the connections into the route’s gateway.