一、實驗目的::用三層交換機讓同一vlan的主機能通信,不同vlan的主機也能通信
二、拓撲圖如下

三、具體步驟如下:、
先給每台主機和服務器配置ip地址和網關
例:

(1)S1三層交換機配置:
Switch>en --進入特權模式
Switch#conf t --進入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S1 --修改三層交換機主機名為S1
S1(config)#vtp domain test --創建vtp域
Domain name already set to test.
S1(config)#vtp mode server --設置當前交換機在vtp的工作模式為server
Device mode already VTP SERVER.
S1(config)#vlan 10 --創建vlan 10
S1(config-vlan)#vlan 20 --創建vlan 20
S1(config-vlan)#vlan 30 --創建vlan 30
S1(config-vlan)#vlan 40 --創建vlan40
S1(config-vlan)#interface f0/1 --進入端口
S1(config-if)#switchport mode access --將端口模式改為access模式
S1(config-if)#switchport mode trunk --將端口模式改為trunk模式
S1(config-if)#interface range f0/2-3 --進入端口
S1(config-if-range)#switchport mode access --將端口模式改為access模式
S1(config-if-range)#switchport access vlan 40 --將端口划入vlan 40
S1(config-if-range)#exit --返回上一級
S1(config)#ip routing --啟動三層交換機的路由功能
S1(config)#interface vlan 10 --進入vlan 10
S1(config-if)#ip address 192.168.1.254 255.255.255.0 --給vlan 10添加ip地址
S1(config-if)#interface vlan 20 --進入vlan 20
S1(config-if)#ip address 192.168.2.254 255.255.255.0 --給vlan 20添加ip地址
S1(config-if)#interface vlan 30 --進入vlan 30
S1(config-if)#ip address 192.168.3.254 255.255.255.0 --給vlan 30添加ip地址
S1(config-if)#interface vlan 40 --進入vlan 40
S1(config-if)#ip address 192.168.4.254 255.255.255.0 --給vlan 40添加ip地址
S1(config-if)#end --返回特權模式
S1#copy running-config startup-config --保存配置
[OK] --保存成功
(2)S2交換機配置
Switch>en --進入特權模式
Switch#conf t --進入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S2 --修改交換機名為S2
S2(config)#vtp mode client --設置當前交換機在vtp中為客戶機模式
Device mode already VTP CLIENT.
S2(config)#interface f0/10 --進入端口
S2(config-if)#switchport mode trunk --將端口設置為trunk模式
S2(config-if)#interface f0/1 --進入端口
S2(config-if)#switchport mode access --將端口設置為access模式
S2(config-if)#switchport access vlan 30 --將端口划入vlan30
S2(config-if)#interface f0/2 --進入端口
S2(config-if)#switchport mode access --將端口設置為access模式
S2(config-if)#switchport access vlan 20 --將端口划入vlan 20
S2(config-if)#interface f0/3 --進入端口
S2(config-if)#switchport mode access --將端口設置為access模式
S2(config-if)#switchport access vlan 10 --將端口划入vlan 10
S2(config-if)#end --返回特權模式
S2#copy running-config startup-config --保存配置
[OK] --保存成功
(3)S3交換機配置
Switch>en --進入特權模式
Switch#conf t --進入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S3 --修改交換機名為S3
S3(config)#vtp mode client --設置當前交換機在vtp中為客戶模式
Device mode already VTP CLIENT.
S3(config)#interface range f0/10-12 --進入端口
S3(config-if-range)#switchport mode trunk --將端口設置為trunk模式
S3(config-if-range)#interface f0/1 --進入端口
S3(config-if)#switchport mode access --將端口設置為access模式
S3(config-if)#switchport access vlan 30 --將端口划入vlan 30
S3(config-if)#interface f0/2 --進入端口
S3(config-if)#switchport mode access --將端口設置為access模式
S3(config-if)#switchport access vlan 20 --將端口划入vlan20
S3(config-if)#interface f0/3 --進入端口
S3(config-if)#switchport mode access --將端口設置為access模式
S3(config-if)#switchport access vlan 10 --將端口划入vlan 20
S3(config-if)#end --返回特權模式
S3#copy running-config startup-config --保存配置
[OK] --保存成功
(4)S4交換機配置
Switch>en --進入特權模式
Switch#conf t --進入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S4 --修改交換機名為S4
S4(config)#vtp mode client --設置當前交換機在vtp中為客戶模式
Device mode already VTP CLIENT.
S4(config)#interface f0/10 --進入端口
S4(config-if)#switchport mode trunk --將端口設置為trunk模式
S4(config-if)#interface f0/1 --進入端口
S4(config-if)#switchport mode access --將端口設置為access模式
S4(config-if)#switchport access vlan 30 --將端口划入vlan 30
S4(config-if)#interface f0/2 --進入端口
S4(config-if)#switchport mode access --將端口設置為access模式
S4(config-if)#switchport access vlan 20 --將端口划入vlan 20
S4(config-if)#interface f0/3 --進入端口
S4(config-if)#switchport mode access --將端口設置為access模式
S4(config-if)#switchport access vlan 10 --將端口划入vlan 10
S4(config-if)#end --返回特權模式
S4#copy running-config startup-config --保存配置
[OK] --保存成功
四、驗證
測試不同vlan下的主機是否互通
(1)PC11與PC33

vlan10與vlan30互通
(2)PC13與PC21

vlan10與vlan20互通
