LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-10-2005, 06:58 AM   #1
knight-rider
LQ Newbie
 
Registered: Feb 2004
Posts: 5

Rep: Reputation: 0
two nic's same n/w different interface for gw, how done?


I am posing this question as I cannot see in the man page how it can be done but here is my question:

Suppose I have a linux box with 2 nic's each with their own ip address on the same network, and i want each to route packets to the gateway directly not using the other interface.

heres what i mean, this is my routing table:

Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
138.217.168.0 0.0.0.0 255.255.252.0 U 0 0 0 eth1
138.217.168.0 0.0.0.0 255.255.252.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 138.217.168.1 0.0.0.0 UG 0 0 0 eth0

now as you can see the default GW is 138.217.168.1 using Iface eth0. Thats fine for eth0 to use this but I dont however want interface eth1 routing through there also.

The reason I want to do this is that i want to use eth0 as my web server and eth1 for something else of a different purpose, and I want each interface eth0 and eth1 to operate independantly of each other.
 
Old 08-10-2005, 07:56 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
How about trying this

Code:
route add -net default gw X.X.X.X dev ethX
Hope this helps!
 
Old 08-10-2005, 07:30 PM   #3
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
Quote:
Originally posted by Centinul
How about trying this

Code:
route add -net default gw X.X.X.X dev ethX
Hope this helps!
Looks like knight-rider already has a default route, though (look at the last line-- 0.0.0.0).

knight-rider, I am not sure I understand what you are trying to accomplish, but routing is dead simple:

+ Routing comes into play when your computer needs to send a packet somewhere. If you do not have IP forwarding enabled, that means it will only happen when the packets originate locally on that machine. Otherwise, the packets can also come in over one of the NICs.

+ When deciding where to send the packets, the routing machinery consults the routing table. Each entry has a destination and a netmask.

+ The netmask is applied to the destination address for the packets, and it is compared to the destination entry in the routing table. If it's a match, then the packets can be sent there.

+ Sometimes there could be several matches. In that case, the most specific match is made. For example, if I am sending packets to 192.168.1.7, and I have entries:

Destination Netmask
192.168.0.0 255.255.0.0
192.168.1.0 255.255.255.0

The second entry will be chosen because it has the more specific network (there are more bits set in its netmask).

That's about all there is to it.

So there are some things you *can't* do just by routing. Say I have a web server and an FTP server, and I have two NICs. Let's further suppose that I want all my web traffic to go out over NIC 1, and all FTP traffic to go out over NIC 2. Well, for a given destination, there is going to be exactly 1 route, so if a particular host uses both FTP and a web browser, my plan is not going to work.

Instead, I would probably have to set up netfilter to forward the packets to the correct interface. You could use the command line utility, iptables, to do that.

Does that help at all?
 
Old 08-10-2005, 11:56 PM   #4
RHELL
Member
 
Registered: Feb 2004
Location: Outermost mingetty
Distribution: RHEL3,RH4U4,Sol9, Sol10
Posts: 321

Rep: Reputation: 31
I believe you can designate a different gateway in each ifcfg-ethx file:
'GATEWAY=xx.yy.zz.aa'

This would allow you to specify a different gateway for each nic.
 
  


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
1 IP for 2 NIC's turbo_acura Linux - Networking 4 10-10-2005 04:33 PM
2 NIC's help troycus Linux - Networking 18 04-07-2005 08:01 PM
TWO NIC's bhughesiii Linux - Networking 8 09-23-2004 09:48 AM
2 NIC's plisken Linux - Networking 1 04-19-2003 03:32 PM
NIC's sscharbo Linux - Networking 1 01-11-2001 08:34 AM

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

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