实验时间正序目录
第五章 利用三层交换机实现VLAN间路由
实验背景
某企业有两个主要部门,技术部和销售部,分处于不同的办公室,为了安全和便于
管理对两个部门的主机进行了 VLAN 的划分,技术部和销售部分处于不同的
VLAN,先由于业务的需求需要销售部和技术部的主机能够相互访问,获得相应的
资源,两个部门的交换机通过一台三层交换机进行了连接。
技术原理
三层交换机具备网络层的功能,实现 VLAN 相互访问的原理是:利用三层交换机
的路由功能,通过识别数据包的 IP 地址,查找路由表进行选路转发,三层交换机
利用直连路由可以实现不同 VLAN 之间的相互访问。三层交换机给接口配置 IP 地
址。采用 SVI(交换虚拟接口)的方式实现 VLAN 间互连。SVI 是指为交换机中的
VLAN 创建虚拟接口,并且配置 IP 地址。
Packet Tracer拓扑图
IP配置
计算机0
IP: 192.168.1.2
子网掩码: AUTO
网关: 192.168.1.1
计算机1
IP: 192.168.2.2
子网掩码: AUTO
网关: 192.168.2.1
交换机配置
二层交换机
Switch>en %enable进入特权模式
Switch#conf t %config 进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 2 %划分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 %将端口加入vlan 2,默认所有端口都在vlan 1
Switch(config-if)#int fa 0/3
Switch(config-if)#switchport access vlan 3
Switch(config-if)#int fa 0/1
Switch(config-if)#switchport mode trunk %将端口配置成trunk模式(允许vlan通过)
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#show vlan %显示vlan端口配置
VLAN Name Status Ports
VLAN 名 状态 端口
---- -------------------------------- --------- -------------------------------
1 default active Fa0/4, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig0/1, Gig0/2
2 VLAN0002 active Fa0/2
3 VLAN0003 active Fa0/3
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
网络检测
计算机0 ping 计算机 1
验证二层交换机VLAN2,VLAN3下的主机之间不能相互通信
交换机配置
三层交换机
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 2
Switch(config-vlan)#exit
Switch(config)#vlan 3
Switch(config-vlan)#exit
Switch(config)#int fa 0/1
Switch(config-if)#switch trunk encapsulation dot1q %对fa 0/1端口进行802.1q协议封装
Switch(config-if)#switch mode trunk
Switch(config-if)#exit
Switch(config)#int fa 0/2
Switch(config-if)#switch access vlan 2
Switch(config-if)#exit
Switch(config)#ip routing %启动三层交换机的路由功能
Switch(config)#int vlan 2 %进入关联vlan号为2的路由端口设置
Switch(config-if)#ip add 192.168.1.1 255.255.255.0 %配置路由端口的IP和子网掩码
Switch(config-if)#no shutdown %启动路由端口
Switch(config-if)#exit
Switch(config)#int vlan 3
Switch(config-if)#ip add 192.168.2.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
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, Vlan2
C 192.168.2.0/24 is directly connected, Vlan3
Switch#show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/3, Fa0/4, Fa0/5, Fa0/6
Fa0/7, Fa0/8, Fa0/9, Fa0/10
Fa0/11, Fa0/12, Fa0/13, Fa0/14
Fa0/15, Fa0/16, Fa0/17, Fa0/18
Fa0/19, Fa0/20, Fa0/21, Fa0/22
Fa0/23, Fa0/24, Gig0/1, Gig0/2
2 VLAN0002 active Fa0/2
3 VLAN0003 active
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
2 enet 100002 1500 - - - - - 0 0
3 enet 100003 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
--More--
网络检测
计算机0 ping 计算机1
验证二层交换机VLAN2,VLAN3下的主机之间可以相互通信