Linux commonly used routing commands

Add linux permanent static routing There are two ways

Add routes command:

1.route add

route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0  #添加一条静态路由  
route add default gw 192.168.0.1   #添加默认路由 
route del -net 192.168.1.0 /24 gw 192.168.0.1  #删除一条路由
route -n  #查看路由表

2.ip ro add

ip ro add 192.56.76.0 /24 dev 192.168.0.1  #添加一条静态路由
ip ro add default via 192.168.0.1 dev eth0  #添加默认路由  
ip ro del 192.168.1.0/24 #删除一条路由 ip route show  #查看路由表 

Common parameters:

Add to add routing

del Delete route

via export gateway IP address

dev gateway exports physical device name

After allowing the routing restart the server remains in effect:

1. /etc/rc.local which added:

Add the route command is: copy command directly from the command line operations into the file, you can save out.

2. In the / etc / sysconfig / static-routes file written inside:

If the file does not exist, manually create, add content format:

/Etc/init.d/network reference file inside the shell statement:

# 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

Then, if you want to add a static route command is:

route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0

Then, add formatting in / etc / sysconfig / static-routes file as follows:

any -net 192.56.76.0 netmask 255.255.255.0 dev eth0

Add a static route contrast in two ways:

1.rc.local:

Reboot the server to take effect;

Restart network services, static routing failure;

rc.local script is a last run after the system starts, so if you like NFS network service requirements need to be mounted, then the way is not suitable;

2.static-routes:

Reboot the server to take effect;

Network Service Restart to take effect:

For services that require network requirements;

Adding script static routing methods and rc.local on the same subject:

This method is actually to write your own script, placed /etc/rc3.d/ beginning to S.

S means is activated, a sequence number, K is the stopping means.

Daemon is usually started at a startup sequence mode.

The smaller the number of sequential forward start;

/etc/rc3.d text is a multi-user environment, the general environment is the production environment.

If you need to add static routes, try to add static routes to / etc / sysconfig / static-routes file. Avoid restart the network service routing failure cause, in order to avoid failure.

Guess you like

Origin www.cnblogs.com/notfound/p/11932201.html