Use the Linux route command

Source: Internet
Author: User

Note: The route command prints and operates the ip route table.

Description: The route operation is based on the kernel ip route table. Its main function is to create a static route so that a specified master machine or network can pass through a network interface, such as eth0. When the "add" or "del" parameter is used, the route table is modified. If no parameter exists, the current content of the route table is displayed.

Parameter description: add a new route.
Del: delete a route.
-Net: the destination address is a network.
-Host: The target address is a host.
Netmask: when adding a network route, you need to use the network mask.
Gw: Route data packets through the gateway. Note that the gateway you specified must be accessible.
Metric: set the number of Route hops.

Instance:
1. route add-net 192.168.2.0 netmask 255.255.255.0 dev eth0
Add a route to the 192.168.2.0 network, specify the network mask as 255.255.255.0, and the packet is transmitted through the network interface eth0.
2. route add-net 192.57.66.0 netmask 255.255.255.0 gw 192.168.2.1
Add a route to the 192.57.66.0 network, specify the network mask as 255.255.255.0, and the data packet passes through the gateway address 192.168.2.1.
3. route add-host 192.57.66.200 gw 192.168.2.1
All packets destined for the 192.57.66.200 host are sent to the gateway address 192.168.2.1.
4. route add default gw 192.168.1.1
Add a default gateway, and all data packets will be forwarded to 192.168.1.1.

Route table description:
View routes
# Route-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.57.66.200 192.168.1.1 255.255.255.255 UGH 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
Destination: target network or host.
Gateway: the Gateway address.
Genmask: The network mask of the target network. "255.255.255.255" indicates a host. "0.0.0.0" indicates the gateway.
Flags: flag.
U and route are enabled.
H. The target is a host.
G. Use the gateway.

Related Article

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.