LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   two nic's same n/w different interface for gw, how done? (https://www.linuxquestions.org/questions/linux-networking-3/two-nics-same-n-w-different-interface-for-gw-how-done-351796/)

knight-rider 08-10-2005 06:58 AM

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.

Centinul 08-10-2005 07:56 AM

How about trying this

Code:

route add -net default gw X.X.X.X dev ethX
Hope this helps!

carl.waldbieser 08-10-2005 07:30 PM

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?

RHELL 08-10-2005 11:56 PM

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.


All times are GMT -5. The time now is 02:16 PM.