New application to split local and international traffic - now on Telkom Router

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,171
Seems like no one has done this for the D-Link DSL-2500U yet.

Here's how to do it:
The telnet login will be prompted with "Login:" and "Password:"
To view the routing table, you can use the command: route show
To list the network interfaces, you can use the command: ifconfig
The PPPoE connections would be named like follow: ppp_0_8_35_#, eg. ppp_0_8_35_1 and ppp_0_8_35_2
To add routes you'll run something like: route add <IP address> <Subnet Mask> <Interface Name>, eg. route add 196.26.0.0 255.255.0.0 ppp_0_8_35_2​

To test, I've added routes for the 196.25.0.0/16 and 196.26.0.0/16 just to demonstrate.
My router's routing table:
Code:
> route show

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
41.240.64.1     *               255.255.255.255 UH    0      0        0 ppp_0_8_35_2
41.132.44.1     *               255.255.255.255 UH    0      0        0 ppp_0_8_35_1
192.168.89.0    *               255.255.255.0   U     0      0        0 br0
196.25.0.0      *               255.255.0.0     U     1      0        0 ppp_0_8_35_1
196.26.0.0      *               255.255.0.0     U     1      0        0 ppp_0_8_35_2
192.168.0.0     192.168.89.254  255.255.0.0     UG    1      0        0 br0
default         41.240.64.1     0.0.0.0         UG    0      0        0 ppp_0_8_35_2
The results (See the 3rd hop is different: with the 1 using my Mweb account (ppp_0_8_35_1) and the 2nd one using my Telkom account (ppp_0_8_35_2) :) ):
Code:
>tracert 196.25.1.11

Tracing route to wblv-ip-dns-3.saix.net [196.25.1.11]
over a maximum of 30 hops:

  1     6 ms     2 ms     2 ms  rb750.tuis [192.168.90.1]
  2     3 ms     2 ms     6 ms  d-link-adsl-router.tuis [192.168.89.1]
  3    28 ms    25 ms    28 ms  41-132-44-1.dsl.mweb.co.za [41.132.44.1]
  4    49 ms    48 ms    49 ms  tengig-0-0-0-101.vic-ipc-1.mweb.co.za [196.22.169.134]

>tracert 196.26.1.11

Tracing route to pc11.196-26-1.is.co.za [196.26.1.11]
over a maximum of 30 hops:

  1     2 ms     2 ms     3 ms  rb750.tuis [192.168.90.1]
  2     3 ms     2 ms     2 ms  d-link-adsl-router.tuis [192.168.89.1]
  3    28 ms    29 ms    25 ms  dsl-240-64-01.telkomadsl.co.za [41.240.64.1]
  4    30 ms    27 ms    30 ms  wblv-ip-lir-1-gig-4-0-0.telkom-ipnet.co.za [196.43.8.190]
Now someone has to modify the script :D
 
Last edited:

MiY4Gi

Expert Member
Joined
Dec 4, 2010
Messages
1,105
I just discovered that my Telkom Mega 105WR Router supports static routing and multiple pppoe accounts, so I wanna try setting up static routing for local only and international only accounts.

Now, I'm a noob when it comes to static routing so I got a few questions.

From the routing table above please explain what the following represents:


Destination (I assume this is the IP for the website you wanna visit)

Gateway (I assume this is your adsl accounts IP address)

Genmask (I think this is the subnet mask, but I'm not sure how subnet masks work, other than that it represents a period of many IP's.)

* (I assume this is a wildcard representing all gateways/adsl accounts)

255.255.255.255 (What does this represent?)

255.255.255.0 (And this?)

255.255.0.0 (And this?)

255.0.0.0 (And this?)

0.0.0.0 (I assume this is also like a wild card representing all subnet masks.)

What's the difference between 255.255.255.255 and 0.0.0.0.

If I want to route traffic to 196.0.0.12, through the gateway 42.1.1.1, how would I set up my routing table?

And if I want to route all traffic to the IP's in 196.0.0.0 - 196.255.255.255, through gateway 42.1.1.1, then how would I set up my routing table?
 

RSkeens

Expert Member
Joined
Jan 5, 2007
Messages
1,647
Now someone has to modify the script :D
I the included the modified script below. Just to confirm this is for the D - Link 2500U:

Code:
#!/bin/sh
#Your router's IP address, adjust the following line accordingly
host="ipaddress"
#If your router's login user is not admin, adjust the following line accordingly
user="admin"
#In the line below, replace with your router login password:
passwd="password"
#Your router's local interface, adjust the following line accordingly
if="interfacename"
# Download new list of local routes
wget "http://developers.locality.co.za/routes-rs.txt" -O localroutes.txt
modify()
{
while read i s
do
if [ "$i" != "#" ]; then
echo send \"route add `echo $i | sed 's/,/ /'` $if \\\\r\" >> localrouter.sh
echo expect \"# \" >> localrouter.sh
fi
done < localroutes.txt
}
echo "#!/usr/bin/expect --" > localrouter.sh
# Perform login
cat >> localrouter.sh << EOF
spawn telnet
expect "telnet>"
send "open $host\r"
expect "ogin: "
send "$user\r"
expect "word: "
send "$passwd\r"
EOF
# Add routes
modify
# Exit
cat >> localrouter.sh << EOF
send "exit\r"
send "!\r"
expect "$ "
EOF
# Make localrouter.sh executable
chmod a+x localrouter.sh
# Execute script
./localrouter.sh
 

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,171
Destination = the lower end of the destination IP range
Gateway = the gateway/router/end-point that you're using for the next hop
Genmask = just the subnet mask, which is used in combination with the Destination field to compute the destination IP range

255.255.255.255 = 256 ^ 0 host
255.255.255.0 = 256 ^ 1 hosts
255.255.0.0 = 256 ^ 2 hosts
255.0.0.0 = 256 ^ 3 hosts
0.0.0.0 = 256 ^ 4 hosts

See http://oav.net/mirrors/cidr.html for the conversion between CIDR / Subnet Mask / Binary netmask.

So to check if the IP address falls within the route, use the following operation:
IP address to check AND Genmask == Destination
If IP address to check AND Genmask != Destination, then it isn't in the IP range. Also, to ensure that the Destination is correct, it should be: Destination AND Genmask == Destination

For the equations above, you have to convert the Subnet mask (Genmask), Destination & IP address to check into integer values, OR you can do that operation separately for each 4 segments of the IP address.
eg. IP address to check = 10.0.0.100, Destination = 10.0.0.0, Subnet mask = 255.255.255.0
Calculation (First row = IP to check, 2nd row = Subnet Mask, and if the last row = Destination, then the IP falls in the Destination IP range):
10 AND 255 = 10
0 AND 255 = 0
0 AND 255 = 0
100 AND 0 = 0
^ So as you can see that IP address to check falls in the Destination IP range.

I'm not going to explain anything more than this, because if you don't understand this, then you just have to go and Google for IP Routing yourself.
 

MiY4Gi

Expert Member
Joined
Dec 4, 2010
Messages
1,105
Oh, so Destination is a range, and Genmask helps to specify that range.

That bit about the testing operation is rather gibberish to me.

Damn, I had no idea routing tables were so complicated.

Google Google Google
 

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,171
Once you understand the mathematical concept of the subnet mask AND that smaller subnets have priority over larger subnets, then routing tables are quite simple.
However, it gets a whole new dimension when you're working with multiple routing tables and routing table rules :p
 

MiY4Gi

Expert Member
Joined
Dec 4, 2010
Messages
1,105
You didn't tell me in what program I must use the operation. Is it in Excel, Matlab, CMD, on in the router? Or do I perform the operation in my head? I'll do more research later. Got things to do at the moment.
 

wikus

Senior Member
Joined
Feb 24, 2008
Messages
822
The script doesn't work for me on my DLink DSL-2500U.

I had to manually add a few routes at a time in telnet.

Is anyone else having any luck with this script and the same router, or am I just doing something wrong?
 

RSkeens

Expert Member
Joined
Jan 5, 2007
Messages
1,647
Top