two etherports with two gateways

I need some help here. I have a box running RH EP WS and I have two ethernet ports each connected to a different switch with different subnets.

eth1 - gateway
eth0 - gateway

I need requests on each port to use its own gateway when reponding, but they both seem to be using the same broadcast IP (the .1 network). I can hit out side addresses from the box--and then I bring down eth1--I cannot hit an outside address. In /etc/sysconfig/network-scripts I have a file for each address ifcfg-eth0 which looks like this:



[]# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface     *        U         0 0          0 eth0     *        U         0 0          0 eth1     *          U         0 0          0 eth1
default         UG        0 0          0 eth1

Can someone tell me how to get each to use it's own gateway? Please let me know if you need me to do any tests to see what is happening.

Thanks in advance.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

ahoffmannConnect With a Mentor Commented:
> I need eth1 to use and eth0 to use
that's already done by the netroute for each subnet, just the default route gows to
So what exactly is your problem?
An interface doesn't have a "gateway". What you have is a routing table which where to send data to.

A default gateway is just a route to all possible IP addresses for which you don't have a more specific route.

If you want to have two gateways, you can set them manually by doing the following:

route add default gw metric 1
route add default gw metric 10

I would recommend setting different metrics. This setting means that he will send all traffic except the connected to

If he is unable to reach because that interface is down, he will switch over to the second default gateway.

td234Author Commented:
Thanks for correcting my naming. I have deduced that I and trying to set my "persistent static routes".  I do not believe your example will set them on a per interface level unless I am missing somthing. I need eth1 to use and eth0 to use

I found this:
Which tells me to set up "route-ethX" files for each interface. I have tried that, but still get this:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface     *        U     0      0        0 eth0     *        U     0      0        0 eth1     *          U     0      0        0 eth1
default         UG    0      0        0 eth1

Any other ideas?

Thanks Thom
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

No, my setup will not set them on a "per interface level". But that is not possible.

Suppose you have a package you want to send to

What your system does is look into the routing table:
 1- Is there a directed connected network which has this IP adress. No.
 2- What is the MOST specific route ( has presedence over (the default route)) in my routing table to this IP address. If you have only specified a default route, he will take that one.
 3- If there is more than one route which are equally specific, take the one with the lowest metric.

Once you got a route he will send the traffic to the next hop. It is only at that stage that the computer decides to send traffic to a specific interface: he'll send it to the interface where the gateway he wants to use is located.

Can you explain the reason why you want two default gateways ? If it is because you want to build in redundancy, my suggestion will work.  If it is because you want to send some data one direction, the other the other way, you need to make a different routing table. But maybe there is another reason ?


Hanno P.S.IT Consultant and Infrastructure ArchitectCommented:
As stated before: You cannot connect specific routers to specific interfaces.
Routing always tries to find the best suited path and therefore which interface to send packets out.
If you want to be able communicating still when any one interface is down, you will have to add two default gateways. Usually, when taking an interface down, the corresponding route(s) should get removed with it. (Linux doesn't do this?)
If there are "intelligent" routers on the subnets, you might have them advertise routes and use the 'gated' or 'routed' daemons to load your routing tables dynamically.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.