私有VLAN(英文:Private VLAN),也称为专用VLAN
Private VLAN的主要功能就是能够实现节约IP地址,隔离广播风暴,病毒攻击,控制端口二层互访。特别适用于大二层结构的环境,用户多,vlan多,但是IP地址又是同一个网段,又要实现彼此之间二层隔离,个别VLAN之间又有互访的需求。常见的场景有宾馆酒店,小区宽带接入,运营商与高校共建的校园网等,他们的特点是一个房间或者一户人家一个vlan,彼此隔离,但是IP地址有限,无法给数量庞大的vlan每个分一个网段IP,只能共用一个IP地址段,比如vlan 10的IP地址段10.10.10.0/24,这样一户人家可能就使用了1-2个IP,造成剩余200多个ip地址浪费。
另一种比较典型的PVLAN应用类似于端口隔离功能,即将所有用户端口设置为隔离VLAN((Isolated Port),这样即使同一vlan,同一网段的IP之间的用户也无法访问,可以有效隔离病毒攻击。
功能简介:
服务提供商如果给每个用户一个VLAN,则由于一台设备支持的VLAN数最大只有4096而限制了服务提供商能支持的用户数;在三层设备上,每个VLAN被分配一个子网地址或一系列地址,这种情况导致IP地址的浪费;另外同一个vlan内的广播风暴,病毒攻击等安全问题让维护人员非常头疼,等等的这些问题的一种解决方法就是应用Private VLAN 技术。
组网需求
如图3所示:
· 汇聚层设备Device A为接入设备Device B分配了VLAN 10,网关接口VLAN-interface10可以和所有用户互通,以便用户可以通过Device A来访问外部网络。Device B连接的所有用户均处于同一网段10.0.0.0/24。
· Host A和B属于销售部,Host C和D属于财务部。为保证安全,需要使不同部门之间二层隔离,同部门的用户之间则可以互通。
现由于Device A不能为Device B分配更多VLAN,要求通过Private VLAN功能实现:
· Device A只需识别VLAN 10。
· Device B在Primary VLAN 10下为各部门配置不同的Secondary VLAN,使部门间二层隔离。
配置思路
Private VLAN功能只需要在接入设备Device B上配置。
配置注意事项
系统缺省VLAN(VLAN 1)不支持Private VLAN相关配置。
配置步骤
Device B的配置
# 配置VLAN 10为Primary VLAN。
<DeviceB> system-view
[DeviceB] vlan 10
[DeviceB-vlan10] private-vlan primary
[DeviceB-vlan10] quit
# 创建Secondary VLAN 201、202。
[DeviceB] vlan 201 to 202
# 建立Primary VLAN 10和Secondary VLAN 201、202的映射关系。
[DeviceB] vlan 10
[DeviceB-vlan10] private-vlan secondary 201 to 202
[DeviceB-vlan10] quit
# 配置上行端口GigabitEthernet1/0/1在VLAN 10中工作在promiscuous模式。
[DeviceB] interface gigabitethernet 1/0/1
[DeviceB-GigabitEthernet1/0/1] port private-vlan 10 promiscuous
[DeviceB-GigabitEthernet1/0/1] quit
# 将下行端口GigabitEthernet1/0/2、GigabitEthernet1/0/3添加到VLAN 201,GigabitEthernet1/0/4、GigabitEthernet1/0/5添加到VLAN 202,并配置它们工作在host模式。
[DeviceB] interface range gigabitethernet 1/0/2 to gigabitethernet 1/0/3
[DeviceB-if-range] port access vlan 201
[DeviceB-if-range] port private-vlan host
[DeviceB-if-range] quit
[DeviceB] interface range gigabitethernet 1/0/4 to gigabitethernet 1/0/5
[DeviceB-if-range] port access vlan 202
[DeviceB-if-range] port private-vlan host
[DeviceB-if-range] quit
Device A的配置
# 创建VLAN 10。将接口GigabitEthernet1/0/1加入VLAN 10。
<DeviceA> system-view
[DeviceA] vlan 10
[DeviceA] quit
[DeviceA] interface gigabitethernet 1/0/1
[DeviceA-GigabitEthernet1/0/1] port access vlan 10
[DeviceA-GigabitEthernet1/0/1] quit
# 配置网关接口VLAN-interface10。
[DeviceA] interface vlan-interface 10
[DeviceA-Vlan-interface10] ip address 10.0.0.1 24
[DeviceA-Vlan-interface10] quit
验证配置
# Device A可以ping通任意用户。查看ARP表,可以看到所有用户均属于VLAN 10。
[DeviceA] display arp
Type: S-Static D-Dynamic O-Openflow R-Rule M-Multiport I-Invalid
IP address MAC address VLAN/VSI Interface/Link ID Aging Type
10.0.0.2 d485-64a1-7e4a 10 GE1/0/1 19 D
10.0.0.3 7446-a0aa-7774 10 GE1/0/1 19 D
10.0.0.4 6805-ca05-39ae 10 GE1/0/1 20 D
10.0.0.5 6805-ca05-414e 10 GE1/0/1 20 D
# 显示Device B上的Private VLAN配置情况。
[DeviceB] display private-vlan
Primary VLAN ID: 10
Secondary VLAN ID: 201-202
VLAN ID: 10
VLAN type: Static
Private VLAN type: Primary
Route interface: Not configured
Description: VLAN 0010
Name: VLAN 0010
Tagged ports: None
Untagged ports:
GigabitEthernet1/0/1 GigabitEthernet1/0/2
GigabitEthernet1/0/3 GigabitEthernet1/0/4
GigabitEthernet1/0/5
VLAN ID: 201
VLAN type: Static
Private VLAN type: Secondary
Route interface: Not configured
Description: VLAN 0201
Name: VLAN 0201
Tagged ports: None
Untagged ports:
GigabitEthernet1/0/1 GigabitEthernet1/0/2
GigabitEthernet1/0/3
VLAN ID: 202
VLAN type: Static
Private VLAN type: Secondary
Route interface: Not configured
Description: VLAN 0202
Name: VLAN 0202
Tagged ports: None
Untagged ports:
GigabitEthernet1/0/1 GigabitEthernet1/0/4
GigabitEthernet1/0/5
可以看到,工作在promiscuous模式的端口GigabitEthernet1/0/1和工作在host模式的端口GigabitEthernet1/0/2~GigabitEthernet1/0/5均以Untagged方式允许VLAN报文通过。
# Host A、B之间可以互相ping通,Host C、D之间可以互相ping通。Host A、B与Host C、D之间均不能ping通。
配置文件
部分交换机的配置文件中会显示port link-mode bridge命令,请以实际情况为准。
· Device B
#
vlan 1
#
vlan 10
private-vlan primary
private-vlan secondary 201 to 202
#
vlan 201 to 202
#
interface GigabitEthernet1/0/1
port link-mode bridge
port link-type hybrid
undo port hybrid vlan 1
port hybrid vlan 10 201 to 202 untagged
port hybrid pvid vlan 10
port private-vlan 10 promiscuous
#
interface GigabitEthernet1/0/2
port link-mode bridge
port link-type hybrid
undo port hybrid vlan 1
port hybrid vlan 10 201 untagged
port hybrid pvid vlan 201
port private-vlan host
#
interface GigabitEthernet1/0/3
port link-mode bridge
port link-type hybrid
undo port hybrid vlan 1
port hybrid vlan 10 201 untagged
port hybrid pvid vlan 201
port private-vlan host
#
interface GigabitEthernet1/0/4
port link-mode bridge
port link-type hybrid
undo port hybrid vlan 1
port hybrid vlan 10 202 untagged
port hybrid pvid vlan 202
port private-vlan host
#
interface GigabitEthernet1/0/5
port link-mode bridge
port link-type hybrid
undo port hybrid vlan 1
port hybrid vlan 10 202 untagged
port hybrid pvid vlan 202
port private-vlan host
#
· Device A
#
vlan 1
#
vlan 10
#
interface Vlan-interface10
ip address 10.0.0.1 255.255.255.0
#
interface GigabitEthernet1/0/1
port link-mode bridge
port access vlan 10
#