Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-13-2009, 07:46 PM   #1
LQ Newbie
Registered: Oct 2007
Posts: 1

Rep: Reputation: 0
2 NIC's - one gateway, setup Static route to Host

Dear All,

Box (kernel 2.6.27) with 2 NIC's behind a router(gw).

eth1 (NIC1):

gw (to the net):

the gw properly set up as the default gateway for eth1.

I would like to use eth2 (NIC2) to connect to one specific remote internet server:

The catch is that I need to be able to connect with eth1 to the internet,
as well as / or at least to the same

Since there seems to be no applications for 2 NIC's accessing the same gateway I couldn't find any useful Howto's or solutions.

I made two attempts to solve this task:
First was:
# ifconfig eth2 netmask up
# route add -host IP<> gw eth2

however, there is no way to access from eth1 (since eth2 becomes the preferred route for accessing

so I tried an experiment by erasing the default route for eth1 and instead adding
# route add -host IP<> gw eth1

which left me with 4 entries in the routing tab. 2 of them to access the subnet and the other 2 for accessing from eth1 and eth2 via

In both cases I then tried to establish a connection with stunnel and bind it to a the eth1 and eth2 IP

$ stunnel -c -f -I -d localhost:10443 -r

$ stunnel -c -f -I -d localhost:10993 -r

but the result was always that one of the devices was chosen by the kernel to perform the both data transfers. (which is the default behavior of the linux kernel, so I'm not whining about it

Is there a way to do such a 'static' load balancing by dest. IP that I'm looking for, and can I make both NIC's talk to the gw?

I'm guessing there is, if and only if I don't attempt to access the same IP ( with both NIC's.
If I do, the only way seems to be to filter the incoming packets with iptables by dest. port.

Sorry for the long post, I tried to make it as clear as I could.
Thanks for any help.
Old 04-14-2009, 02:05 PM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
iptables and packet marking is probably the best way to do this. You say that if you see a packet looking to leave the system which hits an iptables rule matching the ip and dest port then mark it with "2" or something, then use a seperate routing table which just throws everything out of your 2nd nic, bearing in mind that nothing will use that table by default.


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
can I setup a personal route through a server to a gateway using iptables wastingtime Linux - Networking 1 04-20-2008 07:41 PM
Two NIC's on same subnet/gateway TBKDan Linux - Networking 4 04-06-2007 10:20 PM
IP_forward? Static route (-host)? HELP! haiders Linux - Networking 2 09-18-2006 01:45 PM
Two NIC's for filtered gateway Markild Linux - Networking 8 12-04-2005 11:22 AM
nfs setup on slack 9.1 - no route to host daceo Slackware 2 02-19-2004 05:04 PM > Forums > Linux Forums > Linux - Newbie

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

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