The route command is a command to operate and view the routing table. A routing table is a table that records how network devices (such as computers, routers, etc.) transmit data packets. Through the route command, we can view the current routing table information and add or delete routing rules.
Syntax
route [option] [command] [destination address] [mask subnet mask] [gateway address] [metric hop count] [if interface]
Common options
-p: Save the added routing rules persistently, that is, they will still be valid after restarting.
-delete or -d: Delete the specified routing rule.
-print: Print out the current routing table information.
Common commands
add: Add a routing rule. Parameters such as destination address, subnet mask, gateway address and interface need to be specified.
Sample code:
View the current routing table information
route print
Add a routing rule
route add 192.168.1.0 mask 255.255.255.0 192.168.0.1 if 1
The above command indicates that the network segment with the target address 192.168.1.0 and the subnet mask 255.255.255.0 will be transmitted from interface 1 through the gateway address 192.168.0.1.
Delete a routing rule
route delete 192.168.1.0 mask 255.255.255.0 192.168.0.1
The above command means to delete the network segment with the target address 192.168.1.0, the subnet mask is 255.255.255.0, and the gateway address is 192.168 .0.1 routing rules.
Use the route command to flexibly configure the routing table of a network device to achieve data transmission between different networks. In actual use, we can add, delete and modify routing rules according to specific network environments and needs to achieve optimal network transmission performance.
It should be noted that you should be careful when using the route command. Wrong routing rules may cause abnormal network transmission or even network failure. When modifying routing rules, it is recommended to back up the original routing table in advance so that it can be restored when necessary. In addition, when adding persistent routing rules, make sure that they are still valid after the network device is restarted to avoid causing network connection problems.
The above is the detailed content of Route command introduction. For more information, please follow other related articles on the PHP Chinese website!