Here is the traditional way to set static route on Linux OS.
1 |
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 |
The best way to make it permanent, is to add the gateway directly to the interface by editing the interface script :
1 |
/etc/sysconfig/networking/devices/ifcfg-eth0 |
add :
1 |
GATEWAY=192.168.1.1 |
To remove a static route :
1 |
route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 |
On RHEL/CentOS Linux, there is a way to set this per interface through a single config file.
Edit the following file (create if non-existent) :
1 |
vi /etc/sysconfig/network-scripts/route-eth0 |
Append the following lines and modify with your values :
1 2 3 |
default 0.0.0.0 dev eth0 0.0.0.0/24 via 0.0.0.1 dev eth0 0.0.2.0 via 0.0.2.1 dev eth0 |
*Include the default route on the first line and then add as many subnet as you have.