Mikrotik RouterBOARD Traffic Splitter Script (Split Local and International Traffic)

alt21

Senior Member
Joined
Apr 4, 2008
Messages
765
Reaction score
3
Location
On a Chicken Farm
Tech Guru's Forum Page

Step by Step Guide for new RouterBOARD Installation

Download Splitter.rsc before continuing. This script assumes you have your ADSL Router connected to ether1 and your network is connected to ether2. The default IP for the Router would be 192.168.88.1 and the DHCP Range is 192.168.88.10 - 192.168.88.250

Step 1
Open Winbox and scan for connected devices. Find your device in the list and click on the MAC Address.
Step01a.jpg


The default username is admin with no password, click connect once you have entered the username.
Step01b.jpg


Step 2
The first time you connect to your RouterBOARD it will give you an option to remove the current configuration, click remove so we can start with a completely blank Router.
Step02.jpg


Optional Step if "Remove Configuration" window did not appear
If you did not receive the option to remove the default configuration open a New Terminal Window, type "system reset-configuration" (or just type sys <tab> reset <tab> to autocomplete the command) and press enter. The unit will reboot after the reset, once the unit has rebooted go back to Step 2
Optional1.jpg


Step 3
Open the Files Window then drag and drop the Splitter.rsc file from your PC.
Step03.jpg


Step 4
Open a New Terminal Window and type import Splitter.rsc (or im <tab> S <tab> to autocomplete the command)
Step04.jpg


Step 5
Open Interfaces, open ppp-international, Dial Out and enter your international accounts username and password. Once done do the same for ppp-local using your local accounts username and password.
Step05.jpg


Step 6
The route script will run every day at 5am to get new local routes, you can force the first run by clicking on System, Scrips, Splitter and Run Script. Check the RouterBOARD log for any errors.
Step06.jpg
 
Last edited:
The Scheduler and Route Download Script to be used on an existing RB Configuration

If you have an existing RouterBOARD configuration all you would need is to create a PPPoE interface called "ppp-local" using your second local only account and then run the following code in a new terminal to add the script and a scheduled task to download the routes once a day.

Code:
/system scheduler
add disabled=no interval=1d name="Splitter - Daily" on-event="/system script run Splitter" policy=reboot,read,write,test start-date=jan/01/1970 start-time=05:00:00
/system script
add name=Splitter policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source="# Define User Variables ( Accepted Values \"yes\" / \"no\" )\r\
    \n:global mark \"no\"\r\
    \n:global disabled \"no\"\r\
    \n\r\
    \n# Check if PPPoE Local Interface Exists\r\
    \n:if ([/interface find name=ppp-local] = \"\") do={\r\
    \n:log error \"ppp-local Interface doesn't exist.\";\r\
    \n:error;\r\
    \n}\r\
    \n\r\
    \n# Fetch Routes\r\
    \n/tool fetch url=\"http://www.techgurus.co.za/routes.php\?mark=\$mark&disabled=\$disabled\" dst-path=routes.rsc\r\
    \n\r\
    \n# Remove Old Local Routes\r\
    \n/ip route remove [/ip route find comment=\"Local Route\" ]\r\
    \n\r\
    \n# Import Local Routes\r\
    \nimport routes.rsc\r\
    \n"


The Complete Splitter.rsc Script

Code:
/ip pool
add name=dhcp_1 ranges=192.168.88.10-192.168.88.250
/ip dhcp-server
add address-pool=dhcp_1 disabled=no interface=ether2 lease-time=3d name=dhcp_1
/interface pppoe-client
add add-default-route=no disabled=no interface=ether1 name=ppp-international
add add-default-route=no disabled=no interface=ether1 name=ppp-local
/ip address
add address=192.168.88.1/24 disabled=no interface=ether2 network=192.168.88.0
/ip dhcp-server config
set store-leases-disk=5m
/ip dhcp-server network
add address=192.168.88.0/24 dns-server=192.168.88.1 gateway=192.168.88.1
/ip dns
set allow-remote-requests=yes servers=168.210.2.2
/ip firewall nat
add action=masquerade chain=srcnat disabled=no
/ip route
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ppp-international scope=30 target-scope=10
/system clock
set time-zone-name=Africa/Johannesburg
/system identity
set name="Tech Guru's Splitter"
/system ntp client
set enabled=yes mode=unicast primary-ntp=207.46.197.32 secondary-ntp=0.0.0.0
/system scheduler
add disabled=no interval=1d name="Splitter - Daily" on-event="/system script run Splitter" policy=reboot,read,write,test start-date=jan/01/1970 start-time=05:00:00
/system script
add name=Splitter policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source="# Define User Variables ( Accepted Values \"yes\" / \"no\" )\r\
    \n:global mark \"no\"\r\
    \n:global disabled \"no\"\r\
    \n\r\
    \n# Check if PPPoE Local Interface Exists\r\
    \n:if ([/interface find name=ppp-local] = \"\") do={\r\
    \n:log error \"ppp-local Interface doesn't exist.\";\r\
    \n:error;\r\
    \n}\r\
    \n\r\
    \n# Fetch Routes\r\
    \n/tool fetch url=\"http://www.techgurus.co.za/routes.php\?mark=\$mark&disabled=\$disabled\" dst-path=routes.rsc\r\
    \n\r\
    \n# Remove Old Local Routes\r\
    \n/ip route remove [/ip route find comment=\"Local Route\" ]\r\
    \n\r\
    \n# Import Local Routes\r\
    \nimport routes.rsc\r\
    \n"
/tool graphing interface
add allow-address=0.0.0.0/0 disabled=no interface=ppp-international store-on-disk=yes
add allow-address=0.0.0.0/0 disabled=no interface=ppp-local store-on-disk=yes


Splitter Script Options

You have two options that can be set in the Splitter Script once installed on your RouterBOARD

Mark= Yes / No
Disabled = Yes / No

Mark adds a Routing Mark to each Route which allows you to manage which traffic should go over the local PPPoE instead of splitting all traffic over local and international.

Disabled adds the Route as a disabled route, this would be used if you run the script manually connecting remotely via the international interface. This option will prevent you from being disconnected when working remotely.

Optional2.jpg


When using the Mark option you would have to add the following mangle rule via New Terminal

Code:
/ip firewall mangle add action=mark-routing chain=prerouting disabled=no in-interface=ether2 new-routing-mark=local passthrough=no

Once this rules is added you can add the tcp ports to the mangle rule for traffic you would like to mark as local.

Click on IP, Firewall, Mangle then double click on the mangle rule to open it.
Optional3a.jpg


In the mangle rule select protocol as tcp and in destination port you can add all the ports you would like to have marked. Ports are seperated by a , with no spaces.
Optional3b.jpg
 
Last edited:
Well done!

I've never managed to script the automatic importing of the routes due to MikroTik not being able to handle more than 4kB at a time, but since you're just importing a script and not iterating through a file containing the routes, you've managed to do it :D

I would rather recommend that the people leave out the Protocol & Dst. Port in the last image, so that they split the traffic of EVERYTHING, including games and torrents.
 
Well done!

I've never managed to script the automatic importing of the routes due to MikroTik not being able to handle more than 4kB at a time, but since you're just importing a script and not iterating through a file containing the routes, you've managed to do it :D

I would rather recommend that the people leave out the Protocol & Dst. Port in the last image, so that they split the traffic of EVERYTHING, including games and torrents.

The last part is optional as I use it in a corporate environment and sometimes I need the option to split only some of the traffic, for most home users you would not need it but it is there if you do :)

We are also working on a page that will allow the user to enter their IP Range / Ethernet ports that they have their ADSL / Network connected to so the script will be generated with their settings and not the static settings it has now.
 
Top
Sign up to the MyBroadband newsletter
X