Detailed explanation of the route add command

The route add command is used to add a route rule to the local routing table. This command defines the route rule by specifying the destination network address, subnet mask, gateway, and outgoing interface.

The specific command format is as follows:

add a route to target network address with subnet mask, gateway, and specify the output interface metric.

The meanings of each parameter are as follows:

  1. Destination Network Address: The target network address to which the routing rule needs to be added, usually an IP address or a network address.
  2. Subnet mask: Used to specify the subnet mask of the target network address, determining the scope of the target network.
  3. Gateway: Specifies the next hop IP address, where the data packet should be sent before being forwarded.
  4. Metric: used to specify the measurement value of a route, representing the priority of the route. When multiple route rules match, the system will choose the route with the lowest metric value for forwarding.
  5. Output interface: the network interface through which specified data packets are sent.

Here is a specific example:

Add a route for 192.168.0.0 with a subnet mask of 255.255.255.0 through gateway 192.168.1.1 with a metric of 1 on interface 2.

The command above adds a rule to the local routing table, sending packets with a destination network address of 192.168.0.0/24 to the gateway 192.168.1.1 through interface 2, with a metric value of 1.

It is important to note that the “route add” command only adds temporary route rules in the current session, and these rules will be cleared after the system is restarted. If you want to permanently save route rules, you can use the “route -p add” command to add persistent route rules.

广告
Closing in 10 seconds
bannerAds