分享
 
 
 

Cisco IOS Cookbook 中文精简版第五章IP路由

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

<!--[if !supportLists]-->第五章 <!--[endif]-->IP路由

5.1. 查找路由条目

提问 在路由表中查找特定的路由条目

回答

Router>show ip route 172.25.100.15

Routing entry for 172.25.100.0/24

Known via "ospf 55", distance 110, metric 11, type inter area

Redistributing via ospf 55

Last update from 172.25.1.1 on Ethernet0, 2d12h ago

Routing Descriptor Blocks:

* 172.25.1.1, from 172.25.1.1, 2d12h ago, via Ethernet0

Route metric is 11, traffic share count is 1

注释 路由器在路由表中查找路由条目的原则是最长匹配,所以例子中虽然查找的是172.25.200.15但是由于没有这条特定的路由,显示的结果是最长匹配的172.15.100.0/24。假如没有任何一条匹配只能使用缺省路由,会出现下面信息

Router> show ip route 172.15.101.5

% Network not in table

注重的是这里都是无类路由,假如有类的就不一样了

5.2. 查找特定类型的路由条目

提问 在路由表中查找相同类型的路由条目

回答

Router>show ip route static

192.168.1.0/32 is subnetted, 1 subnets

S 192.168.1.1 [1/0] via 172.25.1.4

还有一个更有用的命令

Router>show ip route summary

IP routing table name is Default-IP-Routing-Table(0)

Route Source Networks Subnets Overhead Memory (bytes)

connected 0 3 328 432

static 1 0 64 144

ospf 55 1 3 256 576

Intra-area: 1 Inter-area: 2 External-1: 1 External-2: 0

NSSA External-1: 0 NSSA External-2: 0

internal 2 2328

Total 4 6 648 3480

注释 通过显示路由表的统计情况来了解当前路由器的路由条目,也可以用来以后的比对

5.3. 各种掩码的转换

注释 脚本略去,建议使用Boson提供的免费转换工具

5.4. 使用静态路由

提问 配置静态路由

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#ip route 10.35.15.5 255.255.255.255 Ethernet0 (permanent选项可以使此条目一直存在于路由表中,而不管下一跳的可达性)

Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2 (permanent)

Router(config)#end

Router#

也可以给路由条目打上标签

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2 tag 36291

Router(config)#end

Router#

注释 在类似以太网这种多路访问的网络中建议使用下一跳为地址而不是接口。正常情况下路由器对静态路由的下一跳有效性的检查是一分钟,在12.3(10)以后增加了下面的命令可以对此时间进行调整Router(config)#ip route static adjust-time 30。对静态路由打tag用于路由再发布时的区分

5.5. 浮动静态路由

提问 当动态路由出问题的时候使用静态路由作为备份

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#ip route 10.0.0.0 255.0.0.0 172.16.1.1 190 (下一跳也可以触发一个拨号接口)

Router(config)#end

Router#

注释 通过调整治理距离的方式来进行路由备份,不过要注重的是治理距离只适合在相同路由的情况下,路由条目的最长匹配是第一位的。另外在不同厂商设备互联的时候,调整治理距离一定要设置合理。

5.6. 基于源地址的策略路由

提问 根据源地址的不同选择不同的路径

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#Access-list 1 permit 10.15.35.0 0.0.0.255

Router(config)#access-list 2 permit 10.15.36.0 0.0.0.255

Router(config)#interface Ethernet0

Router(config-if)#ip address 10.15.22.7 255.255.255.0

Router(config-if)#ip policy route-map Engineers

Router(config-if)#ip route-cache policy

Router(config-if)#exit

Router(config)#route-map Engineers permit 10

Router(config-route-map)#match ip address 1

Router(config-route-map)#set ip next-hop 10.15.27.1

Router(config-route-map)#exit

Router(config)#route-map Engineers permit 20

Router(config-route-map)#match ip address 2

Router(config-route-map)#set interface Ethernet1

Router(config-route-map)#end

Router#

注释 缺省情况下route map的最后一句都是deny all,这样不符合route map规则的数据包都会按照正常的路由表进行转发。set ip next-hop verify-availability命令提供了对下一跳的验证,不过是基于CDP的,所以假如使用此命令需要打开CDP,最好同时调整时长,究竟缺省是180秒。在使用策略路由时会在排错时增加难度,因为缺省对于本路由器发出的数据包可以绕过route map这样会造成错觉。

5.7. 基于应用的策略路由

提问 根据不同的应用来选择不同的路径

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#access-list 101 deny tcp 10.15.25.0 0.0.0.255 any eq www

Router(config)#access-list 101 permit tcp any any eq www

Router(config)#interface Ethernet0

Router(config-if)#ip address 10.15.22.7 255.255.255.0

Router(config-if)#ip policy route-map Websurfers

Router(config-if)#ip route-cache policy

Router(config-if)#exit

Router(config)#route-map Websurfers permit 10

Router(config-route-map)#match ip address 101

Router(config-route-map)#set ip next-hop 10.15.27.1

Router(config-route-map)#exit

Router(config)#route-map Websurfers permit 20

Router(config-route-map)#set ip default next-hop 10.15.26.1

Router(config-route-map)#end

Router#

对于本设备的发出的数据包也使用策略路由

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#ip local policy route-map dlswtraffic

Router(config)#access-list 103 permit tcp any any eq 2065

Router(config)#access-list 103 permit tcp any eq 2065 any

Router(config)#route-map dlswtraffic permit 10

Router(config-route-map)#match ip address 103

Router(config-route-map)#set ip next-hop 10.15.27.3

Router(config-route-map)#end

Router#

注释 正常情况下假如所有定义的下一跳都不存在的情况下会使用路由表来查询,假如路由表没有此定义会使用缺省路由,这时候你可以使用set ip default next-hop来定义一个不同的缺省路由

5.8. 策略路由检查

提问 检查所应用的策略路由

回答

Router>show ip policy

Interface Route map

local dlswtraffic

Ethernet0 Websurfers

Serial0 High-priority

Router>show route-map

route-map High-priority, permit, sequence 10

Match clauses:

ip address (access-lists): 101

Set clauses:

ip next-hop 10.15.27.1

Policy routing matches: 0 packets, 0 bytes

route-map Websurfers, permit, sequence 10

Match clauses:

ip address (access-lists): 102

Set clauses:

ip next-hop 10.15.27.1

Policy routing matches: 0 packets, 0 bytes

route-map Websurfers, permit, sequence 20

Match clauses:

Set clauses:

ip default next-hop 10.15.26.1

Policy routing matches: 4 packets, 531 bytes

route-map dlswtraffic, permit, sequence 10

Match clauses:

ip address (access-lists): 103

Set clauses:

ip next-hop 10.15.27.3

Policy routing matches: 5 packets, 500 bytes

注释 也可以通过show access-list 103命令看到更多的匹配信息

5.9. 改变治理距离

提问 调整学到的外部网络的缺省治理距离

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#router rip

Router(config-route)#network 192.168.15.0

Router(config-route)#distance 15 192.168.15.1 0.0.0.0

Router(config-route)#distance 200 192.168.15.0 0.0.0.255

Router(config-route)#distance 255

Router(config-route)#end

Router#

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#router eigrp 111

Router(config-route)#network 192.168.16.0

Router(config-route)#distance eigrp 55 200

Router(config-route)#end

Router#

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#router ospf 66

Router(config-route)#distance ospf inter-area 115

Router(config-route)#distance ospf intra-area 105

Router(config-route)#distance ospf external 125

Router(config-route)#end

Router#

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#router bgp 65520

Router(config-route)#distance bgp 115 220 50

Router(config-route)#end

Router#

注释 治理距离只是针对自己的,通过调整这些外部路由的治理距离来调整自己路由表的结构

5.10. 相同代价值的多路径路由

提问 限制路由器到达同一目的地的路径数目

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#router ospf 65510

Router(config-router)#maximum-paths 2

Router(config-router)#end

Router#

IOS 12.2T以后对BGP增加了下面的命令

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#router bgp 65511

Router(config-router)#maximum-paths 2

Router(config-router)#maximum-paths ibgp 3

Router(config-router)#end

Router#

注释 缺省情况下静态路由可以有6条冗余,BGP只有一条最佳路径,其他路由协议为4条。使用上述命令在12.3(2)T之前可以调整最大为6条,12.3(2)T之后可以最大为16条

5.11. 配置静态路由的追踪

提问 在某个端口当掉等情况下才启用特定的静态路由

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#track 10 interface Serial0/0 line-protocol

Router(config-track)#delay down 5 up 30

Router(config-track)#exit

Router(config)#ip route 192.168.10.0 255.255.255.0 10.3.12.26 track 10

Router(config)#end

Router#

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#track 11 ip route 10.2.95.0 255.255.255.0 reachability

Router(config-track)#delay down 5 up 5

Router(config-track)#exit

Router(config)#ip route 0.0.0.0 0.0.0.0 10.3.12.26 track 11

Router(config)#end

Router#

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#track 12 list boolean and

Router(config-track)#object 10 not

Router(config-track)#object 11

Router(config-track)#exit

Router(config)#ip route 192.168.13.0 255.255.255.0 10.3.12.26 track 12

Router(config)#end

Router#

注释 从12.3T和12.4以后开始IOS提供了一种track的特性,可以定义跟踪不同的状态。可以使用show track命令来查看跟踪的状态。跟踪状态也可以进行组合,使用and or逻辑运算或者百分比,权重等增加灵活度,很好玩,不过别把自己绕进去了

<!--[if !supportLists]-->5.12. <!--[endif]-->路由表变动统计

提问 通过路由表变动的统计来衡量路由表的稳定性

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#ip route profile

Router(config)#end

Router#

Router#show ip route profile

IP routing table change statistics:

Frequency of changes in a 5 second sampling interval

-------------------------------------------------------------

Change/ Fwd-path Prefix Nexthop Pathcount Prefix

interval change add change change refresh

-------------------------------------------------------------

0 327 327 335 335 331

1 4 4 0 0 1

2 2 2 0 0 1

3 0 0 0 0 0

4 1 1 0 0 1

…….

Router#

注释 12.0就有的一个老命令,但估计很少有人使用,这个统计也是够难懂的,简单的说最理想的情况就是第一行数目很大,其他行都是0。统计方法是每3秒一个间隔,在这个间隔内假如有1次路由表变化就累计一次,多次变化就累计多次。但这个命令还是有一些缺点,一就是不能清掉老的数据,必须通过no ip route profile,然后ip route profile 来清除,还有就是这里只是统计结果,没有办法确定是哪条路由出的问题

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有