Route command parameters detailed, linux add delete routing command __linux

Source: Internet
Author: User

The route command for the Linux system is used to display and manipulate the IP routing table (show/manipulate the IP routing table). To achieve communication between two different subnets, you need a router that connects two networks, or a gateway that is located in two networks. In a Linux system, routing is often set up to address the following issues: The Linux system has a gateway in a local area network that allows the machine to access the Internet, so it needs to set the IP address of the machine to the default route of the Linux machine. It is important to note that the route command to add routes directly under the command line is not persisted, and that the route is invalidated when the network adapter is rebooted or the machine is restarted, and the route command can be added to the/etc/rc.local to ensure that the route 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 manipulate the kernel-based IP routing table, and its primary role is to create a static route that specifies a host or network through a network interface, such as a eth0. When you use the "add" or "del" parameters, the routing table is modified, and if there are no parameters, the current contents of the routing table are displayed.

3. Command parameters:

-C Display more information

-N does not resolve names

-V Display detailed processing information

-F Display Send message

-C Display Routing cache

-F Clears the routing table for all gateway portals.

-P makes the route permanent when used with the add command.

Add: Adds a new route.

Del: Deletes a route.

-net: The destination address is a network.

-host: The destination address is a host.

Netmask: When you add a network route, you need to use a netmask.

GW: Routing packets through gateways. Note that the gateway you specify must be able to reach.

Metric: Sets the route hop count.

command to specify the commands 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 destination.

Gateway specifies the forward or next-hop IP address that the address set and subnet mask of the network destination definition can reach.

Metric metric Specifies an integer cost value (from 1 to 9999) for the route, which is available when you select multiple routes in the routing table (which matches the destination address of the forwarding packet).

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 feature of the route Print command. You can use decimal or hexadecimal values for interface indexing.

4. Use instance:

Example 1: Show current Route

command:

Route

Route-n

Output:

[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

Description:

The first line indicates that the host network has an address of 192.168.120.0, and if the data transfer target is communicating within the local area network, the packet can be forwarded directly via eth0;

Line four indicates that data transfer is intended to access the Internet, then the interface eth0 to send packets to the gateway 192.168.120.240

Where flags is the routing flag that marks the status of the current network node.

Flags Flag Description:

U up indicates that this route is currently in the starting state

H host, which indicates that this gateway is a host

G Gateway, which indicates that this gateway is a router

R reinstate Route, using dynamic routing to reinitialize a route

D dynamically, this route is dynamically written to

M Modified, this route is dynamically modified by the routing daemon or the guide

! Indicates that this route is currently off state

Note:

Route-n (-n indicates that the name is not resolved, and the list speed is faster than route)

Example 2: add gateway/settings Gateway

command:

Route add-net 224.0.0.0 netmask 240.0.0.0 Dev eth0

Output:[root@localhost ~] # route add-net 224.0.0.0 netmask 240.0.0.0 Dev eth0
[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
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
224.0.0.0 * 240.0.0.0 U 0 0 0 eth0
Default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0

[Root@localhost ~]#

Description:

Add a route to 244.0.0.0

Example 3: Shielding a route

command:

Route add-net 224.0.0.0 netmask 240.0.0.0 Reject

Output:

[root@localhost ~] # route add-net 224.0.0.0 netmask 240.0.0.0 Reject
[Root@localhost ~] #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.