技术原理
l? 三层交换机具备网络层的功能,实现VLAN相互访问的原理是:利用三层交换机的路由功能,通过识别数据包的IP地址,查找路由表进行选路转发,三层交换机利用直连路由可以实现不同VLAN之间的相互访问。三层交换机给接口配置IP地址。采用SVI(交换虚拟接口)的方式实现VLAN间互连。SVI是指为交换机中的VLAN创建虚拟接口,并且配置IP地址。
实验步骤
新建packet tracer拓扑图
(1)在二层交换机上配置VLAN2、VLAN3,分别将端口2、端口3划分给VLAN2、VLAN3。
(2)将二层交换机与三层交换机相连的端口fa 0/1都定义为tag Vlan模式。
(3)在三层交换机上配置VLAN2、VLAN3,此时验证二层交换机VLAN2、VLAN3下的主机之间不能相互通信。
(4)设置三层交换机VLAN间的通信,创建VLAN2,VLAN3的虚接口,并配置虚接口VLAN2、VLAN3的IP地址。
(5)查看三层交换机路由表。
(6)将二层交换机VLAN2、VLAN3下的主机默认网关分别设置为相应虚拟接口的IP地址。
(7)验证二层交换机VLAN2,VALN3下的主机之间可以相互通信。
首先在三层交换机上分别设置各VLAN的接口IP地址。三层交换机将vlan做为一种接口对待,就象路由器上的一样,再在各接入VLAN的计算机上设置与所属VLAN的网络地址一致的IP地址,并且把默认网关设置为该VLAN的接口地址。这样,所有的VLAN也可以互访了。
实验设备
Switch_2960 1台;Swithc_3560 1台;PC 3台;直连线如图1-1
图1-1
PC1配置
IP地址:? ? ? ? ?? 192.168.1.2
Submark(子网掩码): ?????? 255.255.255.0
Gateway(网关): ?????? 192.168.1.1
PC2配置
IP地址:??????????? 192.168.2.2
Submark(子网掩码): ?????? 255.255.255.0
Gateway(网关): ?????? 192.168.2.1???
PC3配置
IP地址:???????????????? 192.168.1.3
Submark(子网掩码): ?????? 255.255.255.0
Gateway(网关): ?????? 192.168.1.1
打开S2960敲入指令:
Switch>en? ? ? (进入特权模式)
Switch#conf t? ? ?(进入全局配置模式)
Switch(config )#vlan 2
Switch(config-vlan)#exit
Switch(config )#vlan 3
Switch(config-vlan)#exit??????
Switch(config )#int fa 0/2
Switch(config-if)#switchport access vlan 2
Switch(config-if)#exit
Switch(config )#int fa 0/3
Switch(config-if)#switchport access vlan 3
Switch(config-if)#exit
Switch(config )#int fa 0/1
Switch(config-if)#switchport? mode ?trunk
Switch(config-if)#end
Switch#show vlan
打开S3560敲入指令:
Switch>en? ? ? ? (进入特权模式)
Switch#conf t? ? ? (进入全局配置模式)
Switch(config )#vlan 2? (新建虚拟局域网vlan 2)
Switch(config-vlan)#exit? (返回上层配置模式)
Switch(config )#vlan 3? ? ? (新建vlan 3)
Switch(config-vlan)#exit? ?(返回上层配置模式)
Switch(config )#int fa 0/1? ?(进入交换机0模块第1端口)
Switch(config-if)#switchport trunk encapsulation dot1q? ? ? ? (给这个接口的trunk封装为802.1Q的帧格式)
Switch(config-if)#switchport mode trunk? (定义这个接口的工作模式为trunk)
Switch(config-if)#exit? ? ? ??(返回上层配置模式)
Switch(config )#int fa 0/2? ?(进入交换机0模块第2端口)
Switch(config-if)#switchport access vlan 2?? (将当前端口fa0/2划分到vlan 2中)
Switch(config-if)#exit? ? ? ???(返回上层配置模式)
Switch(config )#interface vlan 2? ? ? ??(进入vlan2 虚拟接口)
Switch(config-if)#ip address 192.168.1.1 255.255.255.0? (配置IP地址为192.168.1.1 子网掩码为255.255.255.0)
Switch(config-if)#no shutdown? ? ?? (开启该端口)
Switch(config-if)#exit? ? ? ? ? ??(返回上层配置模式)
Switch(config )#interface vlan 3? ? ???(进入vlan 3虚拟接口)
Switch(config-if)#ip address 192.168.2.1 255.255.255.0? ? ??(配置IP地址为192.168.2.1 子网掩码为255.255.255.0)
Switch(config-if)#no shutdown? ? ???(开启该端口)
Switch(config-if)#end? ? ? ? ? ? (退出)
Switch#show ip route? (显示路由表)
Switch#show vlan? ? ? ?(显示虚拟局域网vlan配置表)
实验最终目的????
要求PC1 Ping PC3(IP地址192.168.1.3)有回复
要求PC1 Ping PC2??(IP地址192.168.2.2)有回复? ?
编辑:黄飞
?
评论