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] ....].
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!

The five core components of the Linux operating system are: 1. Kernel, 2. System libraries, 3. System tools, 4. System services, 5. File system. These components work together to ensure the stable and efficient operation of the system, and together form a powerful and flexible operating system.

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools
