Use Linux route

Source: Internet
Author: User

The route command is used to display and operate IP Route tables. To achieve communication between two different subnets, you need a router that connects two networks or a gateway that is located in both networks. In Linux, routing is usually set to solve the following problems: the Linux system has a gateway in a LAN that allows machines to access the Internet, then you need to set the IP address of this machine to the default route of the Linux machine. Note that you can directly execute the route command on the command line to add a route. The route will not be permanently saved. When the NIC is restarted or the machine is restarted, the route will become invalid; you can go to/etc/rc. add the route command to local to ensure that the route settings are permanently valid.

Format: Route
Format:/sbin/route
Displays the current routing table ).
When using a non-root user, you must use the full path to execute the route command.

The meanings of the route table fields output by the route command are as follows:
Destination target
The destination network or destination host. Target network or target host.

Gateway
The gateway address or '*' If none set. gateway address, if not, an asterisk is displayed.

genmask network mask
The netmask for the destination net; '255. 255.255 'For A
host destination and '0. 0.0.0 'for the default route.

flags possible flags include flag, commonly used U and G.
U (route is up) routing enabled
H (target is a host) Target Host
G (use gateway) use gateway
r (reinstate route for Dynamic Routing)
D (dynamically installed by daemon or redirect)
M (Modified from routing daemon or redirect)
A (installed by addrconf)
C (cache entry)
! (Reject route)

Metric distance and number of hops. Useless.
The 'distance 'to the target (usually counted in hops). It is
Not used by recent kernels, but may be needed by routing Dae-
Mons.

Ref is not required. The constant value is 0.
Number of references to this route. (not used in the Linux Ker-nel .)

Use the number of times this route is used to roughly estimate the network traffic to the specified network address.
Count of lookups for the route. Depending on the use of-F and
-C this will be either route cache misses (-F) or hits (-C ).

Iface interface, that is, network interface names such as eth0 and eth0
Interface to which packets for this route will be sent.

Format: route-n
Format:/sbin/route-n
Used to print the route table. The-N parameter is used to print the IP address directly without printing the host name in the output information.

Format: Route add default GW {IP-ADDRESS} {interface-name}
Used to set the default route, where,
Parameter {IP-ADDRESS): used to specify the IP address of the router (GATEWAY;
Parameter {interface-name}: Specifies the interface name, for example, eth0. Use/sbin/ifconfig-a to display all interface information.

Example: Route add default GW mango

Format: Route add-net {network-address} netmask {netmask} Dev {interface-name}
The routing rules added to the specified network.
Parameter {network-address}: used to specify the network address
Parameter {netmask}: used to specify the subnet mask
Parameter {interface-name}: Specifies the interface name, for example, eth0.

Example 1: Route add-net 192.56.76.0 netmask 255.255.255.0 Dev eth0
Example 2: Route add-net 224.0.0.0 netmask 240.0.0.0 Dev eth0

Format: Route add-net {network-address} netmask {netmask} reject
Set to inaccessible to the specified network to avoid connection to the network addressProgramAfter a long wait, you can see that the network is inaccessible.

Example: Route add-net 10.0.0.0 netmask route 0.0.0 reject

Format: Route del-net {network-address} netmask {netmask} Dev {interface-name}
Format: Route del-net {network-address} netmask {netmask} reject
Used to delete route settings. The method specified by the parameter is similar to route add.

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.