
配置交换机3
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#no logging console
Switch(config)#vlan 10
Switch(config-vlan)#interface vlan 10 //创建VLAN虚接口
Switch(config-if)#ip address 192.168.10.254 255.255.255.0
Switch(config-if)#interface fa0/1
Switch(config-if)#switchport access vlan 10
Switch(config-if)#interface fa0/24
Switch(config-if)#no shutdown
Switch(config-if)#no switchport //交换模式改成路由模式
Switch(config-if)#ip address 192.168.20.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#ip routing //启用路由功能
Switch(config)#router ospf 1
Switch(config-router)#network 192.168.20.0 0.0.0.255 area 1
Switch(config-router)#network 192.168.10.0 0.0.0.255 area 1
Switch(config-router)#redistribute connected //将直连链路发布到LSDB中
配置路由器R1
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no logging console
Router(config)#hostname R1
R1(config)#interface fa0/0
R1(config-if)#ip address 192.168.20.2 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#interface fa0/1
R1(config-if)#ip address 192.168.30.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#router ospf 1
R1(config-router)#network 192.168.20.0 0.0.0.255 area 1
R1(config-router)#network 192.168.30.0 0.0.0.255 area 0
配置路由器R2
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no logging console
Router(config)#hostname R2
R2(config)#interface fa0/0
R2(config-if)#ip address 192.168.30.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#interface fa0/1
R2(config-if)#ip address 192.168.40.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#router ospf 1
R2(config-router)#network 192.168.30.0 0.0.0.255 area 0
R2(config-router)#network 192.168.40.0 0.0.0.255 area 2
配置路由器R3
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no logging console
Router(config)#hostname R3
R3(config)#interface fa0/0
R3(config-if)#ip address 192.168.40.2 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#interface fa0/1
R3(config-if)#ip address 192.168.50.254 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#router ospf 1
R3(config-router)#network 192.168.40.0 0.0.0.255 area 2
R3(config-router)#network 192.168.50.0 0.0.0.255 area 2
结论:两台PC机可以相互ping通