Linux routing command operation example summary

  

When you need to display the routing table in the Linux system operation, you will be exposed to the route command, then what is the usage of the route command? The following system home Xiaobian will give you an example of how to use the route command in Linux. Interested friends may wish to understand it.

In the Linux system, set the route usually to address the following issues: the Linux system in a local area network, local area network has a gateway that allows the machine to access Internet, you will need these machines The IP address is set to the default route of the Linux machine. It should be noted that the route is directly executed on the command line to add a route, which will not be saved permanently. When the network card is restarted or the machine is restarted, the route is invalid; you can add the route command in /etc/rc.local to ensure that the route is guaranteed. This route setting is permanently valid.

1. Command Format:

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]

2. Command Function:

The Route command is used to operate the kernel-based ip routing table. Its main function is to create a static route to 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. If there is no parameter, the current content of the routing table is displayed.

3. Command parameters:

-c Show more information

-n Do not resolve names

-v Display detailed processing information

-F Display sending information

-C Display Route Cache

-f Clears the routing table for all gateway entries.

-p Makes the route permanent when used with the add command.

add: Add a new route.

del: Delete a route.

-net: The destination address is a network.

-host: The destination address is a host.

netmask: When adding a network route, you need to use a network mask.

gw: Routing packets through the gateway. Note that the gateway you specify must be reachable.

metric: Set the number of route hops.

Command Specify the command you want to run (Add/Change/Delete/Print).

Destination Specifies the network destination for this route.

mask Netmask Specifies the network mask (also known as the subnet mask) associated with the network target.

Gateway Specifies the forward or next hop IP address that the address set and subnet mask defined by the network target can reach.

metric Metric Specifies an integer cost value for the route (from 1 to 9999) that can be used when selecting among multiple routes in the routing table that best matches the forwarded packet destination address.

If Interface specifies an interface index for an interface that can access the target. To get a list of interfaces and their corresponding interface indexes, use the display function of the route print command. Interface indexing can be done using decimal or hexadecimal values.

4. Example:

Instance 1: Display Current Route

Command:

The code is as follows:

route

route -n

Output:

The code is as follows:

[root@localhost ~]# route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.120.0 * 255.255.255.0 U 0 0 0 eth0

e192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0

10.0 .0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0

default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0

[root@localhost ~]# route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.120.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0

10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0

0.0.0.0 192.168.120.240 0.0.0.0 UG 0 0 0 Eth0
Previous123Next page Total 3 pages

Copyright © Windows knowledge All Rights Reserved