本节使用一些命令来演示OSPF协议的工作机制,并使用命令来调整链路的cost值,便最终的路由表正确反映拓扑及链路的实际情况。
1.实验目的
通过本实验,读者可以把握以下技能
●监测OSPF建立邻接关系的过程;
●监测OSPF事件;
●监测OSPF包的收发;
●调整链路的带宽,以更改Cost值。
2.设备需求及拓扑结构说明
本实验需要的设备和拓扑结构与本章实验1相同,请参照实验1的有关说明。
3.实验配置及监测结果
本实验是在完成实验1的基础上进行的。
第1部分:理解Router ID并监测邻接关系的建立
首先考察OSPF路由器ID号与回送接口地址的关系,同时监测路由器建立邻接关系的过程。
监测清单11-3是配置和监测过程的记录。
监测清单11-3监测Router们和邻接关系的建立
R2(config)#int loop0
R2(config-if)#ip addr 10.1.1.1 255.255.255.0
R2(config-if)#int loop1
R2(config-if)#ip addr 10.1.2.1 255.255.255.0
R2(config-if)#exit
R2(config)#logg console
R2(config)#no router ospf 100
R2#debug ip ospf adj
OSPF adjacency events debugging is on
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#router ospf 100
R2(config-router)#netw 192@168.1.2 0.0.0.0 area 0
R2(config-router)#^Z
R2#
01:05:32: OSPF:Interface Serial1 going UP
01:05:33: OSPF:Build router LSA for area 0,router ID 10.1.2.1,seq 0x80000001
01:05:33: OSPF:2 Way Communication to 192.168.1.1 on Serial1,state 2WAY
01:05:33: OSPF:Send DBD to 192.168.1.1 on Serial1 seq OxIOA opt 0x42 flag 0x7 len 32 '
01:05:33: OSPF:Rcv DBD from 192.168.1.1 on Serial1 seq Ox23F4 opt 0x42 flag 0x7 len 32 mtu 1500
EXSTART
01:05:33: OSPF: NBR Negotiation Done. We are the SLAVE
01:05:33: OSPF: Send DBD to 192.168.1.1 on Seriall seq Ox23F4 opt 0x42 flag 0x2 len 52
01:05:33: OSPF: Rev DBD from 192.168.1.1 on Seriall seq Ox23F5 opt 0x42 flag 0x3 len 72 mtu 1500 state
EXCHANGE
01:05:33: OSPF: Send DBD to 192.168.1.1 on Seriall seq Ox23F5 opt 0x42 flag 0x0 len 32
01:05:33: OSPF: Database request to 192.168.1.1
01:05:33: OSPF: sent LS REQ packet to 192.168.1.1,length 24
01:05:34: OSPF: Rev DBD from 192.168.1.1 on Seriall seq Ox23F6 opt 0x42 flag 0x1 len 32 mtu 1500 state
EXCHANGE
01:05:34: OSPF:Exchange Done with 192.168.1.1 on Serial1
01:05:34: OSPF: Send DBD to 192.168.1.1 on Seriall seq Ox23F6 opt 0x42 flag 0x0 len 32
01:05:34: OSPF:Synchronized with 192.168.1.1 on Serial1,state FULL
01:05:34: %OSPF-5-ADJCHG: Process 100,Nbr 192.168.1.1 on Serial1 from LOADING to FULL, Loading
Done
R2#
R2#sh ip ospf 100
Routing Process "ospf 100" with ID 10.1.2.1 and Domain ID 0.0.0.100
Supports only single TOS(TOSO) routes
Supports opaque LSA
... (此处省略)
R2#
Term_Server1
[Resuming connection 1 to r1 ... ]
R1#sh ip ospf neighbor
Neighbor IDPriStateDead TimeAddressInterface
10.1.2.11FULL/-00:.00:29192.168.1.2Serial1
R1#
(1)首先,在R2路由器上创建2个回送接口loopback0和loopback1,相应的IP地址分别是10.1.1.1和10.1.2.1。
(2)使用no命令关闭OSPF进程,以便创建新的OSPF进程,并观察Router ID和邻接建立过程。
(3)debug ip ospf adj命令打开对OSPF邻接活动的监测。
(4)再次启动进程号为100的OSPF路由进程,为了观察的方便,需要把S1接口加入到路由进程中。
(5)接下来的数行监测信息是OSPF邻接建立过程的报告。其中主要的阶段如下:
●建立区域O的LSA,Router ID是10.1.2.1;
●与ID号为192.168.1.1的路由器R1进行2路通信,处于"2WAY"状态;
●发送和接收数据库描述包 (DBD),状态为"EXSTART";
●发送链路状态请求包 (LS REQ Packct)到192.168.1.1,状态为"EXCHANGE";
●与邻居路由器192.168.1.1的同步操作完成,状态为"FULL";
●整个加载过程完成。
(6)show IP ospf 100命令也显示了路由器R2的ID号为10.1.2.1,即回送接口上的最高IP
(7)切换到R1路由器,查看其OSPF邻居,同样可以看到邻居路由器R2的ID变成了
第2部分:监测OSPF事件和OSPF包的传输
以下使用debug ip ospf events和debug ip ospf packet命令监测OSPF相关事件和相关数据包的传输。
监测清单11-4记录了有关操作及监测结果。
监测清单11-4监测OSPF事件和数据包
R1(config)#logg console
R1(config)#^Z
R1#debug ip ospf events
OSPF events debuggmg is on
R1#
02:08:50: OSPF: Rev hello from 10,1.2.1 area 0 from Serial1 192.168.1.2
02:08:50: OSPF: End of hello processing
02:09:00: OSPF: Rev hello from 10.1.2.1 area 0 from Serial1 192.168.1.2
02:09:00: OSPF: End of hello processing
02:09:10: OSPF: Rcv hello from 10.1.2.1 area 0 from Serial1 192.168.1.2
02:09:10: OSPF: End of hello processing
02:09:20:'OSPF: Rcv hello from 10.1.2.1 area 0 from Serial1 192.168.1.2
02:09:20: OSPF: End of hello processing
R1#undebug all
All possible debugging has been turned off
R1#debug ip ospf packet
OSPF packet debugging is on
R1#
02:11:40: OSPF: rev. v:21:1 1:48 rid: 10.1.2.1
aid:0.0.0.0.chk:2DF3 aut:0 auk: from Serial1
02:11:50: OSPF: rev. v:21:1 1:48 rid: 10.1.2.1
aid:0.0.0.0 chk:2DF3 aut:0 auk: from Serial 1
02:12:00: OSPF: rev. v:2 t:1 1:48 rid: 10.1.2.1
aid:0.0.0.0 chk:2DF3 aut:0 auk: from Serial 1
02:12:10: OSPF: rev. v:2 t:1 1:48 rid:10.1.2.1
aid:0.0.0.0 ehk:2DF3 aut:0 auk: from Serial 1
02:12:20: OSPF: rev. v:2 t:1 1:48 rid: 10.1.2.1
aid:0.0.0.0 ehk:2DF3 aut:0 auk: from Serial 1
RS#undebug all
All possible debugging has been turned off
(1)在R1路由器上,首先打开对OSPF事件的Debug,监测结果显示了接收一系列的Hello包,其源地址是192.168.1.2,即R2的IP地址。
注重到Hello包之间的时间间隔是10秒,这是因为在点到点链路中,Hello包每隔10秒发送一次。
(2)关闭Debug。然后打开对OSPF包的监测,其命令是debug ip ospf packet。
R1路由器监测到从R2传来的一系列的OSPF包,这些包实际上就是每10秒接收1个的Hello包。
第3部分:调整带宽参数更改cost值
路由器接口的带宽参数对链路cost有直接的影响。
监测清单11-5是有关操作及监测结果的记录。
监测清单11-5更改带宽参数以影响cost值
让我们用实验来进行演示。
第1段:查看接口带宽与链路Cost
R2#conft
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#router ospf 100
R2(config-router)#netw 192.168.1.5 0.0.0.0 area 0
R2(config"router)#^Z
R2#
R2#sh ip route ospf
172.16.0.0/24 is subnetted, 2 subnets
O172.16.1.0 [110/11] via 192.168.1.1, 00:00:33, Serial1
O172.16.3.0 [110/11 via 192.168.1.6, 00:00:33, Serial0
R2#sh int s0
Serial0 is up, line protocol is up
Hardware is HD64570
Internet address is 192.168.1.5/30
MTU 1500 DLY 20000 usec,
reliability 255/255, txioad 1/255, rxioad 1/255
... (此处删节)
R2#sh int s1
Serial 1 is up, line protocol is up
Hardware is HD64570
Internet address is 192.168.1.2/30
MTU 1500 bytes,BW 1544 Kbit,DLY 20000 usec,
reliability 255/255, txioad 1/255, rxioad 1/255
... (此处删节)
R2#sh ip ospf int s0
Serial0 is up, line protocol is up
Internet Address 192.168.1.5/30, Area 0
Process ID 100, Router ID 10.1.2.1, Network Type POINT_TO_POINT,Cost:64
... (此处删节)
R2#sh ip ospf int s1
Serial 1 is up, line protocol is up
Internet Address 192.168.1.2/30, Area 0
Process ID 100, Router ID 10.1.2.1, Network Type POINT_TOJPOINT,Cost:64
Transmit Delay is 1 sec. State POINT_TO_POINT,
...(此处删节)
R2#
Term_Server1
[Resuming connection 1 to r1 ... ]
R1#sh ip ospf int e0
Ethernet0 is up, line protocol is up
Internet Address 172.16.1.1/24, Area 0
Process ID 100, Router ID 192.168.1.1, Network Type BROADCAST,Cist:10
Transmit Delay is 1 sec. State DR, Priority 1
... (此处删节)
R1#
第2段:更改接口带宽以影响链路Cost
Term_Server2
[Resuming connection 2 to r2 ... ]
R2#conft
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#int s0
R2(config-if)#bandwidth 64
R2(config-if)#int si
R2(config-if)#bandwidth 125
R2(config-if)#^Z
R2#sh ip route ospf
172.16.0.0/24 is subnetted, 2 subnets
O172.16.1.0 [110/810] via 192.168.1.1, 00:00:09, Serial1
O172.16.3.0 [110/1572] via 192.168.1.6, 00:00:09, Serial0
R2#sh int s0
Serial0 is up, line protocol is up
Hardware is HD64570
Internet address is 192.168.1.5/30
MTU 1500 bytes,BW 64 Kbit,DLY 20000 usec,
reliability 255/255, txioad 1/255, rxioad 1/255
... (此处删节)
R2#sh int s1
Serial1 is up, line protocol is up
Hardware is HD64570
Internet address is 192.168.1.2/30
MTU 1500 bytes,BW 125 Kbit,DLY 20000 usec,
reliability 255/255, txioad 1/255, rxioad 1/255
...(此处删节)
R2#sh ip ospf int s0
Serial0 is up, line protocol is up
Internet Address 192.168.1.5/30, Area 0
Process ID 100, Router ID 10.1.2.1, Network Type POINT_TO_POINT,Cost:1562
Transmit Delay is 1 sec. State POINT_TO_POINT,
... (此处删节)
R2#sh ip ospf int s1
Serial 1 is up, line protocol is up
Internet Address 192.168.1.2/30, Area 0
Process ID 100, Router ID 10.1.2.1, Network Type POINT_TO_POINT,Cost:800
Transmit Delay is 1 sec. State POINT_TO_POINT,
... (此处删节)
R2#
第3段:直接更改接口相关Cost
R2(config)#int s0
R2(config-if)#ip ospfcost 200
R2(config-if)#^Z
R2#sh ip ospf int s0
Serial0 is up, line protocol is up
Internet Address 192.168.1.5/30, Area 0
Process ID 100, Router ID 10.1.2.1, Network Type POINT_TO_POINT,Cost:200
Transmit Delay is 1 sec. State POINT_TO_POINT,
Timer intervals configured. Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:05
Index 2/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 4 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 192.168.1.6
Suppress hello for 0 neighbor(s)
R2#sh ip route ospf
172.16.0.0/24 is subnetted, 2 subnets
O172.16.1.0 [110/1572] via 192.168.1.1, 00:00:11, Serial1
O172.16.3.0 [110/210] via 192.168.1.6, 00:00:11, Serial0
R2#
(1)在第1段开始时,首先在R2路由器上把S0接口加入到OSPF路由进程中,恢复全网的连通性。
使用show ip route ospf命令查看OSPF路由表,会看到经由S0和S1的2条路由的Cost值均为74。
这一结果是我们在以前的实验中没有注重到的,显然它不是我们所希望看到的,因为我们预期中的Cost值是S1比S0低,因为S1的带宽(125kbit/s)要比S0的带宽(64kbit/s)高。
(2)通过发出show interface命令对S0和S1的带宽进行考察发现,它们的带宽(BW)均为1544kbit/s,这是串行接口的缺省带宽。可见路由器并不能根据时钟的设置而自动更改带宽的设置。
(3)show ip ospf interface命令给出了S0和S1接口的Cost值,它们也为相同的64。
(4)细心的读者可能产生了一个疑问,即:为什么在路由表中显示的Cost(74)与接口的Cost(64)之间不同?
为说明问题,切换到R1路由器上,查看OSPF接口信息,表明其E0接口的Cost为10。
从R2路由器到172.16.1.0/24网段需要经过R1、R2之间的串行链路和R2的以太网接口,所以最终的Cost值为两个链路的Cost值相加,为74。对于到172.16.30/24网段的路由而言,其结果相同。
(5)在第2段中,通过更改相应接口的带宽参数来影响Cost值。
在R2路由器上,使用bandwidth命令,设置S0接口的带宽为64kbit/s,S1接口的带宽为125kbit/s。
查看OSPF路由表,结果显示相应的Cost己经更改为1572(S0接口)和810(S1接口)。
分别查看接口信息和OSPF接口信息,表明带宽和Cost值已经产生应有的变化,Cost值分别是1562(S0接口)和800(S1接口)。
(6)有一种更为直接的更改Cost值的方法,那就是第3段中演示的在接口配置模式下使 用ip ospfcost命令定义Cost的方法。
实验中我们把S0接口的Cost设定为200。相应的命令显示设置是成功的。
ip ospf cost命令不管相应接口的带宽为多少,人工设定一个Cost值,并立即生效,参与路由的计算。
第4部分:最终的各路由器配置清单
为便于读者学习,在实验的最后列出3台路由器的完整配置清单。清单中R1和R3路由器也加入了带宽的设置。请注重E0接口下设置了no keepalive语旬,这是因为在实验环境下此接口没有连接网线;在实际的网络环境下,不应设置此语句。
所有路由器的最终配置见配置清单11-2。
配置清单11-2所有路由器的最终配置
第1段:R1路由器的配置清单
Current configuration : 642 bytes
!
version 12.1
service timestamps debug uptime
service timestamps log uptime
no service passWord-encryption
!
hostname R1
ip subnet-zero
!
interface Ethemet0
ip address 172.16.1.1255.255.255.0
no keepalive
!
interface Serial0
no ip address
shutdown
!
interface Serial 1
bandwidth 125
ip address 192.168.1.1255.255.255.252
clockrate 125000
!
router ospf 100
network 172.16.1.1 0.0.0.0 area 0
network 192.168.1.1 0.0.0.0 area 0
!
ip classless
ip http server
!
line con 0
line aux 0
line vty 0 4
login
!
end
第2段:R2路由器的配置清单
Current configuration : 618 bytes
!
version 12.1
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
hostname R2
!
ip subnet-zero
!
interface Ethemet0
no ip address
shutdown
!
interface Serial0
bandwidth 64
ip address 192.168.1.5 255.255.255.252
!
interface Serial 1
bandwidth 125
ip address 192.168.1.2 255.255.255.252
!
router ospf 100
network 192.168.1.2 0.0.0.0 area 0
network 192.168.1.5 0.0.0.0 area 0
!
ip classless
ip http server
!
line con 0
line aux 0
line vty 0 4
login
!
end
第3段:R3路由器的配置清单
Current configuration : 678 bytes
version 12.1
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname R3
!
ip subnet-zero
!
interface Ethemet0
ip address 172.16.3.1255.255.255.0
no keepalive
!
interface Serial0
bandwidth 64
ip address 192.168.1.6 255.255.25.5.252
clockrate 64000
!
interface Serial 1
no ip address
shutdown
!
router ospf 100
network 172.16.3.1 0.0.0.0 area 0
network 192.168.1.6 0.0.0.0 area 0
!
ip classless
ip http server
!
line con 0
line aux 0
line vty 0 4
login
!
end