I have one test server that has Two Interfaces. To one interface i have assigned ip and GW 172.16.xxx.xxx

Now i connected cable to second interface and gave it ip

Now they both on different subnets.

So how do I add the second gateway in /etc/sysconfig/network file. And when i will try to ping then through which interface will it ping the remote system.


Technically you can have multiple default gateways but that is the realm of core internet servers, network load balancers, and so on for the most part.

Much more common is a requirement for multiple routes, each with its own router.

Example: You have a computer sitting between two networks, like this: and

You use as Default Gateway - that is the default route for anything not locally attached. Locally attached is explicitly defined as anything which is in any of the subnets on which you have an interface in the UP/RUNNING state and for which there is no explicit static route defined.

In this configuration you already have three routes: A route for everything locally on, with the gateway being your own IP address on that subnet. You have a similar route for the systems on And finally you have a default route, that being for "" pointing to the default gateway. (There are also some other "psuedo" routes on some operating systems, eg for accessing the loopback device, or for broadcast traffic)

Now say there is a router at which provides access to a number of networks. Usually these are "internal" networks. You can now add "static routes" to these networks. Example for a network with subnet

Linux Example:

route add -net netmask gw

You can add multiple "static" routes through one router, or routes can use as many routers/gateways as needed.

You can view the table of known routes with the command

netstat -rn

The Linux specific command will show the same information in a slightly different format.

ip route show

The router(s) specified must "know" how to reach the target network, otherwise it will go to its own default gateway and forward your packets that way.

To make this configuration changes persistent you need to add it to the system configuration files. Static routes are relevant to one specific interface so they do not go into /etc/sysconfig/network. In stead these go into files located in /etc/sysconfig/network-scripts/

For example: /etc/sysconfig/network-scripts/route-eth0

You add "via" entries into this file for routes. These lines read like "Access network X via gateway Y on Network interface device Z. Example

default dev eth0 via dev eth0 via dev eth0

And so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.