LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 11-06-2008, 08:53 AM   #1
vaibhavs
Member
 
Registered: Jun 2008
Posts: 113

Rep: Reputation: 15
IPTables : Source IP based Gateway Route


Hi,

I have an FC9 server as a gateway server with Squid + Dansguardian.
I have 10 Desktop PCs & 2 ISPs.
I want 5 PCs to access the net via ISP-1 & other 5 PCs via ISP-2.

I believe this can be done via IPTables.

I do not understand much of IPTables.
I seek help from forum members who can give me the rules which will help me route desktop traffic based on the IP address of the Desktops PCS.

I need rule like:
Source IP = 192.168.1.11 -> Gateway = 192.168.1.1
Source IP = 192.168.1.12 -> Gateway = 192.168.1.1
Source IP = 192.168.1.13 -> Gateway = 192.168.1.2
etc

Thank you in advance.

regards,
Vai
 
Old 11-06-2008, 11:00 AM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
To do this you need to use the iproute2 programs.

Set up a table for each different gateway in /etc/iproute2/rt_tables
example rt_tables:
Code:
#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
10      gw1
11      gw2
Then you need to add a default route to each table:
ip route add default via 192.168.1.1 table gw1
ip route add default via 192.168.1.2 table gw2

Then you need to do routing rules like:
ip rule add from 192.168.1.11 table gw1
ip rule add from 192.168.1.12 table gw1
ip rule add from 192.168.1.13 table gw2

You should make sure to have an overall default route added via normal route command or interface setup. It's needed because the default route added to a table only apply to packets routed through that table.

Last edited by estabroo; 11-06-2008 at 11:02 AM. Reason: too many overalls and not enough jeans
 
Old 11-06-2008, 12:34 PM   #3
nkd
Member
 
Registered: Oct 2006
Location: india
Distribution: fedora 8, ubuntu 10.10
Posts: 318

Rep: Reputation: 34
that is only going to take care of a static situation....what if one of your internet link goes down The corresponding hosts are all going to remain disconnected !

Maybe you should consider failover mechanism and write a script to use iptables to mark packets and then do routing as per that. Within the script keep checking both the interfaces regularly, say every 10 secs or so and if any internet interface goes down route the packets from it's src ip hosts through the other internet gw.

nishith
 
Old 11-06-2008, 12:58 PM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Its actually a pretty flexible solution because to reroute all the traffic from one gateway to the other you only need to change the default route for the table that needs to be moved, you don't have to redo all the individual rules.
 
Old 11-06-2008, 01:36 PM   #5
nkd
Member
 
Registered: Oct 2006
Location: india
Distribution: fedora 8, ubuntu 10.10
Posts: 318

Rep: Reputation: 34
right ... but you got to do that manually or would you recommend a script to do that ?
 
Old 11-06-2008, 01:40 PM   #6
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
A script or a daemon would be fine, I'm guessing that for this particular instance it doesn't matter, that the routes both go out the same internet connection, one just happens to be filtered through the squid+dan's guardian and the other isn't.
 
Old 11-06-2008, 11:20 PM   #7
vaibhavs
Member
 
Registered: Jun 2008
Posts: 113

Original Poster
Rep: Reputation: 15
Thx for all the inputs and suggestions.
I need to split the users over 2 ISP for Load Balancing.
If all user move thru single ISP, the b/w per user is low and the other ISP is idle.

I will ceate a PHP script which will route users thru the other gateway when the original ISP is down.
A simple browser based script which will execute IPTables command.
I am more of a PHP guy, little knowledge of Shell Scripts or IPTables.

I would really appreciate if someone can help me with the IPTables part.

I have 1 ethernet only. So the IP packets have to be tagged as to which gateway to use based on their source address.
All help is deeply appreciated!

Thx
Vai
 
Old 11-10-2008, 12:36 PM   #8
vaibhavs
Member
 
Registered: Jun 2008
Posts: 113

Original Poster
Rep: Reputation: 15
Hi,

Can anyone do this setup for me on paid basis.
I need this setup on my server.

Thx
Vai
 
  


Reply



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
can I setup a personal route through a server to a gateway using iptables wastingtime Linux - Networking 1 04-20-2008 07:41 PM
Gateway and route configuration veeruk101 Linux - Networking 1 07-25-2007 07:30 AM
Linux based gateway for time-based wireless service. TotalDefiance Linux - Software 0 10-03-2005 06:06 PM
My gateway can't route michaelsanford Linux - Networking 0 04-20-2005 05:05 PM
default route without a gateway scylla Linux - Networking 1 10-21-2004 01:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:26 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration