Two methods of adding soft routes in Linux
The first type:
Route add-net 172.16.6.0 netmask 255.255.255.0 gw 172.16.2.254 Dev eth0
/* Add a network 172.16.6.0/24 through 172.16.2.254 eth0 */
/*-net Add Network-host Add host netmask subnet mask GW Gateway Dev device, device, here is your network card name */
Route del GW 172.16.2.254/* Delete Default gateway 172.16.2.254 */
Route del-net 172.16.86.0/24/* Delete the default network 172.16.86.0 */
Route/* Displays the current routing table */
This is often the way it is, but sometimes you do not work when you delete or a soft route, and there are hints:
SIOCADDRT: No way to access the Internet
So this is the way to do it.
The second type:
The functions implemented are the same as above
IP route add 172.16.6.0/24 via 172.16.2.254 Dev eth0
IP route del GW 172.16.2.254
IP route del 172.16.6.0/24 dev eth0
IP route
method to delete:
To add a route:
Route add-net 10.0.0.0 netmask 255.0.0.0 Dev eth0
To delete a route:
Route del-net 10.0.0.0 netmask 255.0.0.0 Dev eth0
To add a default route:
Route add default GW 10.0.0.1
To delete the default route:
Route del default GW 10.0.0.1
Or
Route del Default
Ways to add routes under Linux:
One: Use the route command to add
Routes added using the route command, the machine restarts, or the network card restarts, the route is invalidated, by:
Routes added to the host
# route add–host 192.168.168.110 Dev eth0
# route Add–host 192.168.168.119 GW 192.168.168.1
Routes added to the network
# route add–net IP netmask MASK eth0
# route add–net IP netmask MASK GW IP
# route Add–net ip/24 eth1
Add a default gateway
# route add default GW IP
Delete route
# route del–host 192.168.168.110 Dev eth0
Two: The method of setting the permanent route under Linux:
1. Add in/etc/rc.local
Method:
Route add-net 192.168.3.0/24 Dev eth0
Route add-net 192.168.2.0/24 GW 192.168.3.254
2. Add to end in/etc/sysconfig/network
Method: Gateway=gw-ip or Gateway=gw-dev
3./etc/sysconfig/static-router:
Any net x.x.x.x/24 GW Y.y.y.y
This article from "Hhslinux" blog, declined reprint!
Linux add remove soft route