Author Topic: Tech Guru's Traffic Splitter  (Read 12505 times)

Offline alt21

  • Administrator
  • Newbie
  • *****
  • Posts: 22
    • View Profile
Tech Guru's Traffic Splitter
« on: September 25, 2011, 04:53:34 pm »
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.


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


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.


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


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


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


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.


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.



Thanks to:
http://locality.co.za/ for the local IP ranges
Vlad for creating this site and the code to change the IP Ranges into usable ROS commands
« Last Edit: September 27, 2011, 10:30:26 pm by alt21 »

Offline alt21

  • Administrator
  • Newbie
  • *****
  • Posts: 22
    • View Profile
Re: Tech Guru's Traffic Splitter
« Reply #1 on: September 26, 2011, 09:25:08 am »
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: [Select]
/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"
« Last Edit: September 27, 2011, 10:30:54 pm by alt21 »

Offline alt21

  • Administrator
  • Newbie
  • *****
  • Posts: 22
    • View Profile
Re: Tech Guru's Traffic Splitter
« Reply #2 on: September 26, 2011, 09:27:34 am »
The Complete Splitter.rsc Script

Code: [Select]
/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
« Last Edit: September 27, 2011, 10:31:21 pm by alt21 »

Offline alt21

  • Administrator
  • Newbie
  • *****
  • Posts: 22
    • View Profile
Re: Tech Guru's Traffic Splitter
« Reply #3 on: September 26, 2011, 10:23:09 am »
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.



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

Code: [Select]
/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.


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.

« Last Edit: September 27, 2011, 10:31:47 pm by alt21 »

Offline alt21

  • Administrator
  • Newbie
  • *****
  • Posts: 22
    • View Profile
Re: Tech Guru's Traffic Splitter
« Reply #4 on: September 27, 2011, 11:04:27 pm »
Reserved for later use

Offline georg

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Tech Guru's Traffic Splitter
« Reply #5 on: August 11, 2013, 06:31:13 pm »
Hi

Thank you very much for the script, works like a charm.
Would you please share the php code, i would like to change the interface name to suit naming convention on my system.


Thanks
Georg