LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-07-2014, 12:18 PM   #1
arpioni
LQ Newbie
 
Registered: Nov 2014
Posts: 2

Rep: Reputation: Disabled
Question Route to different NICs based on source


Hello,
I would like to route internet traffic based on source IP to different NICs. All traffic comes in on eth0 and then rerouting to eth1 or eth2

source IP 10.0.0.100 uses eth1
source IP 10.0.0.200 uses eth2

I've tried added the following to the nat IPtable, but no luck:

iptables -t nat -A POSTROUTING -s 10.0.0.100 -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.0.0.200 -o eth2 -j MASQUERADE

I'm curious do I need to chang the iptable for FORWARD ?

Thanks for your help

Last edited by arpioni; 11-07-2014 at 12:46 PM.
 
Old 11-07-2014, 02:09 PM   #2
ember1205
Member
 
Registered: Oct 2014
Posts: 176

Rep: Reputation: 16
What's the use case for this? What are you trying to accomplish?
 
Old 11-07-2014, 02:27 PM   #3
arpioni
LQ Newbie
 
Registered: Nov 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
I figured this out, using custom route tables instead. So for future reference.

Create a custom route table: echo 2000 CustomTable >> /etc/iproute2/rt_tables
Add rule: ip rule add from 10.0.0.100 lookup CustomTable
Add route: ip route add default via 10.0.0.254 dev eth1 table CustomTable

This will send any traffic from 10.0.0.100 out on dev eth1

Keep in mind these settings will be lost on reboot or restart of the network services.
 
Old 11-07-2014, 02:29 PM   #4
ember1205
Member
 
Registered: Oct 2014
Posts: 176

Rep: Reputation: 16
Ah... I wasn't understanding that you were looking to route packets that were sourced on the machine.

If you put those commands in a script and set it for execute on startup as part of the networking script or similar, you'll maintain the functionality across reboots.
 
  


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
Duel NICs default route ciscoguru Linux - Networking 6 06-14-2011 12:53 PM
using route tool to forward traffic between two nics dave247 Linux - Networking 4 05-11-2011 09:37 AM
IPTables : Source IP based Gateway Route vaibhavs Linux - Software 7 11-10-2008 12:36 PM
Using two nics, need default route? pridefc Linux - Networking 5 03-12-2007 10:35 PM
route any traffic between two NICs thirumala Linux - Networking 0 03-24-2004 05:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:20 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