About the route command for the Linux routing table (GO)

Source: Internet
Author: User

  View the Linux kernel routing table  Use the following route command to view the Linux kernel routing table. # route Destination  gateway      genmask          flags Metric Ref use IFAC E 192.168.0.0   *                 255.255.255.0  u        0         0     0    eth0 169.254.0.0   *                 255.255.0.0      u        0         0     0    eth0 default        192.168.0.1   0.0.0.0       &NBS P      ug     0         0     0    eth0 The output item description output of the route command             Description Destination       Target network segment or host Gateway       &NB Sp   Gateway address, "*" indicates the destination is the network to which this host belongs, does not require routing Genmask         netmask Flags               tag some possible tags as follows: U-Route is the active H-target is a host N-Target when a network segment G-Route points to the Gateway R-recovery dynamic route generated table item D-by-routing background Program dynamically installs M-by-Route daemon modification!  -Deny routing Metric routing distance, number of relays required to reach the specified network (not used in the Linux kernel).  REF number of Route entry references (not used in the Linux kernel).  The number of times the use of this route entry is routed through the software lookup.  Iface the output interface corresponding to the route table entry. ***************************************************************************************************************   **************** 3 Types of Routes   Host routing host routing is a route record that points to a single IP address or host name in the routing table. The Flags field for host routing is H.  For example, in the following example, the local host passes the IP address of the 192.168.1.1 router to the host with an IP address of 10.0.0.10. Destination Gateway     genmask              flags   Metric Ref use IFAC E-----------     -------         -------          & nbsp        -----     ------   --- ---   -----10.0.0.10 &nbs P 192.168.1.1 255.255.255.255  uh       0         0     0     ET H0 Network Routing Network routing is the network that the host can reach. The Flags field for network routing is n.  For example, in the following example, the local host forwards packets sent to the network 192.19.12 to a router with an IP address of 192.168.1.1. Destination Gateway       genmask          flags Metric Ref use Iface-----------      -------           -------            & nbsp  -----   -----   --- ---   -----192.19.12   192.168.1.1  255.255.255.0  un     0 &nbsp ;      0     0      eth0 default routing when the host cannot find the destination host's IP address or network route in the routing table, the packet is sent to the default route (the default gateway). The Flags field for the default route is G.  For example, in the following example, the default route is a router with an IP address of 192.168.1.1. Destination Gateway      genmask Flags  metric Ref use Iface-----------     -------            -------       -----   ------ --- - --   -----default        192.168.1.1  0.0.0.0     UG     0 &nbsp ;       0    0      eth0 ********************************************************  *********************************************************************** Configure static Routes   The route command sets and views the routing table with the route command, and the command format for setting the kernel routing table is: # route [Add|del] [-net|-host] target [netmask Nm] [GW GW] [[Dev] If] its Middle: add: Adding a Routing rule del: Delete a routing rule-net: The destination address is a network-host: The destination address is a host target: Destination network or host Netmask: netmask for Destination address GW: Routing packet Gateway Dev: Route command for routing specified for route Use example added to host routing # route add-host 192.168.1.2 Dev eth0:0 # route add-host 10.20.30.148 GW 10.20.30.40 Add route to network # route add-net 10.20.30.40 netmask 255.255.255.248 eth0 # route add-net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41 # route add-net 192.168.1.0/24 eth1 Add default route # route add default GW 192.168.1.1 Delete route # Route del-host 192.168.1.2 Dev eth0:0 # route del-host 10.20.30.148 GW 10.20.30.40 # route del-net 10.20.30.40 Netmas K 255.255.255.248 eth0 # route del-net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41 # route Del-net 192.168.1.0/ Eth1 # route del default GW 192.168.1.1 *************************************************************************** ****************************************************  Set up Package forwardingThe default kernel configuration in CentOS already includes the routing feature, but by default it is not enabled at system startup. The Linux-enabled routing function can be achieved by adjusting the kernel's network parameters. To configure and adjust kernel parameters, you can use the Sysctl command.  For example, to turn on the packet forwarding feature of the Linux kernel, you can use the following command. # sysctl-w Net.ipv4.ip_forward=1 This setting, the current system can implement packet forwarding, but the next time you start the computer will be invalidated.  To make the next time you start the computer still valid, you need to write the following line to the configuration file/etc/sysctl.conf.  # vi/etc/sysctl.conf Net.ipv4.ip_forward = 1 Users can also use the following command to see if the current system supports packet forwarding. # sysctl Net.ipv4.ip_forward http://pda158.iteye.com/blog/2173154

Route (8) Linux Programmer ' s Manual ROUTE (8)

NAME
Route-show/manipulate The IP routing table

Synopsis
Route [-cfvnee]

Route [-v] [-A family] add [-net|-host] target [netmask Nm] [GW GW] [metric N] [MSS M] [window W] [Irtt I] [reject] [mod] [Dyn] [Reinstate] [[Dev] If]

Route [-v] [-A family] del [-net|-host] target [GW GW] [netmask Nm] [metric N] [[Dev] If]

Route [-v] [--version] [-h] [--help]

NOTE
This program is obsolete. For replacement check IP route.

DESCRIPTION
Route manipulates the kernel ' s IP routing tables. Its-primary use-is-to-set up-static routes to specific hosts or networks via a interface after it has been configured
With the Ifconfig (8) program.

When the Add or Del Options is used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables.

OPTIONS
-A family
Use the specified address family (eg ' inet '; use ' route--help ' for a full list).

-F operate on the kernel ' s FIB (Forwarding information Base) routing table. This is the default.

-c operate on the kernel ' s routing cache.

-V Select verbose operation.

-N Show numerical addresses instead of trying to determine symbolic host names. This was useful if you were trying to determine, the route to your nameserver have van-
Ished.

-E Use Netstat (8)-format for displaying the routing table. -ee would generate a very long line with all parameters from the routing table.

Del Delete a route.

Add add a new route.

Target the destination network or host. You can provide the IP addresses in dotted decimal or host/network names.

-net the target is a network.

-host the target is a host.

Netmask NM
When adding a network route, the netmask to be used.

GW GW Route packets via a gateway. Note:the specified gateway must be reachable first. This usually means so you had to set up a static route to the Gateway Before-
Hand. If you specify the address of one of the your local interfaces, it'll be used to decide about the interface to which the PAC Kets should is routed to. This is a
bsdism compatibility hack.

Metric M
Set the metric field in the routing table (used by routing daemons) to M.

MSS M sets MTU (Maximum transmission Unit) of the route to M bytes. Note that the current implementation of the route command does not allow the option to set the Maximum
Segment Size (MSS).

Window W
Set the TCP window size for connections over this route to W bytes. This is typically only used on ax.25 networks and with drivers unable to handle
Frames.

Irtt I set the initial round trip time (IRTT) for TCP connections over this route to I milliseconds (1-12000). This was typically only used on ax.25 networks. If omitted the
RFC 1122 Default of 300ms is used.

Reject install a blocking route, which a route lookup to fail. The example used to mask out networks before using the default route. This isn't for
Firewalling.

MoD, Dyn, reinstate
Install a dynamic or modified route. These flags is for diagnostic purposes, and is generally only set by routing daemons.

Dev If force the route to being associated with the specified device, as the kernel would otherwise try to determine the Devic E on it own (by checking already existing routes
and device specifications, and where the route is added to). In the most normal networks you won ' t need this.

If Dev if is the last option on the command line, the word dev could be omitted, as it's the default. Otherwise the order of the route modifiers (METRIC-NETMASK-GW
-dev) doesn ' t matter.

EXAMPLES
Route Add-net 127.0.0.0
Adds the normal loopback entry, using Netmask 255.0.0.0 (class A net, determined from the destination address) and Associa Ted with the ' Lo ' device (assuming this
Device is prviously set up correctly with Ifconfig (8)).

Route add-net 192.56.76.0 netmask 255.255.255.0 Dev eth0
Adds a route to the network 192.56.76.x via "eth0". The class C netmask modifier is not really necessary this because 192.* is a class C IP address. The word "dev"
Can is omitted here.

Route add default GW MANGO-GW
Adds a default route (which is used if no other route matches). All packets using the This route would be gatewayed through "MANGO-GW". The device which'll actu-
Ally is used for that route depends on how we can reach "MANGO-GW"-the static route to "MANGO-GW" would have a to is set up Before.

Route add Ipx4 sl0
Adds the route to the "Ipx4" host via the Slip interface (assuming, "ipx4" is the slip host).

Route add-net 192.57.66.0 netmask 255.255.255.0 GW ipx4
This command adds the net "192.57.66.x" to being gatewayed through the former route to the SLIP interface.

Route add-net 224.0.0.0 netmask 240.0.0.0 Dev eth0
This is a obscure one documented so people know how to do it. This sets all of the class D (multicast) IPs routes to go via "eth0". This is the correct normal config-
Uration line with a multicasting kernel.

Route add-net 10.0.0.0 netmask 255.0.0.0 reject
This installs a rejecting route for the private network "10.x.x.x."

OUTPUT
The output of the kernel routing table is organized in the following columns

Destination
The destination network or destination host.

Gateway
The gateway address or ' * ' if none set.

Genmask
The netmask for the destination net; ' 255.255.255.255 ' for a host destination and ' 0.0.0.0 ' for the default route.

Flags Possible flags include
U (Route is up)
H (target is a host)
G (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 the ' distance ' to the target (usually counted in hops). It is not a used by recent kernels and may be needed by routing daemons.

Ref number of references to the this route. (not used in the Linux kernel.)

Use Count of lookups for the route. Depending on the of-f and-c this would be either route cache misses (-f) or hits (-c).

Iface Interface to which packets for this route would be sent.

MSS Default maximum segement size for the TCP connections over the this route.

Window Default window size for TCP connections over this route.

Irtt Initial RTT (Round trip time). The kernel uses this to guess is about the "best" TCP protocol parameters without waiting on (possibly slow) answers.

HH (Cached only)
The number of ARP entries and cached routes that refer to the hardware header caches for the cached route. This would be-1 if a hardware address is not needed for the
interface of the cached route (e.g. Lo).

ARP (Cached only)
Whether or not, the hardware address for the cached route was up to date.

FILES
/proc/net/ipv6_route
/proc/net/route
/proc/net/rt_cache

See ALSO
IP (8)

History
Route for Linux is originally written by Fred N. van Kempen, <[email protected]> and then modified by Johannes Stil Le and Linus Torvalds for Pl15. Alan Cox Added
The MSS and window options for Linux 1.1.22. Irtt support and merged with Netstat from Bernd eckenfels.

AUTHOR
Currently maintained by Phil Blundell <[email Protected]>.

About the route command for the Linux routing table (GO)

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.