I have two subnets routed to my server from ISP. I have only one gateway ip. The gateway is on the same VLAN as my IP address. For example netowrk 1 is 1.0.0.0/24 and network 2 is 2.0.0.0/24. Both are routed to eth0 by my ISP. Gateway is 1.0.0.1. My host ip is 2.0.0.1/24 (eth0) So I can configure default gateway manually with
ip route add default dev eth0
ip route add default via 1.0.0.1
and then internet connection works properly. How do I configure it in /etc/sysconfig/network-scripts/ifcfg-eth0 ?
I tried to set GATEWAY=1.0.0.1 but it doesn't work. Tried to set GATEWAY and GATEWAYDEV in /etc/sysconfig/network and it does only what first command from listing above do.
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.
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:
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.Ran into the same issue last week. Set up routes manually with
ip route add...
, and to make it persist,ip r l > /etc/sysconfig/network-scripts/route-em1
(edit it afterwards a bit) and voila