Jan 27, 2010

load balancing Huawei C261 ISP Speedy

Let's make load balancing internet with ISP and Huawei C261. Just follow this steps

Make sure that ISP is ready on eth0 and C261 on ppp0, you can check my previous posting  about how to setup ppp connection on ubuntu karmic 9.10. On this case the ISP gateway is 192.168.1.1 and ppp0 connection is assigned by dhcp server.


$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:1e:33:22:4b:08 
          inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21e:33ff:fe22:4b08/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20472 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24246 errors:0 dropped:0 overruns:0 carrier:1
          collisions:0 txqueuelen:1000
          RX bytes:14898826 (14.8 MB)  TX bytes:4689741 (4.6 MB)
          Interrupt:29



$ ifconfig ppp0
ppp0      Link encap:Point-to-Point Protocol 
          inet addr:10.10.8.107  P-t-P:10.17.4.12  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:3945 errors:5 dropped:0 overruns:0 frame:0
          TX packets:4302 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:2596124 (2.5 MB)  TX bytes:842762 (842.7 KB)



$ cat /etc/resolv.conf
# Generated by NetworkManager
# nameserver 208.67.222.222   => if you want to use openDNS
nameserver 192.168.1.1
nameserver 10.17.3.244


On list above NS of ISP is 192.168.1.1 and NS of ppp0 is 10.17.3.244. Now to make it simple, just create a new file loadbalance.sh, just like this :

$ vi loadbalance.sh

#!/bin/bash
RP0=`ip addr show ppp0 | grep inet | awk {'print $4'} | cut -d '/' -f1`
ET0=`ip addr show eth0 | grep global | awk {'print $2'} | cut -d '/' -f1 | cut -d '.' -f1,2,3`.1

sudo ip route replace default scope global nexthop via $ET0  dev eth0 weight 200 nexthop via $RP0  dev ppp0 weight 10

echo "------------- load Balanced  $ET0 => $RP0 "
ip route show
route -n


save it and change permission by running
chmod +x loadbalance.sh

now run the script with sudo privilege


$ sudo ./loadbalance.sh
------------- load Balanced  192.168.1.1 => 10.17.4.12
10.17.4.12 dev ppp0  proto kernel  scope link  src 10.10.8.107
10.42.43.0/24 dev wlan0  proto kernel  scope link  src 10.42.43.1  metric 2
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.3  metric 1
169.254.0.0/16 dev wlan0  scope link  metric 1000
default
    nexthop via 192.168.1.1  dev eth0 weight 200
    nexthop via 10.17.4.12  dev ppp0 weight 10
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.17.4.12      0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
10.42.43.0      0.0.0.0         255.255.255.0   U     2      0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlan0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0 


$ ping www.google.com
PING www.l.google.com (64.233.181.104) 56(84) bytes of data.
64 bytes from ni-in-f104.1e100.net (64.233.181.104): icmp_seq=1 ttl=53 time=89.1 ms
64 bytes from ni-in-f104.1e100.net (64.233.181.104): icmp_seq=2 ttl=53 time=276 ms
^C


okay just try it...  :)

.
Let's make load balancing internet with ISP and Huawei C261. Just follow this steps

Make sure that ISP is ready on eth0 and C261 on ppp0, you can check my previous posting  about how to setup ppp connection on ubuntu karmic 9.10. On this case the ISP gateway is 192.168.1.1 and ppp0 connection is assigned by dhcp server.


$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:1e:33:22:4b:08 
          inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21e:33ff:fe22:4b08/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20472 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24246 errors:0 dropped:0 overruns:0 carrier:1
          collisions:0 txqueuelen:1000
          RX bytes:14898826 (14.8 MB)  TX bytes:4689741 (4.6 MB)
          Interrupt:29



$ ifconfig ppp0
ppp0      Link encap:Point-to-Point Protocol 
          inet addr:10.10.8.107  P-t-P:10.17.4.12  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:3945 errors:5 dropped:0 overruns:0 frame:0
          TX packets:4302 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:2596124 (2.5 MB)  TX bytes:842762 (842.7 KB)



$ cat /etc/resolv.conf
# Generated by NetworkManager
# nameserver 208.67.222.222   => if you want to use openDNS
nameserver 192.168.1.1
nameserver 10.17.3.244


On list above NS of ISP is 192.168.1.1 and NS of ppp0 is 10.17.3.244. Now to make it simple, just create a new file loadbalance.sh, just like this :

$ vi loadbalance.sh

#!/bin/bash
RP0=`ip addr show ppp0 | grep inet | awk {'print $4'} | cut -d '/' -f1`
ET0=`ip addr show eth0 | grep global | awk {'print $2'} | cut -d '/' -f1 | cut -d '.' -f1,2,3`.1

sudo ip route replace default scope global nexthop via $ET0  dev eth0 weight 200 nexthop via $RP0  dev ppp0 weight 10

echo "------------- load Balanced  $ET0 => $RP0 "
ip route show
route -n


save it and change permission by running
chmod +x loadbalance.sh

now run the script with sudo privilege


$ sudo ./loadbalance.sh
------------- load Balanced  192.168.1.1 => 10.17.4.12
10.17.4.12 dev ppp0  proto kernel  scope link  src 10.10.8.107
10.42.43.0/24 dev wlan0  proto kernel  scope link  src 10.42.43.1  metric 2
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.3  metric 1
169.254.0.0/16 dev wlan0  scope link  metric 1000
default
    nexthop via 192.168.1.1  dev eth0 weight 200
    nexthop via 10.17.4.12  dev ppp0 weight 10
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.17.4.12      0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
10.42.43.0      0.0.0.0         255.255.255.0   U     2      0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlan0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0 


$ ping www.google.com
PING www.l.google.com (64.233.181.104) 56(84) bytes of data.
64 bytes from ni-in-f104.1e100.net (64.233.181.104): icmp_seq=1 ttl=53 time=89.1 ms
64 bytes from ni-in-f104.1e100.net (64.233.181.104): icmp_seq=2 ttl=53 time=276 ms
^C


okay just try it...  :)

3 comments:

  1. Hello! Thank you for the script, with ping it work well, but how can i use it in wget or in any download manager?
    With wget i'm able to use only one connection and not both!

    Any tips?

    ReplyDelete
  2. i doubt that wget implement such mechanism of connections. As i know, i just make change in global routing, and its work in transport layer while wget (and other downloader) should be on application layers. I think it will no problem.

    maybe you need to change the scope, or make exception of application (data packets from specific applications) must be run on defined lines.

    i think "route scope" or "iptables" as well.

    ReplyDelete
  3. hw do i ensure that load balancer runs only when both interfaces are up? if i plug out one, the other connection fails as well

    ReplyDelete