VLAN基本配置
1. 创建vlan
2. 将交换机端口加入vlan
3. 验证vlan配置
实例:
配置4个PC的ip地址
SW1配置
Switch>enable
Switch#conf terminal
Switch(config)#hostname SW1
SW1(config)#vlan 2
SW1(config-vlan)#name test2 如果给vlan设置名字,那么两边交换机都要设置,否则不通
SW1(config-vlan)#exit
SW1(config)#vlan 3
SW1(config-vlan)#name test3
SW1(config-vlan)#exit
SW1(config)#interface f0/1 思科交换机只能从接口配置,将接口添加到vlan,华为交换机可以直接从机上配置接口vlan,不用再将接口加入vlan
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 2
SW1(config-if)#exit
SW1(config)#interface f0/3
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 3
SW1(config-if)#exit
SW1(config)#interface f0/2
SW1(config-if)#switchport mode trunk
SW1(config-if)#end
SW1#show vlan brief
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, Gig1/1, Gig1/2
2 VLAN0002 active Fa0/1
3 VLAN0003 active Fa0/3
F0/2不在默认vlan1中,说明trunk端口添加成功
SW1#show interfaces f0/2 switchport
Name: Fa0/2
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk
SW1(config)#interface range f0/3-10 同时将多个端口添加到vlan 3
SW1(config-if-range)#switchport mode access
SW1(config-if-range)#switchport access vlan 3
SW2配置
Switch>enable
Switch#conf terminal
Switch(config)#hostname SW2
SW2(config)#vlan 2
SW2(config-vlan)#name test2
SW2(config-vlan)#exit
SW2(config)#vlan 3
SW2(config-vlan)#name test3
SW2(config-vlan)#exit
SW2(config)#interface f0/2
SW2(config-if)#switchport mode access
SW2(config-if)#switchport access vlan 2
SW2(config-if)#exit
SW2(config)#interface f0/3
SW2(config-if)#switchport mode access
SW2(config-if)#switchport access vlan 3
SW2(config-if)#exit
SW2(config)#interface f0/1
SW2(config-if)#switchport mode trunk
SW2(config-if)#end
SW2#show vlan brief
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, Gig1/1, Gig1/2
2 VLAN0002 active Fa0/2
3 VLAN0003 active Fa0/3
F0/1不在默认vlan1中,说明trunk端口添加成功
SW2#show interfaces f0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk
测试:PC1 ping PC3 通
PC2 ping PC4 通
PC1 ping PC2 不通
结果:trunk可以承载多条vlan同时通信,trunk的作用是使同一个vlan能够跨越交换机通信。
Vlan工作在OSI参考模型的第二层(数据链路层),Vlan可以分割局域网络,相同vlan可以通信,不同vlan之间不能通信,阻止广播风暴。