Community discussions

MikroTik App
 
Frostbyte
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Mon Dec 25, 2017 1:42 am

RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Jan 02, 2019 4:53 pm

Greetings and happy new year!

My old scripts and schedulers used to have a lot of hard coded values, were limited to only two gateways, did not utilize functions and were fairly inconsistent.
After nearly two years of putting it off and the acquisition of my new toys, I finally found the time to sit and rewrite the entirety of the scripts that I use on a daily basis.

You can check them out here:
https://github.com/FrostbyteGR/RouterSCRIPTS

Tip: If you plan on using them yourself: make sure you peruse the README section, as it will save you a lot of time and pain, in the long run.
Last edited by Frostbyte on Wed Jan 02, 2019 9:34 pm, edited 1 time in total.
 
Frostbyte
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Mon Dec 25, 2017 1:42 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Jan 02, 2019 4:54 pm

Frequently Asked Questions:
< To be filled when there are questions >
Last edited by Frostbyte on Wed Oct 02, 2019 8:32 pm, edited 4 times in total.
 
paulavalencia
just joined
Posts: 1
Joined: Tue Jun 25, 2019 5:49 pm

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Tue Jun 25, 2019 6:38 pm

Hey, frostbyte

Don't know if I should be posting here since there are no other replies, but it says to do so in the Github, so here I am.

I keep getting errors saying my variables are empty or contain invalid values in every module. I even tested it with the same values you put in the example, only changing the IP address on WANGateways, but can't make it work. I mainly wanna test your failover script in place of another I have, but also liked the DNS one and would like to set it up as well.

Please, if you can help me on this issue. I'm running the 6.44.3 version, if that's relevant. Thank you in advance.
 
tedd77
newbie
Posts: 39
Joined: Sun Dec 18, 2011 5:05 pm

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Oct 02, 2019 3:01 am

I am facing the same challenge of @paulavalencia
Could anyone assist ?
 
Frostbyte
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Mon Dec 25, 2017 1:42 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Oct 02, 2019 6:00 pm

Hello,

Apologies for the late reply, due to my fairly busy daily schedule this one managed to slip under my radar.

This behavior occurs when the configuration file is saved with the UNIX (\n) instead of Windows (\r\n) EOL scheme.
I have rolled out an update (to the parser function) where it properly detects and adjusts the EOL sequence, which fixes the issue.

Thank you for reporting this to me and for your patience.
 
Tecleo
just joined
Posts: 1
Joined: Thu Oct 31, 2019 11:55 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Thu Oct 31, 2019 12:05 pm

Hi, please assist.
Irrespective of the values used I am getting the message:
"Provision][Error]: Gateways configuration for XXXXXXXXX does not have a corresponding default route.
[Provision][Error]: Gateways configuration for XXXXXXXX does not have a corresponding default route.
[Provision][Error]: The gateways configuration is invalid, please check the config file and try again.

****** Script output ********
[admin@MikroTik] > /import RouterSCRIPTS_Installer.rsc
[RouterSCRIPTS][Info]: Install finished. Assuming you have read through the supplied readme file, you may now remove any modules that you have no use for, then run:
$provision auto

Script file loaded and executed successfully
[admin@MikroTik] > $provision auto
[Provision][Info]: Provisioning all available modules.
[Provision][Info]: Provisioning gateways.
[Provision][Error]: Gateways configuration for Vodafone does not have a corresponding default route.
[Provision][Error]: Gateways configuration for Verizon does not have a corresponding default route.
[Provision][Error]: The gateways configuration is invalid, please check the config file and try again.
[Provision][Info]: Provisioning failover.
[Provision][Error]: The failover module depends on the gateway selector module, please provision it and try again.
[Provision][Info]: Provisioning dyndns.
[Provision][Info]: Provisioning resolver.
[Provision][Info]: Provisioning livestream.
[Provision][Error]: Completed with errors.
[admin@MikroTik] >
*******
 
Frostbyte
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Mon Dec 25, 2017 1:42 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Fri Nov 15, 2019 3:32 pm

The provisioning script is complaining because you haven't designated corresponding routes to the connections you have defined in your cfg file.

From the readme file:
WANGatewayPrefix: The comment prefix to use for identifying default gateway routes in the routing table

The value which follows this configuration variable, must be present as a comment (I personally prefer to prefix it but it doesn't matter), on the 0.0.0.0 routes of each gateway defined in the cfg file.
The corresponding routes are being matched/designated via their comment and gateway fields. Without the comment being in place, the script cannot guess which ones to utilize for it's functions.


An example (using values from the readme) cfg file of:
WANGateways=192.168.1.1,192.168.2.1
WANGatewayPrefix=Default route
Would require you to have two routes like these:
/ip route add comment="Default route blah blah" distance=1 gateway=192.168.1.1
/ip route add comment="Default route blah blah" distance=2 gateway=192.168.2.1
Regarding the distance: The allowed range is from 1 to 2. Because you have declared two gateways in the cfg file.
If you had declared three gateways in the cfg file, then it would've been from 1 to 3 and so on..
 
Nic8756
just joined
Posts: 3
Joined: Wed Apr 22, 2020 7:22 pm

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Apr 22, 2020 7:50 pm

Greetings and happy new year!

My old scripts and schedulers used to have a lot of hard coded values, were limited to only two gateways, did not utilize functions and were fairly inconsistent.
After nearly two years of putting it off and the acquisition of my new toys, I finally found the time to sit and rewrite the entirety of the scripts that I use on a daily basis.

You can check them out here:
https://github.com/FrostbyteGR/RouterSCRIPTS

Tip: If you plan on using them yourself: make sure you peruse the README section, as it will save you a lot of time and pain, in the long run.
Hi Frostbyte,
thank you for the script! is very interesting. I'm doing some experiments but I have a problem, I cannot make it work. How can the Failover script check the WAN reachability of the WAN target through the various secondary gateways if the current default route of the Mikrotik router is on the active gateway? I mean, if I try to ping the WAN target (e.g. 8.8.8.8) from the 2nd gateway interface the response is ICMP timeout even if the 2nd gateway has full Internet connectivity. The ICMP request does not go out on the 2nd gatewa interface, so the entire script assumes that the 2nd gw has not WAN connectivity. I have to do something with NAT? Actually I'm only masquerating with src nat to the two gateway interfaces

I have a routerboard with two ISP Internet connections.

Could you help me? thanks a lot,
Best Regards
 
Frostbyte
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Mon Dec 25, 2017 1:42 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Sat Apr 25, 2020 8:18 pm

How can the Failover script check the WAN reachability of the WAN target through the various secondary gateways if the current default route of the Mikrotik router is on the active gateway?

ping <WAN Target> count=<# of Attempts> interface=<WAN Interface>
The bold part in red is what forces the ping to actually go out from the proper WAN Interface, regardless of what the currently active gateway is.

I mean, if I try to ping the WAN target (e.g. 8.8.8.8) from the 2nd gateway interface the response is ICMP timeout even if the 2nd gateway has full Internet connectivity. The ICMP request does not go out on the 2nd gatewa interface, so the entire script assumes that the 2nd gw has not WAN connectivity. I have to do something with NAT? Actually I'm only masquerating with src nat to the two gateway interfaces

I have a routerboard with two ISP Internet connections.

In order to better understand where the problem lies, some additional information is required:
  • The contents of the *.cfg file you're trying to provision the device with.
  • The output of the following commands (in terminal) from the device:
    1. /ip address print detail
    2. /ip route print detail
    3. $provision auto
    4. $failover check
 
Nic8756
just joined
Posts: 3
Joined: Wed Apr 22, 2020 7:22 pm

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Apr 29, 2020 5:29 pm

How can the Failover script check the WAN reachability of the WAN target through the various secondary gateways if the current default route of the Mikrotik router is on the active gateway?

ping <WAN Target> count=<# of Attempts> interface=<WAN Interface>
The bold part in red is what forces the ping to actually go out from the proper WAN Interface, regardless of what the currently active gateway is.

I mean, if I try to ping the WAN target (e.g. 8.8.8.8) from the 2nd gateway interface the response is ICMP timeout even if the 2nd gateway has full Internet connectivity. The ICMP request does not go out on the 2nd gatewa interface, so the entire script assumes that the 2nd gw has not WAN connectivity. I have to do something with NAT? Actually I'm only masquerating with src nat to the two gateway interfaces

I have a routerboard with two ISP Internet connections.

In order to better understand where the problem lies, some additional information is required:
  • The contents of the *.cfg file you're trying to provision the device with.
  • The output of the following commands (in terminal) from the device:
    1. /ip address print detail
    2. /ip route print detail
    3. $provision auto
    4. $failover check
Dear Frostbyte, thank you for the reply. I'm not completely sure about function of the "interface=" option of the ping command. According to me this command option is used to recursively learn the IP address associated to the specified interface and than create a ping packet with source IP address the IP address of that interface. However this not means that the ping will exit from that interface, because if the destination address of the ping is not in a local network the router still looks at the actual default gateway to decide to which dest address send the packet and accordingly on which interface. But I'm not an expert about Mikrotik world, so I can mistake.

All of this to say that in my small lab your script seems not able to ping the target host from the 2nd path to verify the connectivity, so it can't switch to the 2nd ISP when the first fails. Could you please help me?

Thanks a lot!

I attach the output of your commands, also the ping command.

[admin@MikroTik] > /ip address print detail
Flags: X - disabled, I - invalid, D - dynamic
0 ;;; defconf
address=192.168.80.1/24 network=192.168.80.0 interface=bridge actual-interface=bridge

1 address=192.168.10.71/24 network=192.168.10.0 interface=ether1 actual-interface=ether1

2 address=192.168.88.2/24 network=192.168.88.0 interface=ether5 actual-interface=ether5


[admin@MikroTik] > /ip route print detail
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit
0 A S ;;; Default route
dst-address=0.0.0.0/0 gateway=192.168.10.1 gateway-status=192.168.10.1 reachable via ether1 distance=1 scope=30 target-scope=10

1 S ;;; Default route
dst-address=0.0.0.0/0 gateway=192.168.88.1 gateway-status=192.168.88.1 reachable via ether5 check-gateway=ping distance=4 scope=30 target-scope=10

2 ADC dst-address=192.168.10.0/24 pref-src=192.168.10.71 gateway=ether1 gateway-status=ether1 reachable distance=0 scope=10

3 ADC dst-address=192.168.80.0/24 pref-src=192.168.80.1 gateway=bridge gateway-status=bridge reachable distance=0 scope=10

4 ADC dst-address=192.168.88.0/24 pref-src=192.168.88.2 gateway=ether5 gateway-status=ether5 reachable distance=0 scope=10


[admin@MikroTik] > $provision auto
[Provision][Info]: Provisioning all available modules.
[Provision][Info]: Provisioning gateways.
[Provision][Info]: Provisioning failover.


[admin@MikroTik] > $failover check
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 56 57 12ms
sent=1 received=1 packet-loss=0% min-rtt=12ms avg-rtt=12ms max-rtt=12ms

SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 timeout
sent=1 received=0 packet-loss=100%


[admin@MikroTik] > ping 8.8.8.8 interface=ether5
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 timeout
2 8.8.8.8 timeout
3 8.8.8.8 timeout
4 8.8.8.8 timeout
5 8.8.8.8 timeout
 
Frostbyte
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Mon Dec 25, 2017 1:42 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Apr 29, 2020 8:34 pm

Dear Frostbyte, thank you for the reply. I'm not completely sure about function of the "interface=" option of the ping command. According to me this command option is used to recursively learn the IP address associated to the specified interface and than create a ping packet with source IP address the IP address of that interface. However this not means that the ping will exit from that interface, because if the destination address of the ping is not in a local network the router still looks at the actual default gateway to decide to which dest address send the packet and accordingly on which interface. But I'm not an expert about Mikrotik world, so I can mistake.

According to the documentation, the "interface" parameter applies a "Which interface to use" restriction to the command, so the ping is forced to exit from that interface. Since there is a route (0.0.0.0/0) to your target address (8.8.8.8 ) where it's gateway (192.168.88.1) belongs in the same subnet (192.168.88.0/24) that your interface (ether5) participates in, the ping should go through, otherwise it should fail. Once we get your setup working, you will be able to verify this yourself as well (by actually bringing down connections).

All of this to say that in my small lab your script seems not able to ping the target host from the 2nd path to verify the connectivity, so it can't switch to the 2nd ISP when the first fails. Could you please help me?

Thanks a lot!

I attach the output of your commands, also the ping command.

[admin@MikroTik] > /ip address print detail
Flags: X - disabled, I - invalid, D - dynamic
0 ;;; defconf
address=192.168.80.1/24 network=192.168.80.0 interface=bridge actual-interface=bridge

1 address=192.168.10.71/24 network=192.168.10.0 interface=ether1 actual-interface=ether1

2 address=192.168.88.2/24 network=192.168.88.0 interface=ether5 actual-interface=ether5


[admin@MikroTik] > /ip route print detail
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit
0 A S ;;; Default route
dst-address=0.0.0.0/0 gateway=192.168.10.1 gateway-status=192.168.10.1 reachable via ether1 distance=1 scope=30 target-scope=10

1 S ;;; Default route
dst-address=0.0.0.0/0 gateway=192.168.88.1 gateway-status=192.168.88.1 reachable via ether5 check-gateway=ping distance=4 scope=30 target-scope=10

2 ADC dst-address=192.168.10.0/24 pref-src=192.168.10.71 gateway=ether1 gateway-status=ether1 reachable distance=0 scope=10

3 ADC dst-address=192.168.80.0/24 pref-src=192.168.80.1 gateway=bridge gateway-status=bridge reachable distance=0 scope=10

4 ADC dst-address=192.168.88.0/24 pref-src=192.168.88.2 gateway=ether5 gateway-status=ether5 reachable distance=0 scope=10


[admin@MikroTik] > $provision auto
[Provision][Info]: Provisioning all available modules.
[Provision][Info]: Provisioning gateways.
[Provision][Info]: Provisioning failover.


[admin@MikroTik] > $failover check
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 56 57 12ms
sent=1 received=1 packet-loss=0% min-rtt=12ms avg-rtt=12ms max-rtt=12ms

SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 timeout
sent=1 received=0 packet-loss=100%


[admin@MikroTik] > ping 8.8.8.8 interface=ether5
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 timeout
2 8.8.8.8 timeout
3 8.8.8.8 timeout
4 8.8.8.8 timeout
5 8.8.8.8 timeout

This is a bit weird. On the surface there doesn't seem to be anything wrong with what the scripts are expecting to find. (That means that, concerning the scripts at least, the configuration should be valid).

However, I find two things which are alarming:
1) The provision command did not end with a success/failure message. (If you didn't crop it on purpose, something may have went wrong, which we will need to investigate)
2) Assuming your interface, address, route and firewall (since you mentioned you're NATing) configurations are proper; you should be able to ping with that last command. Something is definitely going on with the configuration of the device in general.

As a small experiment, could you try disabling the route #0 (dst-address=0.0.0.0/0 gateway=192.168.10.1) and try a ping to 8.8.8.8 without the interface parameter? Does it succeed?
 
Nic8756
just joined
Posts: 3
Joined: Wed Apr 22, 2020 7:22 pm

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Sat May 02, 2020 11:16 pm

Dear Frostbyte, thank you for the reply. I'm not completely sure about function of the "interface=" option of the ping command. According to me this command option is used to recursively learn the IP address associated to the specified interface and than create a ping packet with source IP address the IP address of that interface. However this not means that the ping will exit from that interface, because if the destination address of the ping is not in a local network the router still looks at the actual default gateway to decide to which dest address send the packet and accordingly on which interface. But I'm not an expert about Mikrotik world, so I can mistake.

According to the documentation, the "interface" parameter applies a "Which interface to use" restriction to the command, so the ping is forced to exit from that interface. Since there is a route (0.0.0.0/0) to your target address (8.8.8.8 ) where it's gateway (192.168.88.1) belongs in the same subnet (192.168.88.0/24) that your interface (ether5) participates in, the ping should go through, otherwise it should fail. Once we get your setup working, you will be able to verify this yourself as well (by actually bringing down connections).

All of this to say that in my small lab your script seems not able to ping the target host from the 2nd path to verify the connectivity, so it can't switch to the 2nd ISP when the first fails. Could you please help me?

Thanks a lot!

I attach the output of your commands, also the ping command.

[admin@MikroTik] > /ip address print detail
Flags: X - disabled, I - invalid, D - dynamic
0 ;;; defconf
address=192.168.80.1/24 network=192.168.80.0 interface=bridge actual-interface=bridge

1 address=192.168.10.71/24 network=192.168.10.0 interface=ether1 actual-interface=ether1

2 address=192.168.88.2/24 network=192.168.88.0 interface=ether5 actual-interface=ether5


[admin@MikroTik] > /ip route print detail
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit
0 A S ;;; Default route
dst-address=0.0.0.0/0 gateway=192.168.10.1 gateway-status=192.168.10.1 reachable via ether1 distance=1 scope=30 target-scope=10

1 S ;;; Default route
dst-address=0.0.0.0/0 gateway=192.168.88.1 gateway-status=192.168.88.1 reachable via ether5 check-gateway=ping distance=4 scope=30 target-scope=10

2 ADC dst-address=192.168.10.0/24 pref-src=192.168.10.71 gateway=ether1 gateway-status=ether1 reachable distance=0 scope=10

3 ADC dst-address=192.168.80.0/24 pref-src=192.168.80.1 gateway=bridge gateway-status=bridge reachable distance=0 scope=10

4 ADC dst-address=192.168.88.0/24 pref-src=192.168.88.2 gateway=ether5 gateway-status=ether5 reachable distance=0 scope=10


[admin@MikroTik] > $provision auto
[Provision][Info]: Provisioning all available modules.
[Provision][Info]: Provisioning gateways.
[Provision][Info]: Provisioning failover.


[admin@MikroTik] > $failover check
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 56 57 12ms
sent=1 received=1 packet-loss=0% min-rtt=12ms avg-rtt=12ms max-rtt=12ms

SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 timeout
sent=1 received=0 packet-loss=100%


[admin@MikroTik] > ping 8.8.8.8 interface=ether5
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 timeout
2 8.8.8.8 timeout
3 8.8.8.8 timeout
4 8.8.8.8 timeout
5 8.8.8.8 timeout

This is a bit weird. On the surface there doesn't seem to be anything wrong with what the scripts are expecting to find. (That means that, concerning the scripts at least, the configuration should be valid).

However, I find two things which are alarming:
1) The provision command did not end with a success/failure message. (If you didn't crop it on purpose, something may have went wrong, which we will need to investigate)
2) Assuming your interface, address, route and firewall (since you mentioned you're NATing) configurations are proper; you should be able to ping with that last command. Something is definitely going on with the configuration of the device in general.

As a small experiment, could you try disabling the route #0 (dst-address=0.0.0.0/0 gateway=192.168.10.1) and try a ping to 8.8.8.8 without the interface parameter? Does it succeed?
Hi Frostbyte, thank you again for your help and explanations. As soon as possible I'll do some tests and I let you know.
 
Frostbyte
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Mon Dec 25, 2017 1:42 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Fri May 15, 2020 10:12 am

Hi Frostbyte, thank you again for your help and explanations. As soon as possible I'll do some tests and I let you know.

It's been nearly two weeks since your last reply, are you still in need of assistance?
 
luddite
just joined
Posts: 21
Joined: Fri Apr 06, 2012 12:09 am

Re: RouterSCRIPTS - A collection of scripts for RouterBOARD devices

Wed Jun 03, 2020 11:59 am

Just want to say thanks for this amazing work, there is a lot in it, and a lot in your replies to people, good effort helping the community.

Hope to use and explore these scripts.

Who is online

Users browsing this forum: No registered users and 20 guests