Switch>enable #特权模式
Switch#conf #全局配置模式
Switch(config)#hostname SW1 #改名SW1
SW1(config)#vlan 10 #划分VLAN 10
SW1(config-vlan)#ex #退出 exit
SW1(config)#interface vlan 10 #进入vlan 10
SW1(config-if)#ip address 192.168.1.1 255.255.255.0 #给vlan 10 设置 IP地址
SW1(config-if)#ex
#进入端口F0/1 ,加入vlan10
SW1(config)#int f0/1
SW1(config-if)#switchport access vlan 10
#进入端口F0/2,设置IP,和接口模式
SW1(config)#int f0/2
SW1(config-if)#no shutdown
(使此端口变为三层端口)
把端口变成路由口。然后就可以再这个端口上配置IP地址。就和路由器端口一样了
SW1(config-if)#ip address 192.168.10.1 255.255.255.0
SW1(config-if)#shutdown #关
SW1(config-if)#no shutdown #开
测试:
SW1(config-if)#^Z (Ctrl+Z组合键)
#设置就比较简单了,主要就是给二个端口设置IP
Router(config)#int g0/0
Router(config-if)#ip address 192.168.10.2 255.255.255.0
Router(config)#int g0/1
Router(config-if)#ip address 192.168.20.1 255.255.255.0
#RT1设置
#设置和RT0一样
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 192.168.20.2 255.255.255.0
Router(config)#int f1/0
Router(config-if)#ip address 192.168.30.2 255.255.255.0
SW1
查看路由信息表
SW1>enable
SW1#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, 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, E - EGP
i - 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 - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, Vlan10
C 192.168.10.0/24 is directly connected, FastEthernet0/2
#C开头为直连网段
SW1#configure terminal
SW1(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 0
Router(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 - BGP
D - EIGRP, EX - EIGRP external, 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, E - EGP
i - 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 - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, Vlan10
C 192.168.10.0/24 is directly connected, FastEthernet0/2
O 192.168.20.0/24 [110/2] via 192.168.10.2, 00:00:23, FastEthernet0/2
O 192.168.30.0/24 [110/3] via 192.168.10.2, 00:00:13, FastEthernet0/2