Linux add or delete route using route command
Route all traffic via 192.168.1.254 gateway connected via eth0 network interface:
# route add default gw 192.168.1.254 eth0
#route add -net 10.0.0.0/24 IP_nex_hop (showing nexhop like eth_whatever_number, is not acceptable way)
or you can do this like (this is only more typing for you (; )
#route add -net 10.0.0.0/24 IP_nex_hop dev eth?
or with netmask command
# route add net 192.168.1.0 netmask 255.255.255.0 192.168.1.254
Linux route add or delete route using ip command
Just like above but with ip command:
adding static route via interface eth0
# ip route add 192.168.1.0/24 dev eth0
or adding defalt gateway
#ip rote add 0.0.0.0/24 via ip_nex_hop
IF YOU WANT TO DELETE ROUTE, JUST CHANGE WORD 'ADD' TO 'DEL'
Linux Persistence Routes
The drawback of 'ip' or 'route' command is that, when Linux reboots it will forget static routes. So store them in configuration file. Static routing describes a system that does not implement adaptive routing. In these systems routes through a data network are described by fixed paths (statically). These routes are usually entered into the router by the system administrator
Red Hat (RHEL) / CentOS / Fedora Linux Persistence Static Routing
You need to open /etc/sysconfig/network-scripts/route-eth0 (IF YOU HAVE ONE, OTHERWISE JUST CREATE THIS FILE MANUALLY, ROUTE-ETH0 FOR ETH0 INTERFACE ROUTE-ETH1 FOR ETH1 INTERFACE )file to define static routes for eth0 interface:
# cat /etc/sysconfig/network-scripts/route-eth0
Sample Output:
GATEWAY0=192.168.1.254
NETMASK0=255.255.255.0
ADDRESS0=192.168.55.0
GATEWAY1=10.164.234.112
NETMASK1= 255.255.255.240
ADDRESS1=10.164.234.132
if your want do I define static routing for network 10.0.0.0/8 via 10.9.38.65 router?
add to this file the following lines
Append following line:
10.0.0.0/8 via 10.9.38.65
Save and close the file. Restart networking:
# service network restart
Verify new routing table:
# route -n
SUSE configuratons
It could be done through yast2 manager with GUI configuration or CLI commands
#vi /etc/sysconfig/network/routes
10.0.0.0/24 192.168.0.1 eth0
so first line is network you wanna route to...
the second one is gateway you are routing through...
the third line is device (network interface) you connected to the next hop
Open Suse way to add static routes
source:http://www.susegeek.com/networking/how-to-setup-persistent-static-routes-in-opensuse-110/
in openSUSE 11.0, the network setup is by default controller by “NetworkManager” and this is different from the traditional netcontrol. With NetworkManager, users control the Network Interfaces. To confirm this, in GNOME from Computer – Yast – Network Devices – Network Settings, check for option “User Controlled with Network Manager” under Network Setup Method. Or, check for the line ‘NETWORKMANAGER=”yes”‘ in /etc/sysconfig/network/config file.
This may not be a viable option to use on SUSE enterprise Desktop as in a enterprise environment you wouldn’t want the user to modify or control network settings.

To setup persistent Statis Routes in openSUSE 11.0 when network settings are controlled by NetworkManager, then try the following:
1. Create a ifroute-<*> file for each interface
For every network interface on the system which needs individual persisten static routing table create a “ifroute-<*>” file in the /etc/sysconfig/network/ directory.
where <*> is the name of the interface
For instance, on my system the interface name is eth0 and hence I create a file called
/etc/sysconfig/network/ifroute-eth0
This file should have the static route entries for the hosts or networks in any of the following format:
DESTINATION GATEWAY NETMASK INTERFACE [ TYPE ] [ OPTIONS ]
Example
192.168.1.1 192.168.233.2 255.255.255.255 eth0DESTINATION GATEWAY PREFIXLEN INTERFACE [ TYPE ] [ OPTIONS ]
Example
10.1.1.0 192.168.233.2 24DESTINATION/PREFIXLEN GATEWAY - INTERFACE [ TYPE ] [ OPTIONS ]
10.1.1.0/24 192.168.233.2 -
In the above each of the field is seperated by a TAB. [TYPE][OPTIONS] are optional.
If you not in the above, Example 2 & 3 mean exactly the same. Only represented in different formats.
So, I created a file as follows on my system
SAIBABA:~ # cat /etc/sysconfig/network/ifroute-eth0
10.1.1.1 192.168.233.2 255.255.255.255 eth0
10.10.10.0 192.168.233.2 24 eth0
172.20.1.0/24 192.168.233.2 – eth0
2. NetworkManager POST_UP Script
With NetworkManager, the POST_UP scripts are fetched from /etc/sysconfig/network/if-up.d/ directory and is set to ‘yes’ (enabled) by default. In simple terms, any script that you want to run once the Network interface up and active, simply drop them into this directory or create a symbolic link to the script file in this directory.
In SUSE and openSUSE, there are the following scripts in /etc/sysconfig/network/scripts/ directory which assist in bring up/down Interface routes and to check the status
ifup-route
To bring up static routes. This reads the file /etc/sysconfig/network/ifroute-* file.
ifdown-route
To clear the static routes loaded
ifstatus-route
To check the current status of the routes
# /etc/sysconfig/network/scripts/ifstatus-route eth0Configured routes for interface eth0:
169.254.0.0 – 255.255.0.0 eth0
10.1.1.1 192.168.233.2 255.255.255.255 eth0
10.10.10.0 192.168.233.2 24 eth0
172.20.1.0/24 192.168.233.2 – eth0
Active routes for interface eth0:
10.1.1.1 via 192.168.233.2
172.20.1.0/24 via 192.168.233.2
192.168.233.0/24 proto kernel scope link src 192.168.233.128
10.10.10.0/24 via 192.168.233.2
169.254.0.0/16 scope link
default via 192.168.233.2 proto static
3 of 4 configured routes for interface eth0 up
3. Create a Symbolic File for ifup-route
In the POST_UP directory for NetworkManager i.e, /etc/sysconfig/network/if-up.d/ create a Symbolic link as follows to the ifup-route script as follows:
# ln -s /etc/sysconfig/network/scripts/ifup-route /etc/sysconfig/network/if-up.d/ifup-route
Thats it. You can either restart your system or simply restart your Network service for the change to take effect.
# /etc/init.d/network restartShutting down the NetworkManager done
Shutting down network interfaces:
eth0 device: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10) done
Shutting down service network . . . . . . . . . . . . . done.
Starting the NetworkManager done