思科模拟器中配置单区域OSPF
拓扑图
SW1的命令
Switch>enable #特权模式Switch#conf#全局配置模式 Switch(config)#hostname SW1 #改名SW1SW1(config)#vlan 10#划分VLAN 10SW1(config-vlan)#ex#退出 exitSW1(config)#interface vlan 10#进入vlan 10SW1(config-if)#ip address 192.168.1.1 255.255.255.0#给vlan 10 设置 IP地址SW1(config-if)#ex#进入端口F0/1 ,加入vlan10SW1(config)#int f0/1SW1(config-if)#switchport access vlan 10#进入端口F0/2,设置IP,和接口模式SW1(config)#int f0/2SW1(config-if)#no shutdown (使此端口变为三层端口)把端口变成路由口。然后就可以再这个端口上配置IP地址。就和路由器端口一样了SW1(config-if)#ip address 192.168.10.1 255.255.255.0SW1(config-if)#shutdown #关SW1(config-if)#no shutdown #开测试:SW1(config-if)#^Z (Ctrl+Z组合键)
测试
RT0设置
#设置就比较简单了,主要就是给二个端口设置IPRouter(config)#int g0/0Router(config-if)#ip address 192.168.10.2 255.255.255.0Router(config)#int g0/1Router(config-if)#ip address 192.168.20.1 255.255.255.0
#RT1设置
#设置和RT0一样Router(config)#interface FastEthernet0/0Router(config-if)#ip address 192.168.20.2 255.255.255.0Router(config)#int f1/0Router(config-if)#ip address 192.168.30.2 255.255.255.0
OSPF
SW1查看路由信息表SW1>enableSW1#show ip route Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGPi - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area* - candidate default, U - per-user static route, o - ODRP - periodic downloaded static routeGateway of last resort is not setC 192.168.1.0/24 is directly connected, Vlan10C 192.168.10.0/24 is directly connected, FastEthernet0/2#C开头为直连网段
SW1#configure terminalSW1(config)#ip routing(在三层交换机上打开路由功能,默认是关闭的)SW1(config)#router ospf 1 (1代表运行于进程1,仅本地有效)SW1(config-router)#network 192.168.1.0 0.0.0.255 area 0 (将192.168.1.0 0.0.0.255这段路由宣告到area 0里,这里需要用到反掩码)SW1(config-router)#network 192.168.10.0 0.0.0.255 area 0
后面路由器设置都是一样的需要把设置的IP添加进去
Router(config-router)#network 192.168.10.0 0.0.0.255 area 0Router(config-router)#network 192.168.20.0 0.0.0.255 area 0
测试
SW1#show ip route Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGPi - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area* - candidate default, U - per-user static route, o - ODRP - periodic downloaded static routeGateway of last resort is not setC 192.168.1.0/24 is directly connected, Vlan10C 192.168.10.0/24 is directly connected, FastEthernet0/2O 192.168.20.0/24 [110/2] via 192.168.10.2, 00:00:23, FastEthernet0/2O 192.168.30.0/24 [110/3] via 192.168.10.2, 00:00:13, FastEthernet0/2
通过PC1和PC2 PING 测试
+