路由表

linux下通过route可以查看本地路由表:

Kernel IP routing table
Destination      Gateway        
  Genmask        
  Flags   Metric   Ref      Use    Iface
default             localhost      
  0.0.0.0        
   UG      0     
  0       
  0      eth1
link-local          *              
   
255.255.0.0      
U       1000  
  0       
  0       eth1
192.168.1.0       *                   255.255.255.0    U         2     
  0          0     eth1

Destination为目的网络地址,Genmask是子网掩码,Gateway是下一跳地址,Metric是权重(优先级),Iface是发送接口。

Flags中U代表此条目有效(可以禁用某些条目),G标志表示此条目的下一跳地址是某个路由器地址,没有G标志的条目表示目的网络地址是与本机接口直接相连的网络,不必经过路由器转发,因此下一跳地址记为*号。

如果要发送一个数据包,首先该数据包的目的地址首先与子网掩码做与运算,得到IP地址后与目的地址比较,相等则从此条路由的接口Iface将数据包发送出去;

不相等,与第二行的子网掩码做与运算,比对目的地址。

若与前面几个路由条目都不匹配,那么就按缺省路由条目的接口把数据包发送出去,让下个路由器按它的路由表决定下一跳地址。

route命令

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]

When the add or del options are used, route
modifies the routing tables.  Without
these options, route displays the current contents of the routing tables.

-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 is useful if you are trying to determine why the route to your
nameserver has vanished.

-e     use netstat(8)-format for
displaying the routing table.  -ee will 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 IP addresses in
dotted decimal or host/network names.

目标网络,目的IP,即数据包的目的地址。

-net   the target is a network.

-host  the target is a host.

netmask
NM
       when adding a network route, the netmask
to be used. 路由表中的掩码,作用于目的IP。

gw
GW
  route
packets via a gateway.  NOTE: The
specified gateway must be reachable first.

This
usually means that you have to set up a static route to the gateway beforehand.

If you specify the address of one of your local interfaces,
it will be used to decide about the interface to which the packets should be
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
         set the TCP Maximum Segment Size (MSS)
for connections over this route to M bytes.

The
default is the device MTU minus headers, or a lower MTU when path mtu discovery
occurred.

This
setting can be used to force smaller TCP packets on the other end when path mtu
discovery does not work

(usually
because of misconfigured firewalls that block ICMP Fragmentation Needed)

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 back
to back frames.

irtt
I
             set
the initial round trip time (irtt) for TCP connections over this route to I
milliseconds (1-12000).

This
is typically only used on AX.25 networks. If omitted the RFC1122 default of
300ms is used.

reject            install a blocking
route, which will force a route lookup to fail.

This
is for example used to mask out networks before using the default route.  This is NOT for firewalling.

mod,
dyn, reinstate
   install
a dynamic or modified route. These flags are for diagnostic purposes, and are
generally only set by routing daemons.

dev
If
          force the route to be associated with the specified device,
as the kernel will otherwise try to determine the device on its own

(by
checking already existing routes and device specifications, and where the route
is added to). In most normal networks you won't need this.

If dev  If 
is the last option on the command line, the word dev may be omitted, as it's the default. Otherwise the order of the
route modifiers (metric - netmask - gw -dev) doesn't matter.

1)   
网络接口dev if和网关gw GW是等价的,指定一个参数即可,系统会决定数据包应该发向哪个接口或哪个网关。

2) target即IP有两种表示方法:ip+netmask或ip/prefix,两者等价,若指定ip为192.168.10.0/24,则不要添加netmask参数。注:这里的IP为网段(不含主机)。

3) -net和-host区别是-net指定网段;-host用于指定具体主机IP,是一个确定的IP。

route应用

1. 局域网的网络地址192.168.1.0/24,局域网络连接其他网络的网关地址是192.168.1.1。主机192.168.1.20访问172.16.1.0/24网络的路由。

route add -net 172.16.1.0 gw 192.168.1.1 netmask
255.255.255.0 metric 1

route add -net 172.16.1.0/24 gw 192.168.1.1

2. 缺省网关路由

默认网关就是数据包不匹配任何设定的路由规则,最后流经的地址关口!

route add default gw 192.168.10.1

route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.10.1

route add default gw eth0

route add default gw dev eth0

此处的default可理解为target,即目标网络。

3. 删除默认网关

route del default

删除当前默认网关,在路由表destination项标记为“default”或0.0.0.0 的路由条目。

4. 指定数据包发送的网络接口

route add -net 127.0.0.0 netmask 255.0.0.0 dev lo

回环网络lo增加路由。

5. 增加一条拒绝路由

route add -net 10.0.0.0 netmask 255.0.0.0 reject

路由表及route使用的更多相关文章

  1. 关于Linux路由表的route命令

    转自:http://www.cnblogs.com/gunl/archive/2010/09/14/1826234.html 查看 Linux 内核路由表 使用下面的 route 命令可以查看 Lin ...

  2. 关于Linux路由表的route命令(转)

    查看 Linux 内核路由表 使用下面的 route 命令可以查看 Linux 内核路由表. # route Destination  Gateway      Genmask          Fl ...

  3. 配置主机路由表(route)(两)

    我们谈到了路由在互联网为基础的时间问题,必须有一个路径之间的两个主机可通信 TCP/IP 合约,否则就不能是有线啊! 一般来说.只要有一个网络接口,的接口将产生的路由.例如,在哥斯达黎加的内部主机鸟有 ...

  4. Linux路由表信息-route命令

    使用命令 :route route 命令    显示和设置Linux路由表 -A:设置地址类型: -C:打印将Linux核心的路由缓存: -v:详细信息模式: -n:不执行DNS反向查找,直接显示数字 ...

  5. linux 路由表设置 之 route 指令详解

    使用下面的 route 命令可以查看 Linux 内核路由表. # route Destination     Gateway         Genmask Flags Metric Ref     ...

  6. linux 路由表设置 之 route 指令详解【转】

    转自:http://blog.csdn.net/vevenlcf/article/details/48026965 目录(?)[-] 种路由类型 主机路由 网络路由 默认路由 配置静态路由 route ...

  7. Linux 路由表详解及 route 命令详解

    参考资料 Linux 内核的路由表 通过 route 命令查看 Linux 内核的路由表: [root@VM_139_74_centos ~]# route Kernel IP routing tab ...

  8. 10.4 route:显示或管理路由表

    route命令 可以显示或管理Linux系统的路由表,route命令设置的路由主要是静态路由. 路由的概念     计算机与计算机之间的数据传输必须得经由网络,而网络可以通过直接连接两台计算机的方式或 ...

  9. window route 命令

    使用 Route 命令行工具查看并编辑计算机的 IP 路由表.Route 命令和语法如下所示: route [-f] [-p] [Command][Destination] [mask Netmask ...

随机推荐

  1. 更改虚拟内存(使用于win7、win8系统)

    在使用电脑的过程中你肯定有这样的抱怨吧!电脑为什么越来越慢?C盘为什么越来越小?我们都非常清楚:C盘剩余空间量的大小,很大程度上决定着我们在使用电脑的过程中程序运行的速度.随着电脑软件越装越多,尽管我 ...

  2. Windows CMD常用命令大全 运行命令

    http://blog.163.com/lixunhuan@126/blog/static/122060620075124142658/ CMD命令大全 net use \\ip\ipc$ " ...

  3. 理解over()函数

    1.1.两个order by的执行时机分析函数(以及与其配合的开窗函数over())是在整个sql查询结束后(sql语句中的order by的执行比较特殊)再进行的操作, 也就是说sql语句中的ord ...

  4. jquery中 $ 和 jQuery 及 $() 的区别

    用过jquery的人都知道,jquery有两种用法,一种是$,还有一种是jQuery,那么这两种方式在使用上有什么区别呢? 答案是这两种用法没什么区别,只是别名而已,用$要比jQuery简短一些.方便 ...

  5. JMeter学习笔记--详解JMeter逻辑控制器

    JMeter使用逻辑控制器来决定采样器的处理顺序 简单控制器(Simple Controller):存储设备(将某些采样器归组) 循环控制器(Loop Controller:设置循环次数 仅一次控制器 ...

  6. Error_Unix Shell_syntax error near unexpected token `fi'

    2014-06-19 BaoXinjian 1. Issue 调用如下Shell脚本时出现错误syntax error near unexpected token `fi'

  7. Linux内核(3) - 分析内核源码如何入手(下)

    下面的分析,米卢教练说了,内容不重要,重要的是态度.就像韩局长对待日记的态度那样,严谨而细致. 只要你使用这样的态度开始分析内核,那么无论你选择内核的哪个部分作为切入点,比如USB,比如进程管理,在花 ...

  8. python 小游戏之摇骰子猜大小

    最近学习Python的随机数,逻辑判断,循环的用法,就想找一些练习题,比如小游戏猜大小,程序思路如下: 开发环境:python2.7 , 附上源代码如下: 摇骰子的函数,这个函数其实并不需要传任何参数 ...

  9. struts2.xml中所有constant详解--大全

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-/ ...

  10. 转 CAS实现SSO单点登录原理

    原文链接   http://m.blog.csdn.net/hxpjava1/article/details/74019017 CAS 简介 1. 1.1.  What is CAS ? CAS (  ...