LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 01-21-2010, 12:48 PM   #1
vockleya
Member
 
Registered: Aug 2009
Posts: 87

Rep: Reputation: 16
Routing ports to secondary network card


I have a program that connects to the internet that I would like to route through one of my secondary network interfaces. I need one specific port routed to eth1 instead of eth0. I believe that I should be using iptables for that, but I don't really know how to do it. Any suggestions?
 
Old 01-21-2010, 01:14 PM   #2
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
What is the output of "route -n"?
 
Old 01-21-2010, 03:08 PM   #3
vockleya
Member
 
Registered: Aug 2009
Posts: 87

Original Poster
Rep: Reputation: 16
Quote:
aaron-desktop:~ aaron$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
134.82.164.0 0.0.0.0 255.255.255.0 U 1 0 0 eth2
134.82.164.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
134.82.164.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth2
0.0.0.0 134.82.164.254 0.0.0.0 UG 0 0 0 eth2

eth2 is the current default. I want to route port 51413 to eth 0 instead of eth2, so it doesn't interfere with the rest of my internet traffic
 
Old 01-21-2010, 03:19 PM   #4
jschofield
LQ Newbie
 
Registered: Jan 2010
Location: Blackfalds, Alberta
Distribution: Mandriva 2006.0
Posts: 26

Rep: Reputation: 15
Yes for somthing as simple as that 'iptables', is what you should use.

take a look at
http://www.netfilter.org/

iptables -t nat -A POSTROUTING -p tcp -o eth0 --dport 51413 -s 134.82.164.x -j MASQUERADE

I would verify the exact structure as i am doing this from memory.
 
Old 01-21-2010, 03:29 PM   #5
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Thanks.
Post please output of "ifconfig" for eth0, eth1, eth2.

Last edited by nimnull22; 01-21-2010 at 03:33 PM.
 
Old 01-21-2010, 03:35 PM   #6
vockleya
Member
 
Registered: Aug 2009
Posts: 87

Original Poster
Rep: Reputation: 16
While everything in this command seems right, I get the error that --dport is an unknown option.
 
Old 01-21-2010, 03:49 PM   #7
vockleya
Member
 
Registered: Aug 2009
Posts: 87

Original Poster
Rep: Reputation: 16
eth0 Link encap:Ethernet HWaddr 00:c0:f0:48:5a:ea
inet addr:134.82.164.212 Bcast:134.82.164.255 Mask:255.255.255.0
inet6 addr: fe80::2c0:f0ff:fe48:5aea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5124991 errors:1 dropped:0 overruns:0 frame:0
TX packets:2580704 errors:1 dropped:0 overruns:0 carrier:1
collisions:0 txqueuelen:1000
RX bytes:2773159249 (2.7 GB) TX bytes:246327507 (246.3 MB)
Interrupt:20 Base address:0xe800

eth1 Link encap:Ethernet HWaddr 00:a0:cc:41:2a:a1
inet addr:134.82.164.209 Bcast:134.82.164.255 Mask:255.255.255.0
inet6 addr: fe80::2a0:ccff:fe41:2aa1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16325 errors:1 dropped:0 overruns:0 frame:0
TX packets:3611 errors:1 dropped:0 overruns:0 carrier:1
collisions:0 txqueuelen:1000
RX bytes:2709109 (2.7 MB) TX bytes:637324 (637.3 KB)
Interrupt:23 Base address:0xe400

eth2 Link encap:Ethernet HWaddr 00:e0:4d:ba:60:36
inet addr:134.82.164.188 Bcast:134.82.164.255 Mask:255.255.255.0
inet6 addr: fe80::2e0:4dff:feba:6036/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:36332372 errors:0 dropped:0 overruns:0 frame:0
TX packets:19938318 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19853282142 (19.8 GB) TX bytes:2965931557 (2.9 GB)
Interrupt:27 Base address:0xc000
 
Old 01-21-2010, 08:40 PM   #8
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Try that rule:
Code:
iptables -t nat -A OUTPUT -p tcp --dport 51413 -j DNAT --to-destination 134.82.164.212

or may be like this:
iptables -t nat -A OUTPUT -p tcp --dport 51413 -j DNAT --to-destination 134.82.164.212:51413
I actually not really sure that will work, as by this rule we ask iptable to send traffic to eth0 IP address.
It is possible also to send it to GW, but as all ethernet in same network it is useless.
 
Old 01-21-2010, 10:26 PM   #9
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
It's pretty much impossible that the bandwidth of a single NIC is lower than your Internet bandwidth. As long as this is the case there's simply no need to split Internet-bound traffic between different cards.
 
Old 01-21-2010, 10:34 PM   #10
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Quote:
Originally Posted by chort View Post
It's pretty much impossible that the bandwidth of a single NIC is lower than your Internet bandwidth. As long as this is the case there's simply no need to split Internet-bound traffic between different cards.

What are talking about, and with whom?
 
Old 01-21-2010, 11:00 PM   #11
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
Quote:
I have a program that connects to the internet that I would like to route through one of my secondary network interfaces.
There doesn't appear to be any need to actually do this.
 
Old 01-21-2010, 11:15 PM   #12
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Quote:
Originally Posted by chort View Post
There doesn't appear to be any need to actually do this.
Yes, but who knows how OP connects his NIC to switch/router. May be there is something additional after one of NIC.
 
Old 01-21-2010, 11:19 PM   #13
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
Well they're all on the same subnet, so I doubt that... It's best to find out the why before the what. Knowing the first can dramatically change the second.
 
Old 01-21-2010, 11:24 PM   #14
vockleya
Member
 
Registered: Aug 2009
Posts: 87

Original Poster
Rep: Reputation: 16
Each connection to the router has a 2Mbit bandwidth limit. By routing my server traffic over a secondary NIC I can free up the main one for internet browsing and downloading stuff, which is dramatically slowed when the server is being used.
 
Old 01-21-2010, 11:24 PM   #15
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
You don't understand me, between NICs and router/switch can be many additional equipment.
 
  


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
OpenVPN traffic routing on secondary IP problem dominos Linux - Networking 1 07-06-2009 10:42 PM
Running VNC server on a secondary video card rguima Linux - General 3 04-29-2009 07:10 AM
2 Network Card Configuration (for routing) dc_eros Slackware 2 12-19-2006 09:17 PM
how to use a secondary sound card, (i think i did something stupid...) Farthom Linux - Hardware 0 03-07-2004 10:50 PM
Cant get my routing network card to be active! im_not_jose Linux - Networking 9 07-25-2003 12:28 PM

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

All times are GMT -5. The time now is 05:16 AM.

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