Home  >  Article  >  Operation and Maintenance  >  How to use the route add command

How to use the route add command

coldplay.xixi
coldplay.xixiOriginal
2020-10-27 11:41:2218350browse

The route add command is used to display and modify entries in the local IP routing table. Use ROUTE without parameters to display help. The code is [route [-f] [-p] [command [destination] [ mask netmask] ....].

How to use the route add command

route add command usage:

1. Specific functions

This command is used to display and modify entries in the local IP routing table. Use ROUTE without parameters to display help.

2. Detailed syntax explanation

route [-f] [-p] [command [destination] [mask netmask] [gateway] [metric metric] [if inte***ce]

3. Parameter description

-f

Clear all items that are not the main Route (route with subnet mask 255.255.255.255), loopback network route (route with destination 127.0.0.0, subnet mask 255.255.255.0), or multicast route (route with destination 224.0.0.0, subnet mask The routing table contains entries with the route code 240.0.0.0). If it is used in conjunction with one of the commands (such as Add, Change, or Delete), the table is cleared before running the command.

-p

When used together with the Add command, the specified route is added to the registry and the IP routing table is initialized when the TCP/IP protocol is started. By default, the added routes will not be saved when starting the TCP/IP protocol. When used with the Print command, a permanent route list will be displayed. All other commands ignore this parameter. The location where permanent routes are stored in the registry is HKEY_LOCAL_MACHSYSTEMCurrentControlSetServicesTcpipParametersPersistentRoutes.

command Specifies the command to run. The following table lists the valid commands.

destination

Specifies the network destination address of the route. The destination address can be an IP network address (where the network address's host address bits are set to 0), which is the IP address for host routes or 0.0.0.0 for default routes.

mask

subnetmask

Specifies the netmask (also known as the subnet mask) associated with the network destination address. The subnet mask can be an appropriate subnet mask for the IP network address, 255.255.255.255 for the host route, or 0.0.0.0 for the default route. If omitted, subnet mask 255.255.255.255 is used. When defining a route, due to the relationship between the destination address and the subnet mask, the destination address cannot be more detailed than its corresponding subnet mask. In other words, if a bit of the subnet mask is 0, the corresponding bit in the destination address cannot be set to 1.

gateway

Specifies the previous or next hop IP address beyond the set of reachable addresses defined by the network target and subnet mask. For locally connected subnet routing, the gateway address is the IP address assigned to the connected subnet interface. For remote routes that are available through one or more routers, the gateway address is a directly reachable IP address assigned to an adjacent router.

metric

Specifies the integer value of the required hop count for the route (range is 1 to 9999), which is used to select and forward the destination in the packet among multiple routes in the routing table. The route with the best matching address. The selected route has the lowest number of hops. Hop count reflects the number of hops, path speed, path reliability, path throughput, and management attributes.

if inte***ce Specifies the interface index of the interface that the target can reach. Use the Route print command to display a list of interfaces and their corresponding interface indexes. You can use decimal or hexadecimal values ​​for the interface index. For hexadecimal values, add 0x in front of the hexadecimal number. When the if parameter is omitted, the interface is determined by the gateway address.

The Route command of Windows 98 does not support the -p parameter.

This command is available only when the TCP/IP protocol is installed as a component of the network adapter properties in the network connection.

4. Examples

Example 1: To display the complete content of the IP routing table, execute the following command:

route print

Example 2: To Display the routes starting with 10. in the IP routing table and execute the following command:

route print 10.*

Example 3: To add a default route with the default gateway address of 192.168.12.1, execute the following command:

route add 0.0.0.0 mask 0.0.0.0 192.168.12.1

Example 4: To add a route with a target of 10.41.0.0, a subnet mask of 255.255.0.0, and a next hop address of 10.27.0.1, execute the following command:

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1

Example 5: To add a route with a target of 10.41.0.0, subnet mask is 255.255.0.0, next hop address is 10.27.0.1 permanent route, execute the following command:

route -p add 10.41.0.0 mask 255.255.0.0 10.27.0.1

Example 6: To add a target of 10.41.0.0, subnet For a route with a mask of 255.255.0.0, a next hop address of 10.27.0.1, and a hop count of 7, execute the following command:

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7

Example 7: To add a destination of 10.41.0.0 and a subnet mask If the route is 255.255.0.0, the next hop address is 10.27.0.1, and the interface index is 0x3, execute the following command:

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 if 0x3

Example 8: To delete the target is 10.41.0.0 and the subnet mask is 255.255 .0.0 route, execute the following command:

route delete 10.41.0.0 mask 255.255.0.0

Example 9: To delete all routes starting with 10. in the IP routing table, execute the following command:

route delete 10.*

Example 10: To delete the target The next hop address of the route with subnet mask 255.255.0.0 is 10.41.0.0 and is changed from 10.27.0.1 to 10.27.0.25. Execute the following command:

route change 10.41.0.0 mask 255.255.0.0 10.27.0.25

Example 11: To add a static route let Everything with the target network segment 172.0.0.0 is forwarded to the route with the network address 172.25.25.1

route add 172.0.0.0 mask 255.0.0.0 172.25.25.1 metric 2 -p

相关学习推荐:linux视频教程

The above is the detailed content of How to use the route add command. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn