Linux route, linuxroute
I. Introduction
The route command in Linux is used to display and operate the IP route 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 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.
Ii. Routing knowledge
1) Static Routing
Static Routing is a route set manually.
For example, ip route 192.168.1.1 255.255.255.255 192.168.1.254, this static route means to forward all IP data destined for 192.168.1.1 to 192.168.1.254.
2) default route
The default route is used only when no other routing rules match. For example, ip route 0.0.0.0 0.0.0.0 192.168.1.1 indicates that if other routing rules do not match, data is forwarded to 192.168.1.1.
3) Static default route
Generally, the default route is static.
4) Dynamic default route
What is the difference between this and static default routing? For example, there is a star topology where R1 is the core router, while the remaining R2 and R3 are the branches. If R1 wants to tell the branch router that the path cannot be found to reach a remote network, all data is forwarded to the remote network through the core router. However, when a new router is added to the network topology, the router can also find the default route on the core router through the core router. The default route at this time is dynamic (for example: all routers that can dynamically obtain the network of the core router can have such a default route, as shown in D * for the network of the kernel router)
Iii. Instances
1) view the current route
route –n
2) Add/shield/delete a route
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0route add -net 224.0.0.0 netmask 240.0.0.0 rejectroute del -net 224.0.0.0 netmask 240.0.0.0
3) Add/Delete the Default Gateway
route add default gw 192.168.0.1route del default gw 192.168.0.1
Iv. Detailed output
The meaning of The route table field output by The route command is as follows: Destination target The destination network or destination host. Target network or target host. Gateway 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; '2017. 255.255 'for a host destination and '0. 0.0.0 'for the default route. flags: there are multiple flag in total, which indicates that o U (route is up): the route is started; o H (target is a host ): target is a host (IP) rather than a domain; o G (use gateway): packets need to be transferred through an external host (gateway); o R (reinstate route for dynamic routing ): when using dynamic routing, restore the flag of routing information; o D (dynamically installed by daemon or redirect) M (modified from routing daemon or redirect): The route has been modified; o! (Reject route): this route will not be accepted (used to resist insecure domains !) O A (installed by addrconf) o C (cache entry) 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, and The constant 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, to which packets for this route will be sent.
Reference: http://www.cnblogs.com/peida/archive/2013/03/05/2943698.html