LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 07-19-2007, 04:31 AM   #1
TomG22
LQ Newbie
 
Registered: Aug 2005
Posts: 6

Rep: Reputation: 0
[2 internet connections] Combining load balancing and rule based routing


Hi folks,

I have a firewall/gateway setup with 2 DSL connections (using PPPoe).

As far as I know, there are 2 possibilities when someone wants to use both of them simultaneously (from behind a network, using NAT):
  • Load balancing: equalize outbounding connections
    syntax:
    Code:
    	ip route add default equalize scope global \
    		nexthop via <default gateway WAN1> dev <interface WAN1> weight 1 \
    		nexthop via <default gateway WAN2> dev <interface WAN2> weight 1
    Weight: the priority to prefer one link over another. The lower this factor, the more priority this WAN link gets. In this case, both WAN links are less or more equalize.
    Used routes are hold in the routing cache, based on the target ip adress. It means, if the cache isn't cleared regularly, targets will always use the same WAN link.
  • IP rule based routing: choose the WAN link based on source/target host, port and protocol,..
    For example, one could use WAN link A only for HTTP and SMTP+POP3, while using the second link for file transfers (like FTP).
    To achieve this, it's necessary to make a custom routing table for each link (can be setup in /etc/iproute2/rt_tables).
    For example:
    Code:
    1 WAN1_table
    2 WAN2_table
    By adding the default gateway of each WAN link to these defined routing tables, it's possible to route traffic based on some rules:
    Adding default gateway from each WAN link to the separate routing tables:
    Code:
    	ip route add default via <default gateway WAN1> dev <interface WAN1> table WAN1_table
    	ip route add default via <default gateway WAN2> dev <interface WAN2> table WAN2_table
    ... and finally, adding ip rule based routing:
    Code:
    	ip rule add fwmark 1 table WAN1_table
    	ip rule add fwmark 2 table WAN2_table
    In this example, I'll be using IPtables to mark packets based on some criteria (for example, destination address).
    Code:
    	iptables -t mangle -A PREROUTING -d <host a> -j MARK --set-mark 1
    	iptables -t mangle -A OUTPUT -d <host a> -j MARK --set-mark 1
    
    	iptables -t mangle -A PREROUTING -d <host b> -j MARK --set-mark 2
    	iptables -t mangle -A OUTPUT -d <host b> -j MARK --set-mark 2

Now, finally my question:

I want to combine both methods:
As seen above, it's possible to add default gateways from different WAN links to different routing tables.
Using these different WAN links, it's possible to use a WAN link (choosing witch routing table to lookup) based om some criteria.

Now, what I actually want to achieve:
  • 1 routing table for WAN1
  • 1 routing table for WAN2
  • ... and 1 routing table for the load balanced default gateway

This would it make possible, to decide if a client in the network has to use:
  • WAN link 1
  • WAN link 2
  • A load balanced route of WAN link 1 and 2

... and of course other criteria, like:
  • FTP needs to use both links in load balancing
  • HTTP and mail traffic must use WAN link 1
  • all other traffic must use WAN link 2

Actually, this seems to be impossible, because something like:

Code:
	ip route add default equalize scope global \
		nexthop via <default gateway WAN1> dev <interface WAN1> weight 1 \
		nexthop via <default gateway WAN2> dev <interface WAN2> weight 1
		table WAN_LB
... seems to be not possible (incorrect syntax).
Quote:
Error: "nexthop" or end of line is expected instead of "table"
Does someone has a sollution/idea to this problem?

Thanks in advance

Last edited by TomG22; 07-19-2007 at 04:39 AM.
 
Old 07-19-2007, 12:16 PM   #2
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
hi,

i've never tried using complex routing using linux,
but i do get your point in cisco's term -- you want to create both PBR and VRRP.
but from your diagram - you only have 1 router.
and, you need to do the policy-based routing after your VRRP properly configure.

sure you can do PBR with 1 router - but you dont have the option of doing balanced-gateway.

HTH.

Last edited by rossonieri#1; 07-19-2007 at 12:18 PM.
 
Old 07-20-2007, 03:28 AM   #3
TomG22
LQ Newbie
 
Registered: Aug 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Unfortunately, Cisco routers are really to expensive for home usage.

Actually, my setup works fine: the default route chosen is the latest one added with this script. So when the load balanced is the last one added, clients use it by default.
Exceptions can be made through ip rules (for example, client a must use ISP 1, client b ISP 2, and client c a load balanced route of ISP 1 and 2).

But: I just want to have the freedom to use 3 custom routing tables in stead of 2.

That would it make possible to choose the routing table based on the earlier mentioned criteria.
The default behavior would be: all clients, protocols, ports,... use ISP 1, all other exceptions to this default behavior can use ISP 2 or load balancing of both.

One thing I still can try: the load balanced route was added by default in the "main" route table (actually, tis is the default routing table, also used by the "route" command).
So what if I make routing rules for the main table?

Last edited by TomG22; 07-20-2007 at 03:32 AM.
 
Old 07-20-2007, 07:29 AM   #4
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
hi,

the idea of vrrp is that you create a virtual router with a virtual IP handling balanced-gateway - so that you can create a routing-table based on balanced-gateway.

i understand that your :
route A will be packet A and going to line A,
route B will be packet B and going to line B,
but then you need another route for both packet AB going line AB - right?

this thing cant be done in a single router and policy-based routing.

that is the function of VRRP - "another" virtual router which deliver your balanced traffic.

and you can do GLBP (gateway load balancing) which is an alternative to VRRP.

i think thats all for cisco'isme
you've got me interested in developing complex routing based on linux. thanks for the idea. nice one.

HTH.

Last edited by rossonieri#1; 07-20-2007 at 07:36 AM.
 
Old 05-18-2009, 04:50 PM   #5
reards
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
Lightbulb how to avoid Error: "nexthop" or end of line is expected instead of "table"

It's been a while since no-one posted on this topic, but...I've just found the solution to the initial problem mentioned here!
So, to TomG22:
You can add a "weighted" rule to a user-defined routing table, using the following syntax:

Code:
ip route add default scope global table MYTABLE nexthop via 10.0.1.1 dev eth3 weight 1 nexthop via 10.0.2.1 dev eth2 weight 1
So, basically the "table tblname" code must NOT be placed at the end of the command line.
This hint I've found at: http://mailman.ds9a.nl/pipermail/lar...q4/021875.html

Hope this helps!
Cheers
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
internet load balancing pankajkarde Linux - Server 2 04-07-2007 05:53 AM
Load balancing across two internet connections? mlg9000 Linux - Networking 3 03-14-2005 10:00 AM
Load Balancing 2 Internet Connections LinuxGeek Linux - Networking 3 01-16-2005 04:15 AM
Internet load balancing learsima Linux - Networking 2 07-27-2004 09:13 PM
Load Balancing for a Browser Based Application divorcingbill Linux - Networking 3 02-10-2003 03:06 AM


All times are GMT -5. The time now is 06:03 PM.

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