交换机SW1的e0/0-1端口属于VLAN20范围,e0/2-3端口属于VLAN30范围,e1/0端口属于VLAN10范围。
VLAN10 为 Primary VLAN,VLAN20 为 Community VLAN,VLAN30 为 Isolated VLAN。端口e1/0为混杂端口,与VLAN20 和 VLAN30 关联。
通过配置 Private-VLAN,使得PC1能够与PC2通信,PC3不能与PC4通信,PC1与PC2不能与PC3和PC4通信。
SW1#conf t
SW1(config)#vtp mode transparent //需要先开启透明模式
SW1(config)#vlan 10
SW1(config-vlan)#private-vlan primary //主VLAN
SW1(config-vlan)#exit
SW1(config)#vlan 20
SW1(config-vlan)#private-vlan community //团体VLAN
SW1(config-vlan)#exit
SW1(config)#vlan 30
SW1(config-vlan)#private-vlan isolated //隔离VLAN
SW1(config-vlan)#exit
SW1(config)#end
查看PVLAN信息:
SW1#show vlan private-vlan
Primary Secondary Type Ports
---
10 none primary
none 20 community
none 30 isolated
将VLAN20、VLAN30与VLAN10关联起来:
SW1#conf t
SW1(config)#vlan 10
SW1(config-vlan)#private-vlan association 20,30
SW1(config-vlan)#end
查看PVLAN信息:
SW1#show vlan private-vlan
Primary Secondary Type Ports
---
10 20 community
10 30 isolated
添加主机端口,并将VLAN20、VLAN30添加到主机端口:
SW1#conf t
SW1(config)#inter range e0/0-1
SW1(config-if-range)#sw mode private-vlan host
SW1(config-if-range)#sw private-vlan host-association 10 20
SW1(config-if-range)#exit
SW1(config)#inter range e0/2-3
SW1(config-if-range)#sw mode private-vlan host
SW1(config-if-range)#sw private-vlan host-association 10 30
SW1(config-if-range)#exit
设置混杂端口:
SW1(config)#inter e1/0
SW1(config-if)#sw mode private-vlan promiscuous
SW1(config-if)#end
查看PVLAN信息:
SW1#show vlan private-vlan
Primary Secondary Type Ports
---
10 20 community Et0/0, Et0/1
10 30 isolated Et0/2, Et0/3
将VLAN20、VLAN30映射到VLAN10中:
SW1#conf t
SW1(config)#inter e1/0
SW1(config-if)#sw private-vlan mapping 10 add 20,30
SW1(config-if)#end
再查看PVLAN信息:
SW1#show vlan private-vlan
Primary Secondary Type Ports
---
10 20 community Et0/0, Et0/1, Et1/0
10 30 isolated Et0/2, Et0/3, Et1/0
给路由器R1的F0/0端口添加IP:192.34.1.100/24,该端口IP将作为PC的网关。分别给PC1-4配上IP地址和网关。
PC1> ping 192.34.1.2
84 bytes from 192.34.1.2 icmp_seq=1 ttl=64 time=0.282 ms
84 bytes from 192.34.1.2 icmp_seq=2 ttl=64 time=0.192 ms
84 bytes from 192.34.1.2 icmp_seq=3 ttl=64 time=0.220 ms
84 bytes from 192.34.1.2 icmp_seq=4 ttl=64 time=0.269 ms
84 bytes from 192.34.1.2 icmp_seq=5 ttl=64 time=0.233 ms
PC1> ping 192.34.1.3
host (192.34.1.3) not reachable
PC1> ping 192.34.1.4
host (192.34.1.4) not reachable
PC1>
PC3> ping 192.34.1.4
host (192.34.1.4) not reachable
PC3> ping 192.34.1.1
host (192.34.1.1) not reachable
PC3>
以上ping结果表明,团体VLAN间可以互相通信,隔离VLAN间无法互相通信,团体VLAN与隔离VLAN间也无法通信。