2025.12.19 OSPF

OSPF基本概念

OSPF路由协议概述

        内部网关协议和外部网关协议

        自治系统(AS)

        内部网关协议(IGP)

        外部网关协议(EGP)

邻接关系的建立

        OSPF工作过程

        建立邻里关系→链路状态数据库→最短路径树→路由表

                  学习链路状态信息     Dijkstra算法

区域ID

        区域ID可以表示成一个十进制的数字

        也可以表示成一个IP

骨干区域

        负责区域间路由信息传播(中心区域)

OSPF将网络划分为四种类型

        点到点网络

        点到多点网络

       广播多路访问网络

        非广播多路网络

基本配置命令

router ospf [process-id]         启用OSPF路由进程

                        

network [address] [inverse-mask] area [area-id]        公布路由器所在IP网段

               IP网段        反掩码                   区域号

show ip ospf [neighbor]       查看[邻居]OSPF的配置

实验、完成以下单区域网络结构的OSPF的通信

创建网络结构图,并标注,(Router0与Router3需要添加NM-2FE2W的接口,先关机再添加)。

配置IP

Router0

Router(config)#int f0/0

Router(config-if)#ip address 192.168.10.1 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#int f0/1

Router(config-if)#ip address 192.168.20.1 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#int f1/0

Router(config-if)#ip address 192.168.70.2 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router1

Router(config)#int f0/0

Router(config-if)#ip address 192.168.20.2 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#int f0/1

Router(config-if)#ip address 192.168.30.1 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router2

Router(config)#int f0/0

Router(config-if)#ip address 192.168.30.2 255.255.255.0

Router(config-if)#exit

Router(config)#int f0/1

Router(config-if)#ip address 192.168.40.1 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router3

Router(config)#int f0/0

Router(config-if)#ip address 192.168.40.2 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#int f0/1

Router(config-if)#ip address 192.168.50.1 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#int f1/0

Router(config-if)#ip address 192.168.60.1 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router4

Router(config)#int f0/0

Router(config-if)#ip address 192.168.60.2 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#int f0/1

Router(config-if)#ip add 192.168.70.1 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

配置完每个路由器与PC机的IP后,启动每个路由器的路由进程,并公布自身的直连网段。

Router0

Router(config)#router ospf 1

Router(config-router)#network 192.168.10.0 0.0.0.255 area 0

Router(config-router)#network 192.168.20.0 0.0.0.255 area 0

Router(config-router)#network 192.168.70.0 0.0.0.255 area 0

Router1

Router(config)#router ospf 1

Router(config-router)#network 192.168.20.0 0.0.0.255 area 0

Router(config-router)#network 192.168.30.0 0.0.0.255 area 0

Router2

Router(config)#router ospf 1

Router(config-router)#network 192.168.30.0 0.0.0.255 area 0

Router(config-router)#network 192.168.40.0 0.0.0.255 area 0

Router3

Router(config)#router ospf 1

Router(config-router)#network 192.168.40.0 0.0.0.255 area 0

Router(config-router)#network 192.168.50.0 0.0.0.255 area 0

Router(config-router)#network 192.168.60.0 0.0.0.255 area 0

Router4

Router(config)#router ospf 1

Router(config-router)#network 192.168.60.0 0.0.0.255 area 0

Router(config-router)#network 192.168.70.0 0.0.0.255 area 0

配置完成后,使用PC0pingPC1,能够ping通。

再通过抓包可以看到,OSPF协议会自动选择最优路径完成通信,而不是选择路由器的创建先后顺序来完成通信。这里的路线是从PC0→Route0→Router4→Router3→PC1

The device is running! ############## <lsw1>sys Enter system view, return user view with Ctrl+Z. [lsw1]sys S1 [S1] Nov 23 2025 14:23:42-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 1, the ch ange loop count is 0, and the maximum number of records is 4095. [S1]int eth-trunk 1 [S1-Eth-Trunk1]int g0/0/1 [S1-GigabitEthernet0/0/1]eth-trunk 1 Info: This operation may take a few seconds. Please wait for a moment...done. [S1-GigabitEthernet0/0/1] Nov 23 2025 14:28:31-08:00 S1 %%01IFNET/4/IF_STATE(l)[54]:Interface Eth-Trunk1 h as turned into UP state. [S1-GigabitEthernet0/0/1] Nov 23 2025 14:28:33-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 2, the ch ange loop count is 0, and the maximum number of records is 4095.int g0/0/2 [S1-GigabitEthernet0/0/2]eth-trunk 1 Info: This operation may take a few seconds. Please wait for a moment...done. [S1-GigabitEthernet0/0/2] Nov 23 2025 14:28:53-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 3, the ch ange loop count is 0, and the maximum number of records is 4095. [S1-GigabitEthernet0/0/2]int eth-trunk 1 [S1-Eth-Trunk1]port link-type trunk [S1-Eth-Trunk1]port trunk Nov 23 2025 14:29:33-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 4, the ch ange loop count is 0, and the maximum number of records is 4095.all vlan 10 20 [S1-Eth-Trunk1] Nov 23 2025 14:29:43-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 5, the ch ange loop count is 0, and the maximum number of records is 4095. [S1-Eth-Trunk1]vlan batch 10 20 30 Info: This operation may take a few seconds. Please wait for a moment...done. [S1] Nov 23 2025 14:30:13-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 6, the ch ange loop count is 0, and the maximum number of records is 4095. [S1]int g0/0/24 [S1-GigabitEthernet0/0/24]port link-type access [S1-GigabitEthernet0/0/24]port Nov 23 2025 14:30:53-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 7, the ch ange loop count is 0, and the maximum number of records is 4095.defa vlan 30 [S1-GigabitEthernet0/0/24] Nov 23 2025 14:31:03-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 8, the ch ange loop count is 0, and the maximum number of records is 4095. [S1-GigabitEthernet0/0/24]q [S1]int vlan10 [S1-Vlanif10] Nov 23 2025 14:31:38-08:00 S1 %%01IFNET/4/IF_STATE(l)[55]:Interface Vlanif10 has turned into UP state. [S1-Vlanif10]ip add 10.1.10.254 24 [S1-Vlanif10] Nov 23 2025 14:31:51-08:00 S1 %%01IFNET/4/LINK_STATE(l)[56]:The line protocol IP on the interface Vlanif10 has entered the UP state. [S1-Vlanif10] Nov 23 2025 14:31:53-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 9, the ch ange loop count is 0, and the maximum number of records is 4095. [S1-Vlanif10]int vlan20 [S1-Vlanif20] Nov 23 2025 14:32:41-08:00 S1 %%01IFNET/4/IF_STATE(l)[57]:Interface Vlanif20 has turned into UP state. [S1-Vlanif20]ip add 10.1.20.254 24 [S1-Vlanif20] Nov 23 2025 14:32:53-08:00 S1 %%01IFNET/4/LINK_STATE(l)[58]:The line protocol IP on the interface Vlanif20 has entered the UP state. [S1-Vlanif20]int vla Nov 23 2025 14:33:03-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 10, the c hange loop count is 0, and the maximum number of records is 4095.n30 [S1-Vlanif30] Nov 23 2025 14:33:05-08:00 S1 %%01IFNET/4/IF_STATE(l)[59]:Interface Vlanif30 has turned into UP state. [S1-Vlanif30]ip add 10.1.30.254 24 [S1-Vlanif30] Nov 23 2025 14:33:18-08:00 S1 %%01IFNET/4/LINK_STATE(l)[60]:The line protocol IP on the interface Vlanif30 has entered the UP state. [S1-Vlanif30] Nov 23 2025 14:33:23-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 11, the c hange loop count is 0, and the maximum number of records is 4095. [S1-Vlanif30]q [S1]dhcp enable Info: The operation may take a few seconds. Please wait for a moment.done. [S1] Nov 23 2025 14:35:23-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 12, the c hange loop count is 0, and the maximum number of records is 4095. [S1]ip pool vlan10 Info:It's successful to create an IP address pool. [S1-ip-pool-vlan10] Nov 23 2025 14:35:43-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 13, the c hange loop count is 0, and the maximum number of records is 4095. [S1-ip-pool-vlan10]net 10.1.10.0 mask 255.255.255.0 [S1-ip-pool-vlan10] Nov 23 2025 14:36:13-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 14, the c hange loop count is 0, and the maximum number of records is 4095. [S1-ip-pool-vlan10]gat [S1-ip-pool-vlan10]gateway-list 10.1.10.254 [S1-ip-pool-vlan10]lease da Nov 23 2025 14:36:33-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 15, the c hange loop count is 0, and the maximum number of records is 4095.y 2 [S1-ip-pool-vlan10]dn Nov 23 2025 14:36:43-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 16, the c hange loop count is 0, and the maximum number of records is 4095.s-l [S1-ip-pool-vlan10]dns-list 8.8.8.8 [S1-ip-pool-vlan10]q [S1]in Nov 23 2025 14:37:03-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 17, the c hange loop count is 0, and the maximum number of records is 4095.t vlanif10 [S1-Vlanif10]dhcp se [S1-Vlanif10]dhcp select g [S1-Vlanif10]dhcp select global [S1-Vlanif10] Nov 23 2025 14:37:33-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 18, the c hange loop count is 0, and the maximum number of records is 4095. [S1-Vlanif10]undo dhcp select global [S1-Vlanif10] Nov 23 2025 14:41:53-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 19, the c hange loop count is 0, and the maximum number of records is 4095.dhcp se [S1-Vlanif10]dhcp select re [S1-Vlanif10]dhcp select relay [S1-Vlanif10]dhcp Nov 23 2025 14:42:13-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 20, the c hange loop count is 0, and the maximum number of records is 4095. [S1-Vlanif10]dhcp r [S1-Vlanif10]dhcp relay s [S1-Vlanif10]dhcp relay server-ip 10.1.30.253 [S1-Vlanif10] Nov 23 2025 14:42:53-08:00 S1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25. 191.3.1 configurations have been changed. The current change number is 21, the c hange loop count is 0, and the maximum number of records is 4095.
11-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值