Simple Operation notes:
1. View
Route-n
2. Add
Route add-net x.x.x.x netmask x.x.x.x GW x.x.x.x
Route add-net x.x.x.x netmask x.x.x.x Dev eth0
3. Delete
route del-net x.x.x.x netmask x.x.x.x GW x.x.x.x
Route del-net x.x.x.x netmask x.x.x.x reject
4. Shielding
Route add-net x.x.x.x netmask x.x.x.x reject
5. Delete and add set default gateway
Route del default GW x.x.x.x
R oute Add default GW x.x.x.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
eg
[Email protected] ~]# route-n
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[Email protected] ~]# route
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth1
link-local * 255.255.0.0 U 1002 0 0 eth0
link-local * 255.255.0.0 U 1003 0 0 eth1
Default localhost 0.0.0.0 UG 0 0 0 eth0
[Email protected] ~]#
Explain:
Flags flags indicate:
U up indicates that this route is currently in the boot state
H host, which indicates that the gateway is a host
G Gateway, which indicates that this gateway is a router
R reinstate route, re-initialized with dynamic routing
D dynamically, this route is dynamically written to
M Modified, this route is dynamically modified by the route daemon or director
! Indicates that this route is currently in a closed state
Note:
Route-n (-n means not resolving names, listing faster than route)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Command format:
Route [-F] [-P] [Command [Destination] [Mask Netmask] [Gateway] [metric metric]] [if Interface]]
2. Command function:
The route command is used for operations based on the kernel IP routing table, and its primary function is to create a static route that lets you specify a host or a network through a network interface, such as eth0. When the "add" or "del" parameter is used, the routing table is modified, and if there are no parameters, the current contents of the routing table are displayed.
3. Command parameters:
-C Show more information
-N does not parse name
-V displays detailed processing information
-F Display Send message
-C Show Route cache
-F Clears the routing table for all gateway portals.
-P is used with the add command to make the route permanent.
Add: Adds a new route.
Del: Deletes a route.
-net: The destination address is a network.
-host: The destination address is a host.
Netmask: When you add a network route, you need to use a netmask.
GW: Route packets through the gateway. Note that the gateway you specify must be able to be reached.
Metric: Sets the route hop count.
command to specify the commands you want to run (add/change/delete/print).
DESTINATION Specifies the network destination for this route.
The mask Netmask Specifies the network mask (also known as the subnet mask) that is associated with the network destination.
The Gateway specifies the address set and subnet mask defined by the network destination to reach the forward or next hop IP address.
The metric metric specifies an integer cost value for the route (from 1 to 9999) that can be used when the routing table (which matches the destination address of the forwarded packet) is selected in multiple routes.
The If Interface specifies the interface index for the interface that can access the target. To obtain a list of interfaces and their corresponding interface indexes, use the display function of the route print command. You can use decimal or hexadecimal values for interface indexing.
This article from "Ningzhiyuan @it Notes" blog, reproduced please contact the author!
Linux Add Delete route entry notes!