Default gateway is in different subnet. How to configure in RHEL6.2

You really won't find support for something like this, as it's not something that will pass any sanity checks.

So, think about it a bit. Your computer needs to know the gateway address in order to reach other machines outside it's local subnet. So, if you have a subnet 10.0.1.0/24 and your machine is 10.0.1.12, it would be able to reach any machine from 10.0.1.0-10.0.1.255 without using the gateway.

The gateway is typically required to be within the machine's subnet otherwise the machine has no way to reach it (without some routing tricks, as you are doing). Going back to the example above, if the gateway had an IP of 10.0.2.10, the machines would have no way to reach it (in order to send traffic outside their subnet, they need to reach the gateway, which is outside their subnet).

Are you absolutely certain that you have the correct subnet mask? As another example, if you have an IP in 10.0.1.0/16 with a gateway of 10.0.2.0, this is perfectly valid. If you had 10.0.1.0/24 and a gateway of 10.0.2.0, this is not. I would suspect that your ISP has given you the wrong netmask information.


I've managed to find an answer by myself.

#cat /etc/sysconfig/network-scripts/route-eth0
1.0.0.0/24 dev eth0
default via 1.0.0.1 dev eth0

It looks a bit better than lines in rc.local At least it is related to routing in terms if RHEL way of network configuraion


You can't achieve the same result with initscripts. Here's the relevant portion of /etc/sysconfig/network-scripts/network-functions:

if [ "$GATEWAY" = "0.0.0.0" ]; then
    /sbin/ip route add default dev ${GATEWAYDEV}
else
    /sbin/ip route add default via ${GATEWAY}
fi

Which means that only one of the two commands you listed would run, but not both.

A better solution would be taking another IP from 1.0.0.0/24 and giving it to eth0 on the server instead of 2.0.0.1. Then you have the conventional setup, routing everything over 1.0.0.0/24, and you use 2.0.0.0/24 with fully legit stuff like proxy ARP and iptables.

If you can't do that, just stick the two ip route commands into /etc/rc.local.