Show all Routes now
#route
[Email protected] ubuntu:~# Route
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
10.147.9.0 * 255.255.255.0 U 1 0 0 eth0
192.168.1.0 * 255.255.255.0 U 2 0 0 Wlan0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
link-local * 255.255.0.0 U 0 0 eth0
192.168.0.0 192.168.1.1 255.255.0.0 UG 0 0 0 Wlan0
Default 10.147.9.1 0.0.0.0 UG 0 0 0 eth0
[Email protected]:~#
The result is top-down, that is, which one is in front, which one has precedence, none in front, with the last default
For example, add a route (all the network segments destined for 192.168.62 go through the gateway 192.168.1.1)
Route add-net 192.168.62.0 netmask 255.255.255.0 GW 192.168.1.1
Delete a route
Route del-net 192.168.122.0 netmask 255.255.255.0
Do not write the gateway when deleting
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
Linux-Add, modify, delete routes