「实战」动态路由协议OSPF基本配置,一分钟了解下

2023-06-25 07:23:15

一、配置要求

1.路由器名为cisco1,cisco2和cisco3;

2.配置IP地址如图所示,cisco1的环回口IP地址为1.1.1.1,255.255.255.0,cisco3为3.3.3.3,子网掩码为255.255.255.0。

3.三台路由器属于同一个OSPF区域0;

4.将三台路由器相连,并在路由器上启用OSPF路由协议;

5.用扩展PING命令,测试用1.1.1.1 到3.3.3.3 的连通性

二、拓扑

三、步骤

1.设置路由选择协议

cisco1(config)#router ospf 1

cisco1(config-router)#network 192.168.12.0 0.0.0.255 area 0

cisco1(config-router)#network 1.1.1.1 0.0.0.0 area 0

注:利用反掩码技术来匹配某一接口,如果匹配到了,那么就把这个接口的网段参与到OSPF的进程中

cisco2(config)#router ospf 1

cisco2(config-router)#network 192.168.0.0 0.0.255.255 area 0

注:虽然只写入了一个条目,但是它匹配到了192.168.12.2和192.168.23.2这两个接口,所以他们都会参与到OSPF进程中

cisco3(config)#router ospf 1

cisco3(config-router)#network 3.3.3.0 0.0.0.255 area 0

cisco3(config-router)#network 192.168.23.0 0.0.0.255 area 0

2.查看路由表

cisco1#show ip route

1.0.0.0/24 is subnetted, 1 subnets

C 1.1.1.0 is directly connected, Loopback0

3.0.0.0/32 is subnetted, 1 subnets

O 3.3.3.3 [110/75] via 192.168.12.2, 00:00:59, Ethernet0

C 192.168.12.0/24 is directly connected, Ethernet0

O 192.168.23.0/24 [110/74] via 192.168.12.2, 00:00:59, Ethernet0

注:OSPF的代号为O。管理距离值为110。度量值的计算方法是cost=10的8次方除以带宽。

观察OSPF邻居关系的建立情况

cisco1#debug ip ospf adj

cisco1(config)#int e0

cisco1(config-if)#shutdown

cisco1(config-if)#

注:开启OSPF建立邻居关系的debug信息。关闭端口!以验证邻居建立情况

02:00:59: %LINK-5-CHANGED: Interface Ethernet0, changed state to administratively down----等待接口被管理员性关闭后,再用no shutdown打开

02:01:00: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0, changed state to down

cisco1(config-if)#no shutdown----打开端口

cisco1(config-if)#

02:01:05: OSPF: Interface Ethernet0 going Up

02:01:05: OSPF: Build router LSA for area 0, router ID 1.1.1.1, seq 0x80000005

02:01:07: %LINK-3-UPDOWN: Interface Ethernet0, changed state to up

02:01:08: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0, changed state to up

02:01:12: OSPF: 2 Way Communication to 192.168.23.2 on Ethernet0, state 2WAY

02:01:12: OSPF: Backup seen Event before WAIT timer on Ethernet0

02:01:12: OSPF: DR/BDR election on Ethernet0

02:01:12: OSPF: Elect BDR 1.1.1.1

02:01:12: OSPF: Elect DR 192.168.23.2

02:01:12: OSPF: Elect BDR 1.1.1.1

02:01:12: OSPF: Elect DR 192.168.23.2

02:01:12: DR: 192.168.23.2 (Id) BDR: 1.1.1.1 (Id)

02:01:12: OSPF: Send DBD to 192.168.23.2 on Ethernet0 seq 0x1513 opt 0x42 flag 0x7 len 32

02:01:15: OSPF: Rcv DBD from 192.168.23.2 on Ethernet0 seq 0x169C opt 0x42 flag 0x7 len 32 mtu 1500 state EXSTART

02:01:15: OSPF: NBR Negotiation Done. We are the SLAVE

02:01:15: OSPF: Send DBD to 192.168.23.2 on Ethernet0 seq 0x169C opt 0x42 flag 0x2 len 112

02:01:15: OSPF: Rcv DBD from 192.168.23.2 on Ethernet0 seq 0x169D opt 0x42 flag 0x3 len 92 mtu 1500 state EXCHANGE

02:01:15: OSPF: Send DBD to 192.168.23.2 on Ethernet0 seq 0x169D opt 0x42 flag 0x0 len 32

02:01:15: OSPF: Database request to 192.168.23.2

02:01:15: OSPF: sent LS REQ packet to 192.168.12.2, length 12

02:01:15: OSPF: Rcv DBD from 192.168.23.2 on Ethernet0 seq 0x169E opt 0x42 flag 0x1 len 32 mtu 1500 state EXCHANGE

02:01:15: OSPF: Exchange Done with 192.168.23.2 on Ethernet0

02:01:15: OSPF: Send DBD to 192.168.23.2 on Ethernet0 seq 0x169E opt 0x42 flag 0x0 len 32

02:01:15: OSPF: Synchronized with 192.168.23.2 on Ethernet0, state FULL

02:01:15: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.23.2 on Ethernet0 from LOADING to FULL, Loading Done

02:01:15: OSPF: Build router LSA for area 0, router ID 1.1.1.1, seq 0x80000006

cisco1(config-if)#end

cisco1#u all

问题分析:OSPF的整个邻居关系应该经历以下完整的过程

DOWN---INIT---2 WAY---EXSTART---EXCHANGE---LOADING---FULL

3.查看ospf邻居表

cisco1#show ip ospf neighbor

Neighbor ID Pri State Dead Time Address Interface

192.168.23.2 1 FULL/DR 00:00:39 192.168.12.2 Ethernet0

注:OSPF的HELLO 时间为10秒,HOLD时间为40秒。可以显示对端邻居的接口IP地址,可以查看OSPF的邻居状态,稳定时为FULL。

cisco2#show ip ospf neighbor

Neighbor ID Pri State Dead Time Address Interface

1.1.1.1 1 FULL/BDR 00:00:31 192.168.12.1 Ethernet0

3.3.3.3 1 FULL/ - 00:00:38 192.168.23.3 Serial1

注:-代表了cisco2和cisco3上却没有DR和BDR的选举

问题分析:为什么在cisco1和cisco2上有DR和BDR的选举过程,而cisco2和cisco3上却没有?我们要了解,对于DR和BDR的选举,是有条件的,那就是必须是要在多路访问的链路上进行,cisco1和cisco2是用以太网线链接,以太网的链路是星型结构,属于多路访问类型,可以参与DR和BDR的选举,但是cisco2和cisco3上使用的是serial线缆,它是属于点到点的专线结构,所以是没有必要参与DR和BDR的选举的。

4.查看参与OSPF进程的以太网口状态

cisco1#show ip ospf interface ethernet 0

Ethernet0 is up, line protocol is up

Internet Address 192.168.12.1/24, Area 0

Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 10--------------------以太网类型为多路访问(brocast)

Transmit Delay is 1 sec, State DROTHER, Priority 0

Designated Router (ID) 192.168.23.2, Interface address 192.168.12.2

No backup designated router on this network

Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5

Hello due in 00:00:07

Index 1/1, 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 8 msec

Neighbor Count is 1, Adjacent neighbor count is 1

Adjacent with neighbor 192.168.23.2 (Designated Router)

Suppress hello for 0 neighbor(s)

cisco2#show ip ospf interface serial 1

Serial1 is up, line protocol is up

Internet Address 192.168.23.2/24, Area 0

Process ID 1, Router ID 192.168.23.2, Network Type POINT_TO_POINT, Cost: 64--------------------Serial线缆为点到点类型的

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:00

Index 2/2, flood queue length 0

Next 0x0(0)/0x0(0)

Last flood scan length is 1, maximum is 2

Last flood scan time is 0 msec, maximum is 0 msec

Neighbor Count is 1, Adjacent neighbor count is 1

Adjacent with neighbor 3.3.3.3

Suppress hello for 0 neighbor(s)

以下是华为数通路由交换方向完整技术分享,欢迎对华为网络技术感兴趣的小伙伴们订阅。【可在专栏中进行查看订阅】


华为新版HCIP数通路由交换

华为新版HCIE数通路由交换