交换机如何配置OSPF?
一、组网需求
配置OSPF动态路由协议,让全网可以互通
二、组网拓扑
三、配置要点
四、配置步骤
注意:配置之前建议使用 Ruijie#show interface status查看接口名称,常用接口名称有FastEthernet(百兆)、GigabitEthernet(千兆)和TenGigabitEthernet(万兆),以下配置以千兆接口为例
1)根据规划,在设备接口上配置IP地址
SWA配置:
Ruijie(config)#interface GigabitEthernet 0/1
Ruijie(config-if-GigabitEthernet 0/1)#no switchport------>把接口属性改成路由接口
Ruijie(config-if-GigabitEthernet 0/1)#ip address 192.168.1.1 255.255.255.0 ------>配置IP地址
Ruijie(config)#interface Loopback 0 ------>作为OSPF的router-id
Ruijie(config-Loopback 1)#ip address 172.16.1.1 255.255.255.0
SWB配置:
Ruijie(config)#interface GigabitEthernet 0/1
Ruijie(config-if-GigabitEthernet 0/1)#no switchport
Ruijie(config-if-GigabitEthernet 0/1)#ip address 192.168.1.2 255.255.255.0
Ruijie(config)#interfaceGigabitEthernet 0/2
Ruijie(config-GigabitEthernet 0/2)#no switchport
Ruijie(config-GigabitEthernet 0/2)#ip address 192.168.2.2 255.255.255.0
Ruijie(config)#interfaceGigabitEthernet 0/3
Ruijie(config-GigabitEthernet 0/3)#no switchport
Ruijie(config-GigabitEthernet 0/3)#ip address 192.168.3.2 255.255.255.0
Ruijie(config)#interface Loopback 0
Ruijie(config-Loopback 0)#ip address 172.16.1.2 255.255.255.0
SWC配置 :
Ruijie(config)#interface GigabitEthernet 0/1
Ruijie(config-if-GigabitEthernet 0/1)#no switchport
Ruijie(config)#ip address 192.168.2.1 255.255.255.0
Ruijie(config)#interface Loopback 0
Ruijie(config-Loopback 0)#ip address 172.16.1.3 255.255.255.0
SWD配置 :
Ruijie(config)#interface GigabitEthernet 0/1
Ruijie(config-if-GigabitEthernet 0/1)#no switchport
Ruijie(config)#ip address 192.168.3.1 255.255.255.0
Ruijie(config)#interface Loopback 0
Ruijie(config-Loopback 0)#ip address 172.16.1.4 255.255.255.0
2)配置OSPF进程
SW A配置:
Ruijie(config)#router ospf 10 ------>开启ospf 10 进程
Ruijie(config-router)#network 192.168.1.0 0.0.0.255 area 0 ------>把包含192.168.1.0 /24的网络划入区域 0
SW B配置:
Ruijie(config)#router ospf 10
Ruijie(config-router)#network 192.168.1.0 0.0.0.255 area 0
Ruijie(config-router)#network 192.168.2.0 0.0.0.255 area 1
Ruijie(config-router)#network 192.168.3.0 0.0.0.255 area 2
SW C配置:
Ruijie(config)#router ospf 10
Ruijie(config-router)#network 192.168.2.0 0.0.0.255 area 1
SW D配置:
Ruijie(config)#router ospf 10
Ruijie(config-router)#network 192.168.3.0 0.0.0.255 area 2
3)保存配置
Ruijie(config-router)#end
Ruijie#write ------>确认配置正确,保存配置
五、验证命令:
Ruijie#show ip route
Codes: C - connected, S - static, R - RIP, B - BGP
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
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default
Gateway of last resort is no set
C 172.16.1.0/24 is directly connected, Loopback 0
C 172.16.1.1/32 is local host.
C 192.168.1.0/24 is directly connected, GigabitEthernet 0/1
C 192.168.1.2/32 is local host.
O IA 192.168.2.0/24 [110/2] via 192.168.1.1, 00:55:30, GigabitEthernet 0/1 ------>O 表示OSPF学到的路由,O IA表示学到其他区域(area)路由条目
O IA 192.168.3.0/24 [110/2] via 192.168.1.1, 00:56:06, GigabitEthernet 0/1
Ruijie# show ip ospf neighbor ----查看OSPF邻居状态
OSPF process 10, 1 Neighbors, 1 is Full:
Neighbor ID Pri State Dead Time Address Interface
172.16.1.2 1 Full/BDR 00:00:38 192.168.1.1 GigabitEthernet 0/1