There are two ways to permanently add static routes under Linux:
To add a route command:
1,route add
Route add-net 192.56.76.0 netmask 255.255.255.0 dev eth0# Add a static route route add default GW 192.168.0.1# add route del-net 19 2.168.1.0/24 GW 192.168.0.1# Delete a route route-n# view the routing table
2,ip ro Add
IP ro add 192.56.76.0/24 dev 192.168.0.1# add a static route IP ro add default via 192.168.0.1 Dev eth0# add a route IP ro del 192.168.1.0/24 #删除一条路由ip Route show# View the routing table
Common parameters:
Add Add route
Del Delete route
Via Gateway egress IP Address
Dev Gateway Export Physical device name
The way to make way is still valid after restarting the server:
1, add inside the/etc/rc.local:
The Add route command is: Copy the command directly from the command line to the file and save the exit.
2, write inside the/etc/sysconfig/static-routes file:
If the file does not exist, it is created manually and the Add content format is:
Refer to the shell statement inside the/etc/init.d/network file:
# Add non interface-specific static-routes. if [ -f /etc/ sysconfig/static-routes ]; then grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do /sbin/route add -$args done fi
If you want to add a static route, the command is:
Route add-net 192.56.76.0 netmask 255.255.255.0 Dev eth0
Then, in the/etc/sysconfig/static-routes file, add the format:
Any-net 192.56.76.0 netmask 255.255.255.0 Dev eth0
There are two ways to add a static route comparison:
1,rc.local:
Restart the server to take effect;
If the network service is restarted, the static route fails;
Rc.local is the last script that runs after the system starts, so this is not appropriate if the service Requirements for NFS require a network to be mounted;
2,static-routes:
Restart the server to take effect;
Restart the network service to take effect:
Suitable for services that require network requirements;
The way the script adds static routes and rc.local is pretty much the same:
This method is actually written in the script itself, placed at the beginning of/etc/rc3.d/set to S.
s means start, number is Order, K means stop.
Generally, startup is the boot order of a daemon in a pattern.
The smaller the number, the more forward the order of the boot;
/ETC/RC3.D is a text multi-user environment, the general production environment is this environment.
The downside is that it fails after restarting the network.
Summarize:
If you need to add static routes, add static routes to the/etc/sysconfig/static-routes file as much as possible. Avoid failure by restarting the network service, which prevents the routing from failing.
Permanently add static routes under Linux