Linux Command learning: Route command

Source: Internet
Author: User

Copyright Notice Update:2017-05-20
Bo Master: Luckyalan
Contact: [Email protected]
Statement: Draft not forget to dig well man, reproduced please indicate the source!

1 Article Introduction

This article describes the route command under Linux.

2. Development platform

Linux Systems

3. Reading instructions

No

4 Article body

The route command for the Linux system is used to display and manipulate the IP routing table. To achieve communication between two different subnets, you need a router that is connected to two networks, or a gateway to two networks. In Linux systems, routing is usually done to address the problem that the Linux system has a gateway in a local area network that allows the machine to access the Internet, so the IP address of the machine needs to be set to the default route of the Linux machine. Note that the route command is executed directly at the command line to add the route, is not persisted, and is invalidated when the NIC is restarted or the machine restarts, and the route command can be added to the/etc/rc.local to ensure that the routing setting is permanent.

4.1 Command 4.1.1 Command

Command format: route [-f] [-p] [command [Destination] [Mask Netmask] [Gateway] [metric metric]] [if Interface]]
Command function: The route command is used for operations based on the kernel IP routing table, and its primary function is to create a static route that lets you 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, and if there are no parameters, the current contents of the routing table are displayed.

4.1.2 Command Parameters

-C Show more information

-N does not parse name

-V displays detailed processing information

-F Display Send message

-C Show Route cache

-F Clears the routing table for all gateway portals.

-P is used with the add command to make the route permanent.

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: Route packets through the gateway. Note that the gateway you specify must be able to be reached.

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.

The mask Netmask Specifies the network mask (also known as the subnet mask) that is associated with the network destination.

The Gateway specifies the address set and subnet mask defined by the network destination to reach the forward or next hop IP address.

The metric metric specifies an integer cost value for the route (from 1 to 9999) that can be used when the routing table (which matches the destination address of the forwarded packet) is selected in multiple routes.

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

4.2 Command Instance 4.2.1 show current route

Command: route/route-n

The second line indicates that the host network address is 192.168.204.0, if the data transmission target is in the local area network communication, you can forward the packet directly through the eth0;

The first line indicates that the data transfer is intended to access the Internet, and the packet is sent to the gateway 192.168.204.1 by the interface eth0.

A description of the flags flag;

    • U up indicates that this route is currently in the boot state
    • H host, which indicates that the gateway is a host
    • G Gateway, which indicates that this gateway is a router
    • R reinstate route, re-initialized with dynamic routing
    • D dynamically, this route is dynamically written to
    • M Modified, this route is dynamically modified by the route daemon or director
    • ! Indicates that this route is currently in a closed state

Note: the-N in Route-n indicates that the name is not resolved and is listed faster than the route.

4.2.2 Adding gateways/Setting up gateways

Command: route Add -net 224. 0. 0. 0 netmask . 0. 0. 0 Dev eth0
Description: Add a route to 244.0.0.0

4.2.3 Masking a route

Command: route Add -net 224. 0. 0. 0 netmask . 0. 0. 0 Reject
Description: Added a shielded route with the destination address of 224.x.x.x to be rejected

4.2.4 deleting Route Records

Command: Route del-net 224. 0. 0. 0 netmask . 0. 0. 0
Command: Route del-net 224. 0. 0. 0 netmask . 0. 0. 0 Reject

4.2.5 deleting and adding a default gateway

Add default gateway: route Add default GW 192. 168. . 254 Dev eth0
Delete Default gateway: route del default GW 192. 168. . 254 Dev eth0

5 References

1. This article refers to the "one Linux command per day": Route command

END

Linux Command learning: Route command

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.