标题: Linux route(转载) [打印本页] 作者: jpchen 时间: 2016-3-7 11:14 标题: Linux route(转载) Linux route
一、简介
Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table)。要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两个网络的网关来实现。在Linux系统中,设置路由通常是为了解决以下问题:该Linux系统在一个局域网中,局域网中有一个网关,能够让机器访问Internet,那么就需要将这台机器的IP地址设置为Linux机器的默认路由。要注意的是,直接在命令行下执行route命令来添加路由,不会永久保存,当网卡重启或者机器重启之后,该路由就失效了;可以在/etc/rc.local中添加route命令来保证该路由设置永久有效。
route add default gw 192.168.0.1
route del default gw 192.168.0.1
四、输出详解
复制代码
route命令输出的路由表字段含义如下:
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:总共有多个旗标,代表的意义如下:
o U (route is up):该路由是启动的;
o H (target is a host):目标是一部主机 (IP) 而非网域;
o G (use gateway):需要透过外部的主机 (gateway) 来转递封包;
o R (reinstate route for dynamic routing):使用动态路由时,恢复路由资讯的旗标;
o D (dynamically installed by daemon or redirect):已经由服务或转 port 功能设定为动态路由
o M (modified from routing daemon or redirect):路由已经被修改了;
o ! (reject route):这个路由将不会被接受(用来抵挡不安全的网域!)
o A (installed by addrconf)
o C (cache entry)
Metric 距离、跳数。暂无用。
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 不用管,恒为0。
Number of references to this route. (Not used in the Linux ker-nel.)
Use 该路由被使用的次数,可以粗略估计通向指定网络地址的网络流量。
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 接口,即eth0,eth0等网络接口名
Interface to which packets for this route will be sent.