LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 12-07-2011, 07:59 AM   #1
Senior Member
Registered: May 2006
Posts: 3,091

Rep: Reputation: 399Reputation: 399Reputation: 399Reputation: 399
Routing return traffic based on the NIC of the incoming traffic?

I have host A with two NICs. One NIC(1) is at, the other NIC(2) is directly on the internet. The default route for host A is the router on the internet (so traffic is routed through NIC(2). Host B is at and is a firewall connected to the internet, on a completely different subnet from host A, NIC(2). Host A and B have no problems connecting to each other over the network.

I have a web server running on host A, bound to both NICs. I can connect to the server over the internet using the IP address for host A, NIC(2). The firewall on host B is configured to forward port 80 to If I try to bring up the web page by connecting to the external IP address on that firewall, though, it never comes up. Packets obviously reach host A, though, as tcpdump on host A shows:

07:50:16.582844 IP some-remote-machine-on-the-internet-that-I-am-testing-from.34458 > S 1006697601:1006697601(0) win 14600 <mss 1460,sackOK,timestamp 1027543073 0,nop,wscale 4>
Now, if I change the route for some-remote-machine-on-the-internet-that-I-am-testing-from to, the page will come up. If I change the default route for all network traffic to, anyone connecting to the external IP address on the firewall will get the web page. But then, of course, any attempted connection to the IP address on NIC(2) will fail.

Is it possible to have host A route data through a specific route/nic depending on the NIC the connection originates from?
Old 12-07-2011, 04:08 PM   #2
LQ Guru
Registered: Mar 2008
Posts: 13,671

Rep: Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743Reputation: 1743
I am not sure I fully understand this. For the most part you can't easily select a nic for outgoing and a nic for incomming. IT can be done but this isn't what I think you are asking.

You can only use tcp/ip rules to route traffic. If nic a connects to a server then it has to by the rules of routing. Same for nic b. Nic a and nic b can't usually connect to this server because of rules both in hardware and software. Only one nic will take over.

We get back to a few issues. One is how tcp/ip works and how routers work and how a layer 7+ can work. My guess is you could use a layer 7+ router or some specialized device to then choose routes but a normal linux install doesn't easily allow that. And there is no normal reason.

Again I may misunderstand what you are trying to do.
Old 12-07-2011, 04:11 PM   #3
Senior Member
Registered: May 2006
Posts: 3,091

Original Poster
Rep: Reputation: 399Reputation: 399Reputation: 399Reputation: 399
Yeah, I don't think I made it very clear, but that's alright... I've configured the firewall to route port 80 to a machine that is only on the internal network, and has squid running a reverse http proxy to connect to the webserver in question.

Now to see if I can find a reverse ftp proxy. That would make my day :-)

Old 12-11-2011, 05:27 AM   #4
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
You can use "ip rule" to select an alternative routing table by source address.


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
[SOLVED] 2 NIC's 2 seperate networks, traffic routing kamaradski1 Linux - Networking 5 12-26-2011 08:01 AM
Routing incoming traffic to NAT'ed VM on a hired dedicated server merlininthewood Linux - Networking 2 05-21-2010 04:30 PM
[HELP] redirect traffic to spesific port based on Traffic Content using iptables summersgone Linux - Server 2 06-22-2009 12:26 PM
port based routing for local traffic houska Linux - Networking 2 05-24-2009 08:10 AM
Allow Incoming Traffic clarence1720 Mandriva 15 12-07-2004 12:26 AM

All times are GMT -5. The time now is 01:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration