VLAN是交换机端口的逻辑组合,VLAN工作在OSI的第二层,一个VLAN就是一个广播域,VLAN之间的通信是通过是通过第三层的路由器来完成。
VLAN的有点:
1、控制网络广播的问题;每一个VLAN都是一个广播域,一个VLAN上的广播不会扩散到其他VLAN;
2、简化网络的管理;当VLAN中的用户位置移动时,网络管理员只需设置几条命令即可;
- Switch#conf t
- Enter configuration commands, one per line. End with CNTL/Z.
- Switch(config)#vlan 2 //创建ID为2的VLAN
- Switch(config-vlan)#name vlan2 //名字为VLAN2
- Switch(config-vlan)#exit
- Switch(config)#vlan 3 //创建ID为3的VLAN
- Switch(config-vlan)#name vlan3 //名字为VLAN3
- Switch(config)#interface f0/1 //进入f0/1端口
- Switch(config-if)#switch mode access //将f0/1端口设为access模式
- Switch(config-if)#switch access vlan 2 //将f0/1端口划分到vlan 2中
- Switch(config)#interface range f0/2-3
- Switch(config-if-range)#switch mode access
- Switch(config-if-range)#switch access vlan 2
- Switch(config-if-range)#exit
- Switch(config)#exit
- Switch#
- %SYS-5-CONFIG_I: Configured from console by console
- Switch#sh vlan
- VLAN Name Status Ports
- ---- -------------------------------- --------- -------------------------------
- 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
- 2 vlan2 active Fa0/1, Fa0/2, Fa0/3
- Switch#no vlan 2 //在全局配置模式下才可以
- ^
- % Invalid input detected at '^' marker.
- Switch#conf t
- Enter configuration commands, one per line. End with CNTL/Z.
- Switch(config)#no vlan 2
- Switch(config)#sh vlan //sh一般都是在特权模式下
- ^
- % Invalid input detected at '^' marker.
- Switch(config)#exit
- Switch#
- %SYS-5-CONFIG_I: Configured from console by console
- sh
- Switch#show vlan
- VLAN Name Status Ports
- ---- -------------------------------- --------- -------------------------------
- 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
- 3 vlan3 active //只剩VLAN 3了