OSPF工作过程,状态机,数据包,+网络实验

本文详细介绍了OSPF(开放最短路径优先)协议的工作原理、状态机及数据包类型,并通过一个具体的实验案例展示了如何在复杂的网络环境中配置OSPF,包括区域划分、虚链路设置及多进程双向重发布等高级特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

OSPF:开放性最短路径协议

1.简介:

 无类别链路状态协议;
 跨层封装,协议号89;
 组播更新:224.0.0.5(用在串行链路中),224.0.0.6(用在以太网中),存在触发更新和周期更新(30min);
 使用SPF算法;
 存在区域概念;

2.工作过程:

 激活协议后向所有的邻居发送hello包,建立邻居关系,生成邻居表。
 之后和满足的邻居之间建立邻接关系,交换LSA(链路状态通告);
 生成LSDB(链路状态数据库);
 之后基于数据库使用SPF算法计算达到所有未知目标的最短路径加到路由表中;
注:ospf收敛的过程被称为LSA洪范或LSDB同步;

3.OSPF的状态机:

  邻居关系:
  Down:一旦发出hello包将进入下一个状态
  Init:收到的hello包中存在本地的RID时进入下一个状态
  2-WAY:邻居关系建立
  匹配条件:
  1.点到点网路直接进入下一个阶段
  2.MA网络先选DR/BDR;非DR/BDR间不能进入下一个状态;
  Exstart:使用hello的DBD包进行主从关系的选举,主可以先行进入Exchange状态
  Exchange:使用DBD包进行拓扑目录的交互,需要ACK确认;
  Loading:使用LSR/LSU/LSACK获取未知拓扑信息;

4.OSPF的数据包

1.数据包结构

在这里插入图片描述

2.数据包类型

1.hello用于邻居的发现,邻居关系的建立;邻居和邻接关系的保活 hello time 10s或30s dead time 40s或120s

在这里插入图片描述
在这里插入图片描述

邻居间hello包中必须完全一致的参数:hello和dead 时间、区域ID、认证字段、末梢区域标识

OSPF区域划分规则
1.星型结构
2.ABR-区域边界路由器

OSPF实验

1.实验拓扑图

在这里插入图片描述

2.实验要求

1.R3-R5部分为internet,R4为ISP,其上只配置IP地址
2.R1-R3中R3为DR,无BDR;该段IP地址使用192.168.1.0/24
3.R5-R14的地址为172.16.0.0/16
4.合理规划IP地址,尽量减少LSA的更新量
5.R1-R3可以同R5-R14通信

3.实验规划

1.R1环回地址为1.1.1.1/24 直连地址使用192.168.1.1/24(ospf100)
2.R2环回地址为2.2.2.2/24 直连地址使用192.168.1.2/24(ospf100)
3.R3环回地址为3.3.3.3/24 直连地址使用192.168.1.3/24(ospf100)
4.R3-R4之间使用34.1.1.0/24网段,R4-R5之间使用45.1.1.0/24网段,ISP(R4)环回地址为4.4.4.4/24
5.R5-R14之间使用172.16.0.0/16网段
     area 0区域使用172.16.0.0/19,R5的环回地址172.16.16.0/22,R6的环回地址172.16.20.0/22,R7的环回地址172.16.24.0/22,R8的环回地址172.16.28.0/22,中间骨干地址使用172.16.0.0/20(ospf 100)
     area 1区域使用172.16.32.0/19,R8-R9之间使用172.16.32.0/21,R9的环回地址172.16.40.0/21,R9-R10之间使用172.16.56.0/21,R10环回地址172.16.48.0/21 (ospf 100)
     area 2区域使用172.16.64.0/19,R6-R11之间使用172.16.64.0/21,R11-R12之间使用172.16.72.0/21,R11环回地址172.16.89.0/20 (ospf 100)
     area 3区域使用172.16.96.0/19,R7-R13之间使用172.16.96.0/20,R13环回地址172.16.112.0/20(ospf 100)
     area 4区域使用172.16.128.0/19,R13-R14之间使用172.16.144.0/20,R14环回0口使用172.16.128.0/21,R14环回0口使用172.16.136.0/21(ospf 100)
     area 5区域使用172.16.160.0/19,R12环回0口使用172.16.160.0/20,R12环回1口使用172.16.176.0/20(ospf 101 做多进程双向重发布)
6.解决OSPF不规则区域问题
 (1)R3-R5首先跨运营商进行通信起TUNNEL,然后将TUNNEL宣告进OSPF,通过OSPF进行通信
 (2)R7和R13上用虚链路技术
 (3)R12上将两个环回宣告进进程ospf101,做多进程双向重发布
7.访问外网在R3和R5上配置

4.配置

R1

Router>enable	
Router#configure terminal 
Router(config)#hostname R1
R1(config)#no ip domain-lookup
R1(config)#line console 0
R1(config-line)#logging synchronous
R1(config-line)#exec-timeout 0 0
R1(config-line)#exit
**环回**
R1(config)#interface loopback 0
R1(config-if)#ip address 1.1.1.1 255.255.255.0
R1(config-if)#exit
**R1-R2-R3之间**
R1(config)#interface e0/0
R1(config-if)#ip address 192.168.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit 
**OSPF**
R1(config)#router ospf 100
R1(config-router)#router-id 1.1.1.1
R1(config-router)#exit
**进接口宣告**
R1(config)#interface loopback 0
R1(config-if)#ip ospf 100 area 0
R1(config-if)#exit
R1(config)#interface e0/0
R1(config-if)#ip ospf 100 area 0
R1(config-if)#exit

R2

Router>enable
Router#configure terminal
Router(config)#hostname R2
R2(config)#no ip domain-lookup
R2(config)#line console 0
R2(config-line)#logging synchronous
R2(config-line)#exec-timeout 0 0
R2(config-line)#exit
**环回**
R2(config)#interface loopback 0
R2(config-if)#ip address 2.2.2.2 255.255.255.0
R2(config-if)#exit 
**R1-R2-R3**
R2(config)#interface e0/0
R2(config-if)#ip address 192.168.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
**OSPF**
R2(config)#router ospf 100
R2(config-router)#router-id 2.2.2.2
R2(config-router)#exit
**进接口宣告**
R2(config)#interface loopback 0
R2(config-if)#ip ospf 100 area 0
R2(config-if)#exit
R2(config)#interface e0/0
R2(config-if)#ip ospf 100 area 0
R2(config-if)#exit

R3

Router>enable
Router#configure terminal
Router(config)#hostname R3
R3(config)#no ip domain-lookup
R3(config)#line console 0
R3(config-line)#logging synchronous
R3(config-line)#exec-timeout 0 0
R3(config-line)#exit
**环回**
R3(config)#interface loopback 0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R3(config-if)#exit
**R1-R2-R3**
R3(config)#interface e0/0
R3(config-if)#ip address 192.168.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
**R3-R4**
R3(config)#interface s3/0
R3(config-if)#ip address 34.1.1.1 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
**OSPF**
R3(config)#router ospf 100
R3(config-router)#router-id 3.3.3.3
R3(config-router)#exit
**进接口宣告**
R3(config)#interface loopback 0
R3(config-if)#ip ospf 100 area 0
R3(config-if)#exit
R3(config)#interface e0/0
R3(config-if)#ip ospf 100 area 0
R3(config-if)#exit
**R1-R2-R3访问外网**
    1.下放缺省
    R3(config)#ip route 0.0.0.0 0.0.0.0 s3/0
	R3(config)#router ospf 100
	R3(config-router)#default-information originate
	R3(config-router)#exit
	 2.定义内外网
	R3(config)#interface s3/0
	R3(config-if)#ip nat outside 
	R3(config-if)#exit
	R3(config)#interface e0/0
	R3(config-if)#ip nat inside
	R3(config-if)#exit
 	3.抓取感兴趣流量,NAT转换
	R3(config)#access-list 1 permit 192.168.1.0 0.0.0.255
	R3(config)#ip nat inside source list 1 interface s3/0
**TUNNEL,R1,2,3与R5-14通信**
R3(config)#interface tunnel 0
R3(config-if)#ip address 12.1.1.1 255.255.255.0
R3(config-if)#tunnel source s3/0
R3(config-if)#tunnel destination 45.1.1.2
R3(config-if)#exit
**将TUNNEL宣告进OSPF**
R3(config)#interface tunnel 0
R3(config-if)#ip ospf 100 area 0
R3(config-if)#exit

R4(ISP)

Router>enable
Router#configure terminal
Router(config)#hostname R4
R4(config)#no ip domain-lookup
R4(config)#line console 0
R4(config-line)#logging synchronous
R4(config-line)#exec-timeout 0 0
R4(config-line)#exit
**环回**
R4(config)#interface loopback 0
R4(config-if)#ip address 4.4.4.4 255.255.255.0
R4(config-if)#exit
**R3-R4**
R4(config)#interface s3/1
R4(config-if)#ip address 34.1.1.2 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#exit
**R4-R5**
R4(config)#interface s3/0
R4(config-if)#ip address 45.1.1.1 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#exit

R5

Router>enable
Router#configure terminal
Router(config)#hostname R5
R5(config)#no ip domain-lookup
R5(config)#line console 0
R5(config-line)#logging synchronous
R5(config-line)#exec-timeout 0 0
R5(config-line)#exit
**R4-R5**
R5(config)#interface s3/1
R5(config-if)#ip address 45.1.1.2 255.255.255.0
R5(config-if)#no shutdown
R5(config-if)#exit
**R5-R6-R7-R8**
R5(config)#interface e0/0
R5(config-if)#ip address 172.16.0.1 255.255.240.0
R5(config-if)#no shutdown 
R5(config-if)#exit 
**环回**
R5(config)#interface loopback 0
R5(config-if)#ip address 172.16.16.1 255.255.252.0
R5(config-if)#exit
**OSPF**
R5(config)#router ospf 100
R5(config-router)#router-id 5.5.5.5
R5(config-router)#exit
**进接口宣告**
R5(config)#interface loopback 0
R5(config-if)#ip ospf 100 area 0
R5(config-if)#exit
R5(config)#interface e0/0
R5(config-if)#ip ospf 100 area 0
R5(config-if)#exit
**R5-14访问外网**
	1.下放缺省
	R5(config)#ip route 0.0.0.0 0.0.0.0 s3/1
	R5(config)#router ospf 100
	R5(config-router)#default-information originate
	R5(config-router)#exit
	2.定义内外网
	R5(config)#interface s3/1
	R5(config-if)#ip nat outside
	R5(config-if)#exit 
	R5(config)#interface e0/0
	R5(config-if)#ip nat inside
	R5(config-if)#exit
	3.定义感兴趣流量,NAT转换
	R5(config)#access-list 1 permit 172.16.0.0 0.0.255.255
	R5(config)#ip nat inside source list 1 interface s3/1
**TUNNEL,R1,2,3与R5-14通信**
R5(config)#interface tunnel 0
R5(config-if)#ip address 12.1.1.2 255.255.255.0
R5(config-if)#tunnel source s3/1
R5(config-if)#tunnel destination 34.1.1.1
R5(config-if)#exit 
**将TUNNEL宣告进OSPF**
R5(config)#interface tunnel 0
R5(config-if)#ip ospf 100 area 0
R5(config-if)#exit

R6

Router>enable
Router#configure terminal
Router(config)#hostname R6
R6(config)#no ip domain-lookup
R6(config)#line console 0
R6(config-line)#logging synchronous
R6(config-line)#exec-timeout 0 0
R6(config-line)#exit
**环回**
R6(config)#interface loopback 0
R6(config-if)#ip address 172.16.20.1 255.255.252.0
R6(config-if)#exit 
**R5-R6-R7-R8**
R6(config)#interface e0/0
R6(config-if)#ip address 172.16.0.2 255.255.240.0
R6(config-if)#no shutdown 
R6(config-if)#exit 
R6(config)#exit 
**R6-R11**
R6(config)#interface s3/0
R6(config-if)#ip address 172.16.64.1 255.255.248.0
R6(config-if)#no shutdown
R6(config-if)#exit
**OSPF**
R6(config)#router ospf 100
R6(config-router)#router-id 6.6.6.6
R6(config-router)#exit
**进接口宣告**
R6(config)#interface loopback 0
R6(config-if)#ip ospf 100 area 0
R6(config-if)#exit
R6(config)#interface e0/0
R6(config-if)#ip ospf 100 area 0
R6(config-if)#exit
注:
	R6(config)#interface s3/0
	R6(config-if)#ip ospf 100 area 2
	R6(config-if)#exit

R7

Router>enable 
Router#configure terminal
Router(config)#hostname R7
R7(config)#no ip domain-lookup
R7(config)#line console 0
R7(config-line)#logging synchronous
R7(config-line)#exec-timeout 0 0
R7(config-line)#exit
**环回**
R7(config)#interface loopback 0
R7(config-if)#ip address 172.16.24.1 255.255.252.0
R7(config-if)#exit
**R5-R6-R7-R8**
R7(config)#interface e0/0
R7(config-if)#ip address 172.16.0.3 255.255.240.0
R7(config-if)#no shutdown
R7(config-if)#exit
**R7-R13**
R7(config)#interface s3/0
R7(config-if)#ip address 172.16.96.1 255.255.240.0
R7(config-if)#no shutdown
R7(config-if)#exit
**OSPF**
R7(config)#router ospf 100
R7(config-router)#router-id 7.7.7.7
R7(config-router)#exit
**进接口宣告**
R7(config)#interface loopback 0
R7(config-if)#ip ospf 100 area 0
R7(config-if)#exit
R7(config)#interface e0/0
R7(config-if)#ip ospf 100 area 0
R7(config-if)#exit
注:
    R7(config)#interface s3/0
    R7(config-if)#ip ospf 100 area 3
    R7(config-if)#exit 
**虚链路解决area4区域通信问题**
R7(config)#router ospf 100
R7(config-router)#area 3 virtual-link 13.13.13.13
R7(config-router)#exit

R8

Router>enable
Router#configure terminal
Router(config)#hostname R8
R8(config)#no ip domain-lookup 
R8(config)#line console 0
R8(config-line)#logging synchronous
R8(config-line)#exec-timeout 0 0
R8(config-line)#exit
**环回**
R8(config)#interface loopback 0
R8(config-if)#ip address 172.16.28.1 255.255.252.0
R8(config-if)#exit 
**R5-R6-R7-R8**
R8(config)#interface e0/0
R8(config-if)#ip address 172.16.0.4 255.255.240.0
R8(config-if)#no shutdown 
R8(config-if)#exit 
**R8-R9**
R8(config)#interface s3/0
R8(config-if)#ip address 172.16.32.1 255.255.248.0
R8(config-if)#no shutdown 
R8(config-if)#exit
**OSPF**
R8(config)#router ospf 100
R8(config-router)#router-id 8.8.8.8
R8(config-router)#exit
**进接口宣告**
R8(config)#interface loopback 0
R8(config-if)#ip ospf 100 area 0
R8(config-if)#exit
R8(config)#interface e0/0
R8(config-if)#ip ospf 100 area 0
R8(config-if)#exit 
注:
  R8(config)#interface s3/0
  R8(config-if)#ip ospf 100 area 1
  R8(config-if)#exit

R9

Router>enable
Router#configure terminal
Router(config)#hostname R9
R9(config)#no ip domain-lookup
R9(config)#line console 0
R9(config-line)#logging synchronous 
R9(config-line)#exec-timeout 0 0
R9(config-line)#exit
**R8-R9**
R9(config)#interface s3/1
R9(config-if)#ip address 172.16.32.2 255.255.248.0
R9(config-if)#no shutdown 
R9(config-if)#exit
**环回**
R9(config)#interface loopback 0
R9(config-if)#ip address 172.16.40.1 255.255.248.0
R9(config-if)#exit
**R9-R10**
R9(config)#interface s3/0
R9(config-if)#ip address 172.16.48.1 255.255.248.0
R9(config-if)#no shutdown
R9(config-if)#exit
**OSPF**
R9(config)#router ospf 100
R9(config-router)#router-id 9.9.9.9
R9(config-router)#exit 
**进接口宣告**
R9(config)#interface loopback 0
R9(config-if)#ip ospf 100 area 1
R9(config-if)#exit
R9(config)#interface s3/1
R9(config-if)#ip ospf 100 area 1
R9(config)#interface s3/0
R9(config-if)#ip ospf 100 area 1
R9(config-if)#exit

R10

Router>enable
Router#configure terminal
Router(config)#hostname R10
R10(config)#no ip domain-lookup 
R10(config)#line console 0
R10(config-line)#logging synchronous
R10(config-line)#exec-timeout 0 0
R10(config-line)#exit
**环回**
R10(config)#interface loopback 0
R10(config-if)#ip address 172.16.56.1 255.255.248.0
R10(config-if)#exit
**R9-R10**
R10(config)#interface s3/1
R10(config-if)#ip address 172.16.48.2 255.255.248.0
R10(config-if)#no shutdown 
R10(config-if)#exit 
**OSPF**
R10(config)#router ospf 100
R10(config-router)#router-id 10.10.10.10
R10(config-router)#exit 
**进接口宣告**
R10(config)#interface loopback 0
R10(config-if)#ip ospf 100 area 1
R10(config-if)#exit 
R10(config)#interface s3/1
R10(config-if)#ip ospf 100 area 1
R10(config-if)#exit 

R11

Router>enable
Router#configure terminal
Router(config)#hostname R11
R11(config)#no ip domain-lookup
R11(config)#line console 0
R11(config-line)#logging synchronous
R11(config-line)#exec-timeout 0 0
R11(config-line)#exit
**R6-R11**
R11(config)#interface s3/1
R11(config-if)#ip address 172.16.64.2 255.255.248.0
R11(config-if)#no shutdown
R11(config-if)#exit 
R11(config)#interface loopback 0
R11(config-if)#ip address 172.16.80.1 255.255.240.0
R11(config-if)#exit
**R11-R12**
R11(config)#interface s3/0
R11(config-if)#ip address 172.16.72.1 255.255.248.0
R11(config-if)#no shutdown 
R11(config-if)#exit
**OSPF**
R11(config)#router ospf 100
R11(config-router)#router-id 11.11.11.11
R11(config-router)#exit
**进接口宣告**
R11(config)#interface s3/1
R11(config-if)#ip ospf 100 area 2
R11(config-if)#exit 
R11(config)#interface loopback 0
R11(config-if)#ip ospf 100 area 2
R11(config-if)#exit 
R11(config)#interface s3/0
R11(config-if)#ip ospf 100 area 2
R11(config-if)#exit

R12

Router>enable
Router#configure terminal
Router(config)#hostname R12
R12(config)#no ip domain-lookup
R12(config)#line console 0
R12(config-line)#logging synchronous
R12(config-line)#exec-timeout 0 0
R12(config-line)#exit
**R11-R12**
R12(config)#interface s3/1
R12(config-if)#ip address 172.16.72.2 255.255.248.0
R12(config-if)#no shutdown
R12(config-if)#exit 
**环回0**
R12(config)#interface loopback 0
R12(config-if)#ip address 172.16.160.1 255.255.240.0
R12(config-if)#exit
**环回1**
R12(config)#interface loopback 1
R12(config-if)#ip address 172.16.176.1 255.255.240.0
R12(config-if)#exit 
**OSPF**
R12(config)#router ospf 100
R12(config-router)#router-id 12.12.12.12
R12(config-router)#exit 
**进接口宣告**
R12(config)#interface s3/1
R12(config-if)#ip ospf 100 area 2
R12(config-if)#exit 
注:
**OSPF 101**
R12(config)#router ospf 101
R12(config-router)#router-id 12.12.13.12
R12(config-router)#exit
**进接口宣告**
R12(config)#interface loopback 0
R12(config-if)#ip ospf 101 area 5
R12(config-if)#exit
R12(config)#interface loopback 1
R12(config-if)#ip ospf 101 area 5
R12(config-if)#exit
**多进程双向重发布**
R12(config)#router ospf 100
R12(config-router)#redistribute ospf 101 subnets
R12(config-router)#exit
R12(config)#router ospf 101
R12(config-router)#redistribute ospf 100 subnets 
R12(config-router)#exit 

R13

Router>enable
Router#configure terminal
Router(config)#hostname R13
R13(config)#no ip domain-lookup
R13(config)#line console 0
R13(config-line)#logging synchronous
R13(config-line)#exec-timeout 0 0
**R7-R13**
R13(config)#interface s3/1
R13(config-if)#ip address 172.16.96.2 255.255.240.0
R13(config-if)#no shutdown 
R13(config-if)#exit 
**环回**
R13(config)#interface loopback 0
R13(config-if)#ip address 172.16.112.1 255.255.240.0 
R13(config-if)#exit
**R13-R14**
R13(config)#interface s3/0
R13(config-if)#ip address 172.16.144.1 255.255.240.0
R13(config-if)#no shutdown
R13(config-if)#exit
**OSPF**
R13(config)#router ospf 100
R13(config-router)#router-id 13.13.13.13
R13(config-router)#exit
**进接口宣告**
R13(config)#interface s3/1
R13(config-if)#ip ospf 100 area 3
R13(config-if)#exit
R13(config)#interface loopback 0
R13(config-if)#ip ospf 100 area 3
注:
	R13(config)#interface s3/0
	R13(config-if)#ip ospf 100 area 4
	R13(config-if)#exit
**虚链路解决area4区域通信问题**
R13(config)#router ospf 100
R13(config-router)#area 3 virtual-link 7.7.7.7
R13(config-router)#exit

R14

Router>enable
Router#configure terminal
Router(config)#hostname R14
R14(config)#no ip domain-lookup
R14(config)#line console 0
R14(config-line)#logging synchronous
R14(config-line)#exec-timeout 0 0
R14(config-line)#exit 
**R13-R14**
R14(config)#interface s3/1
R14(config-if)#ip address 172.16.144.2 255.255.240.0
R14(config-if)#no shutdown
R14(config-if)#exit
**环回0**
R14(config)#interface loopback 0
R14(config-if)#ip address 172.16.128.1 255.255.248.0
R14(config-if)#exit 
**环回1**
R14(config)#interface loopback 1
R14(config-if)#ip address 172.16.136.1 255.255.248.0
R14(config-if)#exit
**OSPF**
R14(config)#router ospf 100
R14(config-router)#router-id 14.14.14.14
R14(config-router)#exit
**进接口宣告**
R14(config)#interface loopback 0
R14(config-if)#ip ospf 100 area 4
R14(config-if)#exit
R14(config)#interface loopback 1
R14(config-if)#ip ospf 100 area 4
R14(config-if)#exit
R14(config)#interface s3/1
R14(config-if)#ip ospf 100 area 4
R14(config-if)#exit

5.实验测试

1.R1的路由表

在这里插入图片描述
在这里插入图片描述

2.R1,R10,R12,R14访问外网

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.R2与R10通信

在这里插入图片描述
在这里插入图片描述

R1与R12通信

在这里插入图片描述
在这里插入图片描述

R3与R14通信

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值