LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 02-18-2009, 12:37 PM   #1
MikeyCarter
Member
 
Registered: Feb 2003
Location: Orangeville
Distribution: Fedora
Posts: 440

Rep: Reputation: 31
Question Using Linux as a router and load balancer between two DSL WAN connections


I have a netgear dual wan router and yesterday the thing locked up and went back to factory defaults. I had a backup of the settings but rather scary when I realized it's a single point of failure that I have no control over, other to buy a new one.

In the process of looking for a new router I had an epiphany. I have a spare laptop, currently with Fedora 10 on it. I started to think, if I added two USB network cards why couldn't it do the same job as the netgear. It would also have the bonus of a built in UPS.

So here's what I want the setup to do.

I want to have two USB network cards connected to two DSL Modems. I want linux to load balance the traffic between the two connections so that an even load is on each interface. The second thing I need is a way to override that based on protocol, IP and/or session. That way VPN connections don't start bouncing between the interfaces. Not to mention the routers "virtual server" scenario for inbound connections.

Does anyone know a good HOWTO doc on accomplishing this task?
 
Old 02-18-2009, 02:55 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,344

Rep: Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945
in line with most of the results at the bottom of this page, lartc.org chapter 4.
 
Old 04-02-2009, 12:52 AM   #3
SiliconViper
LQ Newbie
 
Registered: Apr 2009
Posts: 4

Rep: Reputation: 1
While it doesn't cover the full list of things you're asking, this guide on setting up a dual wan system on Linux might provide a reasonable starting point.

Last edited by SiliconViper; 10-15-2010 at 07:26 PM. Reason: Fixed broken links.
 
Old 04-02-2009, 08:26 AM   #4
MikeyCarter
Member
 
Registered: Feb 2003
Location: Orangeville
Distribution: Fedora
Posts: 440

Original Poster
Rep: Reputation: 31
All of this was very helpful. I now have my server running with two PPPOE accounts and load balancing between them. (For torrents the highest speed I've seen is 958 kBytes/s.)

I even got creative and did the same for my eth0 and wan0 since NetworkManager activates both devices. Here's the main part:

Code:
########################################################
# Do a check for multiple routes on single Network
########################################################
DefaultRouteIP=$(/sbin/ip route | grep "default via" | awk {'print $3'});
DefaultRoute=$(/sbin/ip route | grep "default via" | awk {'print $5'});
DefaultMask=$(/sbin/ip route | grep "scope link" | grep "$DefaultRoute" | awk {'print $1'})
let TotalRoutes=$(/sbin/ip route | grep "scope link" | grep "$DefaultMask" | wc -l)

if [ $TotalRoutes -gt 1 -a "$DefaultRouteIP" != "" ] ; then
  echo "Found Routes: $TotalRoutes"  >> /var/log/cf_register.log
  BuildCMD="/sbin/ip route change default equalize scope global"
  for routeDev in $(/sbin/ip route | grep "scope link" | grep "$DefaultMask" | awk {'print $3'} | sort -u) ; do
    if [ "$(echo $routeDev | tr -d '[:digit:]')" == "wlan" ] ; then
      BuildCMD=$BuildCMD" nexthop via $DefaultRouteIP dev $routeDev weight 1";
    else
      BuildCMD=$BuildCMD" nexthop via $DefaultRouteIP dev $routeDev weight 2";
    fi
  done
  $BuildCMD;
  /sbin/ip route flush cache
fi

#############################################################
# Do a check for multiple ppp routes
# As in we have multiple dial in or pppoe accounts active
#############################################################
let TotalRoutes=$(/sbin/ip route | grep "scope link" | grep "ppp" | wc -l)

if [ $TotalRoutes -gt 1 ] ; then
  echo "Found Routes: $TotalRoutes"  >> /var/log/cf_register.log
  BuildCMD="/sbin/ip route change default equalize scope global"
  for routeDev in $(/sbin/ip route | grep "scope link" | grep "ppp" | awk -F"dev" {'print $2'} | awk {'print $1'} | sort -u) ; do
      BuildCMD=$BuildCMD" nexthop dev $routeDev weight 1";
  done
  $BuildCMD;
  /sbin/ip route flush cache
fi
I just inserted this code into the /etc/NetworkManager/dispatcher.d/ folder and it runs every time NetworkManager changes.

code in dispatcher.d:
Code:
#!/bin/bash

export LC_ALL=C

echo "Triggered: $(date) $*" 1>> /var/log/cf_register_nm.log 2>&1

if [ "$2" == "down" ]; then
     /usr/bin/cf_register.sh display 1>> /var/log/cf_register_nm.log 2>&1
fi

if [ "$2" == "up" ]; then
     /usr/bin/cf_register.sh display 1>> /var/log/cf_sendmail_nm.log 2>&1
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dual Wan Linux Router with Load Balancing & DHCP weirdaljr Linux - Networking 1 10-30-2008 09:54 PM
load balancer ? spx2 Linux - Networking 4 05-29-2007 02:00 AM
Am I able to establish a PPoE connections with my Cisco 2600 router to my dsl provide abefroman Linux - Networking 1 05-26-2007 12:26 AM
How do i load balance 3 WAN connections? touser Linux - Networking 4 09-05-2005 05:39 AM
Linux Router /w 2 DSL Connections adamantium Linux - Networking 1 01-14-2004 01:20 PM


All times are GMT -5. The time now is 08:19 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration