Home > Article > Operation and Maintenance > route addHow to add static route
The method is: 1. Add the route to the host, "# route add –host 192.168.1.11 dev eth0"; 2. Add the route to the network, "# route add –net 192.168.1.0/24 eth1 ".
#The operating environment of this tutorial: centos7 system, thinkpad t480 computer.
The specific operation method is as follows:
1. Use the route command to add a route.
The route added using the route command will become invalid after the machine is restarted or the network card is restarted. Method:
//Route added to the host
# route add –host 192.168.1.11 dev eth0 # route add –host 192.168.1.12 gw 192.168.1.1
//Route added to the network
# route add –net 192.168.1.11 netmask 255.255.255.0 eth0 # route add –net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1 # route add –net 192.168.1.0/24 eth1
//Add default gateway
# route add default gw 192.168.2.1
//Delete route
# route del –host 192.168.1.11 dev eth0
2: How to set up permanent routing under Linux:
./etc/sysconfig/static-routes : any net 192.168.3.0/24 gw 192.168.3.254 any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129
The method of using static-routes is the best. It will take effect regardless of restarting the system and service network restart.
What is the static-routes file? This is a file called when the network script is executed. This file is placed in the /etc/sysconfig directory. Its location in the network script is:
# 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
As you can see from this script, this is the way to add static routes. The writing method of static-routes is
any net 192.168.0.0/16 gw 网关ip。
(recommended learning: linux tutorial)
The above is the detailed content of route addHow to add static route. For more information, please follow other related articles on the PHP Chinese website!