首先先介绍一OSPF要点:
路由器在所有启ospf进程的接口发helloOSPF报头是固定的(24字节),LSA也有自己的报头,封装OSPF
HELLO协议的功能:
建立邻居关系保持邻居关系确定和邻居的双向关系用DRBDR的选举
路由器建立邻居关系的条件:
Area ID区域号必须相Authentication密码必须相Hello Dead intervals计时器必须相Stub area如果配置stub2台邻居路由器必须都要两端都要设置Stub
Hello包内包含的字段
Hello包的源路由ID Hello包源路由器接口的地址码路由器优先级,DR选举(默认10表示不DR选举) DRBDR 标记位,stub标记这里对端路由器ID,neighbor seen
网络类型:
PointtoPoint
点对点类型,drbdr的选举,ospf包的目标地址224.0.0.5(ospf路由器组播地址)
Broardcast
广播网络,以太网,令牌环网还FDDI. 因为访问,一台路由器的发的包能被所有路由器接收。广播类型网络,要进drbdr选举,hello包的地址224.0.0.5 DRBDR的所有数据包也224.0.0.5Drother224.0.0.6将数据包发DRBDR
NBMA
NBMA不支广播如,ATMFrX.25 一台路由器发送的一不能同时所有的路由器接收到这种类型上要进DRBDR
Pointtomultipoint
点对点类型似不drbdr选举,数据包用组播传送,因为点对点类型类cisco推荐此种配置
下面介绍一下各种类型LSA
Type Code LSA Link-State IDLSID
1 Router LSA 路由器IDospf路由器都会产
2 Network LSA DR的接口地址DRBDR
3 Network summary LSA 网络号,ABR
4 ASBR summary LSA ASBR的路由ID
5 AS external LSA 外部网络
7 NSSA external LSA 外部网络
以下用例子和图示表示这几种类型LSA
Router_B#show ip ospf database此命令查ospf链路数据OSPF Router with ID (170.170.3.2) (Process ID 7) Router Link States (Area 0)0表示此路由器为主,type1lsa Link ID ADV Router Age Seq# Checksum Link count
170.170.3.2 170.170.3.2 17 0x80000002 0x8B6 1
170.170.8.4 170.170.8.4 217 0x80000003 0xAA02 1
170.170.13.3 170.170.13.3 218 0x80000002 0x5156 1
Net Link States (Area 0)type 2LSA DR传送过来Link ID ADV Router Age Seq# Checksum
170.170.3.3 170.170.13.3 18 0x80000002 0xA0B2
Summary Net Link States (Area 0)type 3LSA,域间路Link ID ADV Router Age Seq# Checksum
170.170.7.0 170.170.8.4 240 0x80000001 0x6ED0
Summary ASB Link States (Area 0) type 4LSAASBR发过Link ID ADV Router Age Seq# Checksum
170.170.11.6 170.170.8.4 129 0x80000001 0xF73C
Type-5 AS External Link Statestype 5LSAASBRLink ID ADV Router Age Seq# Checksum Tag
200.200.200.0 170.170.11.6 135 0x80000001 0xE4FA 0
Router_B#
下面用图例来表示几LSA
Router LSA:就Type 1,所有路由器都能产
Network LSAType 2 LSADR产生发给所有Drother
Network Summary LSAType 3 ABR产生,此类用距离向量方法传送路由,一lsa传送一条路
ASBR Summary LSALSA 4ABR产生,下一跳ABR
AS External LSAType 5,下一跳ASBR,此类路由优先级低,为了防止环路,因为外部路由有可能是不可靠的。
下面介绍一ospf的配置命令:
首先全局配置
Step Command
1. router ospf process-id 启用路由进
2. network address wildcard-mask area area-id 启用路由进程的接口和区ID
Router_D:路由DABR
interface ethernet 0
ip address 170.170.3.4 255.255.255.0
interface serial 0
ip address 170.170.7.4 255.255.255.0
router ospf 7
network 170.170.3.0 0.0.0.255 area 0 E0ospf并加入主
network 170.170.7.0 0.0.0.255 area 51 S0ospf加入51
OSPF接口参数,下面的参数都是ospf接口模式输入
Command
ip ospf hello-interval seconds hello
ip ospf dead-interval seconds helloholdtimer
OSPFHello Down机判间隔广1040秒点对1040NBMA 30120
如果两端的间隔配置不对就不会形成邻接
Command
ip ospf priority number 设置路由器优先级,用DR选举,默认10表示不参加
Ospf邻接的时要选DRBDR,那么首先hello种查优先级,如果都相同的话再最高RouterID上面这条命令就是设置优先级
Command
ip ospf cost cost 设定接口成本
上面这条命令表示设置接口成本,用路由计算。
下面看一下实例
Router_D#show ip ospf interface ethernet 0
Ethernet0 is up, line protocol is up
Internet Address 170.170.3.4/24, Area 0
Process ID 7, Router ID 170.170.8.4, Network Type BROADCAST,
Cost: 10
Transmit Delay is 1 sec, State BDR, Priority 1
Designated Router (ID) 170.170.13.3, Interface address
170.170.3.3 Backup Designated router (ID) 170.170.8.4, Interface address 170.170.3.4 Timer intervals configured, Hello 10, Dead 40, Wait 40,
Retransmit 5 Hello due in 00:00:08 Index 1/1, flood queue length 0 Next 0x0(0)/0x0(0) Last flood scan length is 0, maximum is 3 Last flood scan time is 0 msec, maximum is 0 msec Neighbor Count is 2, Adjacent neighbor count is 2
Adjacent with neighbor 170.170.3.2 Adjacent with neighbor 170.170.13.3 (Designated Router) Suppress hello for 0 neighbor(s)
Router_D#
的网络类型ospf
NBMA
Command
neighbor ip-address [priority number] [poll-interval seconds] 手工定邻居
如果网络类型NBMA因为不支广播,那么要用此命令手工定邻居IOS配置为点对点点对多点类型,所以这条命令很少用了
点对点字接口类型:
这种类型物理端口配置成多个接口模式每个接口是一单独每个接口都为点对点模式就不会DR的选举
Router_F:
interface Serial2 no ip address encapsulation frame-relay frame-relay lmi-type ansi
!
interface Serial2.7 point-to-point ip address 170.170.11.6 255.255.255.0 frame-relay interface-dlci 101
! interface Serial2.8 point-to-point ip address 170.170.10.6 255.255.255.0
frame-relay interface-dlci 103
router ospf 7 network 170.170.11.0 0.0.0.255 area 0 network 170.170.10.0 0.0.0.255 area 0
Router_G:
interface Serial0 no ip address encapsulation frame-relay frame-relay lmi-type ANSI
!
interface Serial0.6 point-to-point ip address 170.170.11.7 255.255.255.0 frame-relay interface-dlci 110
router ospf 7 network 170.170.11.0 0.0.0.255 area 0
Command
ip ospf network {broadcast | non-broadcast | {point-to-multipoint [non-broadcast] }} 改变网络类型
这条命令是用ospf接口类型
点对多点类型:
是邻居在一DRBDR的选
Router_E:
interface Serial1 ip address 170.170.9.5 255.255.255.0 no ip mroute-cache encapsulation frame-relay
ip ospf network point-to-multipoint
frame-relay map ip 170.170.9.7 121 broadcast frame-relay map ip 170.170.9.8 123 broadcast router ospf 7 network 170.170.9.0 0.0.0.255 area 0
Router_G:
interface Serial0
no ip address
encapsulation frame-relay
frame-relay lmi-type ANSI
!
interface Serial0.5 multipoint
ip address 170.170.9.7 255.255.255.0
ip ospf network point-to-multipoint
frame-relay map ip 170.170.9.5 112 broadcast router ospf 7 network 170.170.9.0 0.0.0.255 area 0
点对多点还是,所有的邻居都会产生邻居的路由
Router_E#show ip route
Codes: C -connected, S -static, I -IGRP, R -RIP, M -mobile,
B - BGP
D -EIGRP, EX -EIGRP external, O -OSPF, IA -OSPF inter
area
N1 -OSPF NSSA external type 1, N2 -OSPF NSSA external type
2
E1 -OSPF external type 1, E2 -OSPF external type 2, E -
EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, * -
candidate default
U - per-user static route, o - ODR
Gateway of last resort is not set 170.170.0.0/16 is variably subnetted, 5 subnets, 2 masks
O 170.170.9.8/32 [110/64] via 170.170.9.8, 00:07:01, Serial1
C 170.170.9.0/24 is directly connected, Serial1
O 170.170.9.7/32 [110/64] via 170.170.9.7, 00:07:01, Serial1
Router_E#
邻居间就不Frame Relay map
下面DR情况
Router_E#show ip ospf interface serial 1
Serial1 is up, line protocol is up
Internet Address 170.170.9.5/24, Area 0
Process ID 7, Router ID 170.170.9.5, Network Type
POINT_TO_MULTIPOINT, Cost: 64
Transmit Delay is 1 sec, State POINT_TO_MULTIPOINT,
Timer intervals configured, Hello 30, Dead 120, Wait 120,
Retransmit 5
Hello due in 00:00:04
Neighbor Count is 2, Adjacent neighbor count is 2
Adjacent with neighbor 170.170.12.8
Adjacent with neighbor 170.170.12.7
Suppress hello for 0 neighbor(s) Router_E# DRBDR
配置路由聚合
聚合ABRASBR的,聚合可减小路由降低路由抖动路由聚合2l 路由l 外部路由聚合
首先看域间路由聚合
Command
area area-id range address mask 聚合地址area-id是要聚合的那id
路由B和路由DABR,中area0主干在路由B
router ospf 7 network 170.170.1.0 0.0.0.255 area 51 network 170.170.3.0 0.0.0.255 area 0
area 1 range 172.16.128.0 255.255.224.0area 1的路由,发area0
外部路由聚合External route
Command
summary-address address mask 定要聚合外部地址
AASBR,要将外部172.16.128.0/24 172.16.159.0/24聚合area 0主干要配置
router ospf 7
summary-address 172.16.128.0 255.255.224.0
redistribute static subnets
network 170.170.1.0 0.0.0.255 area 51
聚合外部路由要summary-address不能area range聚合
Stub AreasToally Stubby Areas
stubType 5类型Lsa,也外部路由,接其他Lsa Toally缺省路由和域路由,外部
Command
area area-id stub [no-summary] stubToally stub
是看幅图路由A外部路由主干,那么如果Router F配置Stub域,看看还能不能收到那些外部路由
Router_D:
router ospf 7 network 170.170.3.0 0.0.0.255 area 0 network 170.170.7.0 0.0.0.255 area 1
area 1 stub
Router_F:
router ospf 7 network 170.170.7.0 0.0.0.255 area 1
area 1 stub
我们看一路由F的路由
Router_F#sh ip route
Codes: C -connected, S -static, I -IGRP, R -RIP, M -mobile,
B - BGP
D -EIGRP, EX -EIGRP external, O -OSPF, IA -OSPF inter
area
N1 -OSPF NSSA external type 1, N2 -OSPF NSSA external type
2
E1 -OSPF external type 1, E2 -OSPF external type 2, E -
EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, * -
candidate default
U - per-user static route, o - ODR
Gateway of last resort is 170.170.7.4 to network 0.0.0.0 170.170.0.0/24 is subnetted, 3 subnets OIA170.170.1.0[110/138]via170.170.7.4, 00:02:42,Serial0
O IA 170.170.3.0 [110/74] via 170.170.7.4, 00:02:42, Serial0
C 170.170.7.0 is directly connected, Serial0
O*IA 0.0.0.0/0 [110/65] via 170.170.7.4, 00:02:42, Serial0
Router_F#
了域缺省路由之外部路由
下来area 1在配置Toally Stub
Router_D:
router ospf 7 network 170.170.3.0 0.0.0.255 area 0 network 170.170.7.0 0.0.0.255 area 1
area 1 stub no-summary
Router_F:
router ospf 7 network 170.170.7.0 0.0.0.255 area 1
area 1 stub no-summary
在看看路由F的路由
Router_F#sh ip route
Codes: C -connected, S -static, I -IGRP, R -RIP, M -mobile,
B - BGP
D -EIGRP, EX -EIGRP external, O -OSPF, IA -OSPF inter
area
N1 -OSPF NSSA external type 1, N2 -OSPF NSSA external type
2
E1 -OSPF external type 1, E2 -OSPF external type 2, E -
EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, * -
candidate default
U - per-user static route, o - ODR
Gateway of last resort is 170.170.7.4 to network 0.0.0.0
170.170.0.0/24 is subnetted, 1 subnets
C 170.170.7.0 is directly connected, Serial0
O*IA 0.0.0.0/0 [110/65] via 170.170.7.4, 00:00:00, Serial0 Router_F# 有一缺省路由了,LSA Type 3的也有了
NSSA Area Not-So Stubby Area
Command
area area-id nssa [no-redistribution] [default-information-originate] 配置NSSA
Area 51配置NSSA模式,路由A外部路由Lsa Type 7往主干,路由BType 7Type 5
Router_A:
router ospf 7 redistribute static subnets network 170.170.1.0 0.0.0.255 area 51
area 51 nssa
! ip route 172.16.128.0 255.255.255.0 Serial1 ip route 172.16.129.0 255.255.255.0 Serial1 ip route 172.16.130.0 255.255.255.0 Serial1
Router_B:
router ospf 7 network 170.170.1.0 0.0.0.255 area 51 network 170.170.3.0 0.0.0.255 area 0
area 51 nssa
看看路由B的路由到类7的路
Router_B# sh ip route Codes: C -connected, S -static, I -IGRP, R -RIP, M -mobile, B - BGP
D -EIGRP, EX -EIGRP external, O -OSPF, IA -OSPF inter
area
N1 -OSPF NSSA external type 1, N2 -OSPF NSSA external type
2
E1 -OSPF external type 1, E2 -OSPF external type 2, E -
EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, * -
candidate default
U -per-user static route, o -ODR, P -periodic downloaded
static route
T - traffic engineered route
Gateway of last resort is not set
170.170.0.0/24 is subnetted, 3 subnets
C 170.170.1.0 is directly connected, Serial0
C 170.170.3.0 is directly connected, Ethernet0
O IA 170.170.7.0 [110/74] via 170.170.3.4, Ethernet0
172.16.0.0/24 is subnetted, 3 subnets
O N2 172.16.128.0 [110/20] via 170.170.1.1, Serial0 O N2 172.16.129.0 [110/20] via 170.170.1.1, Serial0 O N2 172.16.130.0 [110/20] via 170.170.1.1, Serial0
Router_B#
看看路由B数据Type 7 LSA
Router_B#show ip ospf database OSPF Router with ID (170.170.3.2) (Process ID 7)
Router Link States (Area 0) Link ID ADV Router Age Seq# Checksum Link count
170.170.3.2 170.170.3.2 1395 0x8000002A 0xB6DD 1
170.170.8.4 170.170.8.4 973 0x80000029 0x5433 1
Net Link States (Area 0) Link ID ADV Router Age Seq# Checksum
170.170.3.2 170.170.3.2 1773 0x80000027 0x2281
Summary Net Link States (Area 0) Link ID ADV Router Age Seq# Checksum
170.170.1.0 170.170.3.2 1773 0x80000027 0x9392
170.170.7.0 170.170.8.4 974 0x80000027 0x22F6
Router Link States (Area 51) Link ID ADV Router Age Seq# Checksum Link count
170.170.3.2 170.170.3.2 1378 0x8000002A 0x5F4C 2
170.170.13.1 170.170.13.1 1381 0x80000038 0x3D59 2
Summary Net Link States (Area 51) Link ID ADV Router Age Seq# Checksum
170.170.3.0 170.170.3.2 1398 0x8000002A 0xFE52
170.170.7.0 170.170.3.2 1398 0x80000028 0x59B5
Type-7 AS External Link States (Area 51)
Link ID ADV Router Age Seq# Checksum Tag
172.16.128.0 170.170.13.1 124 0x80000002 0xFF9D 0
172.16.129.0 170.170.13.1 125 0x80000002 0xF4A7 0
172.16.130.0 170.170.13.1 125 0x80000002 0xE9B1 0
Type-5 AS External Link States
Link ID ADV Router Age Seq# Checksum Tag
172.16.128.0 170.170.3.2 1367 0x80000001 0xD6DA 0
172.16.129.0 170.170.3.2 1367 0x80000001 0xCBE4 0
172.16.130.0 170.170.3.2 1367 0x80000001 0xC0EE 0
Router_B#