华为vlan具体配置(电脑如何配vlan)

小编:大闷头 更新时间:2022-11-05

之前讨论的都是思科的,今天咱们具体讨论内容包含VLAN级联的静态配置; 通过GVRP协议实现的VLAN级联的动态配置;端口Hybrid特性配置;PVlan特性配置。

实验一:vlan静态配置:

华为vlan具体配置(电脑如何配vlan)

在完成VLAN的相关配置之后,要求能够达到同一VLAN内的PC可以互通,不同VLAN间的PC不能互通的目的。首先按照上图连接各实验设备,然后配置PCA IP地址为10.1.1.2/24,PCB IP地址为10.1.2.2/24,PCC IP地址为10.1.1.3/24,PCD IP地址为10.1.2.3/24。

1. 具体的配置如下:

(1) 配置交换机端口属于特定VLAN

[Quidway]sysname S3026A

[S3026A]vlan 2

[S3026A-vlan2]port Ethernet 0/9 to e0/16

[S3026A-vlan2]vlan 3

[S3026A-vlan3]port Ethernet 0/17 to e0/24

[Quidway]sysname S3026B

[S3026B]vlan 2

[S3026B-vlan2]port Ethernet 0/9 to e0/16

[S3026B-vlan2]vlan 3

[S3026B-vlan3]port Ethernet 0/17 to e0/24

当配置交换机端口属于特定VLAN时,有两种方法:一种是上面介绍的在VLAN配置模式下进行,另一种是在端口配置模式下进行,大家有兴趣可以试试看。

(2) 配置交换机之间的端口为Trunk端口,并且允许所有VLAN通过

[S3026A]int e0/1

[S3026A-Ethernet0/1]port link-type trunk //设置端口工作在trunk模式(系统默认为access模式)

[S3026A-Ethernet0/1]port trunk permit vlan all //允许所有VLAN通过Trunk端口

[S3026B]int e0/1

[S3026B-Ethernet0/1]port link-type trunk

[S3026B-Ethernet0/1]port trunk permit vlan all

配置完成后,可以看到,同一VLAN内部的PC可以互相访问,不同VLAN间的PC不能够互相访问。

在S3026A和S3026B之间增加交换机S3526C,同样实现上述实验目标:VLAN内互通,VLAN间隔离。组网图如下:

华为vlan具体配置(电脑如何配vlan)

继续上面的实验,这时候,我们需要修改三台交换机e0/1和e0/2接口的配置。

配置步骤如下:

(1) 配置三台交换机之间链路为trunk链路

[Quidway]sysname S3526C

[S3526C]int e0/1

[S3526C-Ethernet0/1]port link-type trunk

[S3526C-Ethernet0/1]port trunk permit vlan all

[S3526C-Ethernet0/1]int e0/2

[S3526C-Ethernet0/2]port link-type trunk

[S3526C-Ethernet0/2]port trunk permit vlan all

完成上述配置之后,我们可以测试一下VLAN内的主机之间是否可以ping通。结果是否定的,这是因为在交换机S3526C没有配置VLAN2和VLAN3,所以来自VLAN2和VLAN3的帧不能通过。必须在交换机上创建VLAN2和VLAN3,这样,这二个VLAN的帧才能够通过S3526C。

(2) 在S3526C上创建VLAN2和VLAN3

[S3526C]vlan 2

[S3526C-vlan2]vlan 3

如果S3026A和S3026B之间连接了多台交换机,是否需要在每一台交换机上都创建VLAN2和VLAN3?如果接入用户的交换机配置了许多VLAN,是否需要在每一台交换机上都创建这些VLAN?

答案是肯定的。如果VLAN众多,这样的静态VLAN配置工作会很复杂。通过GVRP协议,在交换机上动态的创建和注册VLAN,避免了手工配置之苦。

实验二:动态配置

华为vlan具体配置(电脑如何配vlan)

1. 具体的配置如下:

延续上面的实验配置。

(1) 删除S3526上的VLAN创建:

[S3526C]undo vlan 2

[S3526C]undo vlan 3

(2) 在三台交换机上配置VLAN动态注册协议——GVRP:

首先在系统配置模式下启用GVRP协议。

[S3526C]gvrp

GVRP is enabled globally

然后在每一个trunk端口启用GVRP协议。

[S3526C]int e0/1

[S3526C-Ethernet0/1]gvrp

GVRP is enabled on port Ethernet0/1

[S3526C-Ethernet0/1]int e0/2

[S3526C-Ethernet0/2]gvrp

GVRP is enabled on port Ethernet0/2

在S3026A和S3026B上进行相同的配置,即在系统模式下和端口模式下分别启用GVRP协议。然后我们可以用下面的命令来察看配置的GVRP信息和VLAN信息。我们可以看到,在S3526C上,GVRP已经启用,并且自动学习创建了VLAN2和VLAN3。

[S3526C]display gvrp statistics

GVRP statistics on port Ethernet0/1

GVRP Status : Enabled

GVRP Failed Registrations : 0

GVRP Last Pdu Origin : 00e0-fc07-7085

GVRP Registration Type : Normal

GVRP statistics on port Ethernet0/2

GVRP Status : Enabled

GVRP Failed Registrations : 0

GVRP Last Pdu Origin : 00e0-fc07-7089

GVRP Registration Type : Normal

[S3526C]display vlan

Now, the following VLAN exist(s):

1(default), 2-3

(3) 3. 接下来我们可以通过如下的方法来观察一下GVRP注册VLAN信息的过程:

首先在交换机S3026A上手动添加一个VLAN5

[S3026A]vlan 5

然后在三台交换机上分别查看VLAN信息如下:

[S3026B-Ethernet0/1]dis vlan

VLAN function is enabled.

Now, the following VLAN exist(s):

1(default), 2-3, 5

[S3026B-Ethernet0/1]dis vlan

VLAN function is enabled.

Now, the following VLAN exist(s):

1(default), 2-3, 5

[S3526C-Ethernet0/2]dis vlan

Now, the following VLAN exist(s):

1(default), 2-3, 5

现在我们可以看到在另外两台交换机上都已经动态添加了有关VLAN5的信息。

然后再看看有关的Trunk接口上又是怎么一回事:

dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc07-708f

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: trunk

VLAN passing : 1(default vlan), 2-3, 5

VLAN allowed : 1(default vlan), 2-4094

Trunk port encapsulation: IEEE 802.1q

1099 packets output

98522 bytes, 158 multicasts, 176 broadcasts, 0 pauses

998 packets input

81803 bytes, 166 multicasts, 71 broadcasts, 0 pauses

0 CRC errors

0 long frames

dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc07-707c

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: trunk

VLAN passing : 1(default vlan), 2-3, 5

VLAN allowed : 1(default vlan), 2-4094

Trunk port encapsulation: IEEE 802.1q

1092 packets output

91028 bytes, 109 multicasts, 86 broadcasts, 0 pauses

1264 packets input

104679 bytes, 253 multicasts, 106 broadcasts, 0 pauses

0 CRC errors

0 long frames

dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc06-2380

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

MTU: 1500, Maximum Frame Length: 25608752

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: trunk

VLAN passing : 1(default vlan), 2-3, 5

VLAN allowed : 1(default vlan), 2-4094

Trunk port encapsulation: IEEE 802.1q

Last 5 minutes output: 0 packets/sec, 0 bytes/sec

Last 5 minutes input: 0 packets/sec, 0 bytes/sec

input: 1314 packets, 116004 bytes

184 broadcasts, 192 multicasts

input: - input errors, 0 runts, 0 giants, 0 throttles, 0 CRC

1152 frame, - overruns, aborts, 0 ignored, - parity errors

Output: 1211 packets, 99117 bytes

80 broadcasts, 197 multicasts, 0 pauses

Output: - output errors, 0 underruns, - buffer failures

- aborts, 0 deferred, 0 collisions, 0 late collisions

- lost carrier, - no carrier

dis int e0/2

Ethernet0/2 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc06-2380

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

MTU: 1500, Maximum Frame Length: 25608752

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: trunk

VLAN passing : 1(default vlan), 2-3

VLAN allowed : 1(default vlan), 2-4094

Trunk port encapsulation: IEEE 802.1q

Last 5 minutes output: 0 packets/sec, 0 bytes/sec

Last 5 minutes input: 0 packets/sec, 0 bytes/sec

input: 1168 packets, 97347 bytes

89 broadcasts, 116 multicasts

input: - input errors, 0 runts, 0 giants, 0 throttles, 0 CRC

1081 frame, - overruns, aborts, 0 ignored, - parity errors

Output: 1354 packets, 112066 bytes

109 broadcasts, 274 multicasts, 0 pauses

Output: - output errors, 0 underruns, - buffer failures

- aborts, 0 deferred, 0 collisions, 0 late collisions

- lost carrier, - no carrier

现在我们发现在S3026A的Trunk接口e0/1上已经允许VLAN5通过,同样S3026B和S3526C的e0/1接口上也已经VLAN5,但是S3526C的e0/2接口上却只允许VLAN1,2,3通过,VLAN5不能通过,这是为什么呢?

实际上这也是GVRP进行VLAN注册的一条规则,由于交换机S3026B上没有手工配置VLAN5,也就是说S3026B上没有VLAN5的成员,所以S3026B和S3526C之间的Trunk链路就不应该让VLAN5的帧通过。下面我们可以通过在S3026B上配置VLAN5来进行验证:

[S3026B]vlan 5

[S3026B-vlan5]port e0/3

Dynamic VLAN is configured, now changed to static!

由于交换机S3026B上已经动态注册了VLAN5,所以需要通过添加端口来将VLAN改变为静态VLAN。

dis int e0/2

Ethernet0/2 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc06-2380

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

MTU: 1500, Maximum Frame Length: 25608752

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: trunk

VLAN passing : 1(default vlan), 2-3, 5

VLAN allowed : 1(default vlan), 2-4094

Trunk port encapsulation: IEEE 802.1q

Last 5 minutes output: 0 packets/sec, 0 bytes/sec

Last 5 minutes input: 0 packets/sec, 0 bytes/sec

input: 4065 packets, 337496 bytes

253 broadcasts, 370 multicasts

input: - input errors, 0 runts, 0 giants, 0 throttles, 0 CRC

3765 frame, - overruns, aborts, 0 ignored, - parity errors

Output: 4606 packets, 373337 bytes

240 broadcasts, 903 multicasts, 0 pauses

Output: - output errors, 0 underruns, - buffer failures

- aborts, 0 deferred, 0 collisions, 0 late collisions

- lost carrier, - no carrier

在S3026B上已经有了VLAN5的成员之后,S3526C的e0/2接口开始允许VLAN5通过。

(4) 在交换机的Trunk端口上,VLAN的GVRP注册有三种方法:normal、fixed和forbidden。其中normal是默认的注册方法,表示允许在该端口手工或动态创建、注册和注销VLAN。下面我们分别来看看其他两种方法:

首先在S3026A上进行如下配置:

[S3026A-Ethernet0/1]gvrp registration fixed

fixed表示允许在该端口手工创建和注册VLAN,不允许动态注册或注销VLAN。也就是说S3026A的端口Ethernet0/1不会接受从对端来的动态VLAN信息。

下面在S3026B上添加一个新的VLAN,配置如下:

[S3026B]vlan 7

[S3026B-vlan7]dis vlan

VLAN function is enabled.

Now, the following VLAN exist(s):

1(default), 2-3, 5, 7

在另外两台交换机上查看VLAN如下:

dis vlan

Now, the following VLAN exist(s):

1(default), 2-3, 5, 7

dis vlan

VLAN function is enabled.

Now, the following VLAN exist(s):

1(default), 2-3, 5

dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc07-708f

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: trunk

VLAN passing : 1(default vlan), 2-3, 5

VLAN allowed : 1(default vlan), 2-4094

Trunk port encapsulation: IEEE 802.1q

647 packets output

52285 bytes, 97 multicasts, 27 broadcasts, 0 pauses

809 packets input

66183 bytes, 228 multicasts, 54 broadcasts, 0 pauses

0 CRC errors

0 long frames

可以看到S3026A上没有注册VLAN7。

下面我们再来看看如何应用forbidden:

在S3026A上进行如下配置:

[S3026A-Ethernet0/1]gvrp registration forbidden

forbidden表示在端口将注销除VLAN1之外的所有其它VLAN,并且禁止在该端口创建和注册任何其它VLAN。

然后我们可以在查看一下S3026A的端口e0/1:

[S3026A-Ethernet0/1]dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc07-708f

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: trunk

VLAN passing : 1(default vlan)

VLAN allowed : 1(default vlan), 2-4094

Trunk port encapsulation: IEEE 802.1q

929 packets output

74705 bytes, 143 multicasts, 35 broadcasts, 0 pauses

1173 packets input

94456 bytes, 348 multicasts, 70 broadcasts, 0 pauses

0 CRC errors

0 long frames

现在只有VLAN1可以通过端口e0/1。

(5) 配置交换机端口属于特定VLAN

[Quidway]sysname S3026A

[S3026A]vlan 2

[S3026A-vlan2]port Ethernet 0/9 to e0/16

[S3026A-vlan2]vlan 3

[S3026A-vlan3]port Ethernet 0/17 to e0/24

实验三:Hybrid端口配置

华为vlan具体配置(电脑如何配vlan)

配置交换机之间的端口为Hybrid端口,并且允许VLAN2和VLAN3的帧通过Hybrid端口,并且VLAN2的帧在Hybrid端口打上VLAN2的tag,VLAN3的帧不打tag。

1. 具体的配置如下:

(1) 由于当交换机上有Trunk端口存在时不能配置Hybrid,所以我们需要先把Trunk端口改成Access端口。命令如下:

[S3026A-Ethernet0/1]port link-type access

在S3026B和S3526C上也作同样的配置。同时也要在S3526C上配置VLAN2和VLAN3,因为Trunk取消之后,GVRP也随之取消了。

(2) 配置交换机之间的端口为Hybrid端口(注意,连接PC的端口不能配为Hybrid端口):

[S3026A-Ethernet0/1]port link-type hybrid

在S3026B的e0/1端口和S3526C的e0/1、e0/2端口上也作同样的配置

下面查看S3026A的端口信息如下:

[S3026A-Ethernet0/1]dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc07-708f

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: hybrid

Tagged VLAN ID : none

Untagged VLAN ID : 1

1292 packets output

101041 bytes, 423 multicasts, 118 broadcasts, 0 pauses

2027 packets input

152720 bytes, 1119 multicasts, 153 broadcasts, 0 pauses

0 CRC errors

0 long frames

从上面的信息可以看出PVID为1,Tagged VLAN ID没有配置,而Untagged VLAN ID默认为1。

2. 配置VLAN2打tag,VLAN3不打tag。

[S3026A-Ethernet0/1]port hybrid vlan 2 tagged

[S3026A-Ethernet0/1]port hybrid vlan 3 untagged

在交换机S3026B的端口e0/1和S3526C的端口e0/1、e0/2上进行相同的配置。

下面查看S3026A的端口信息如下:

[S3026A-Ethernet0/1]dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc07-708f

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 1

Mdi type: auto

Port link-type: hybrid

Tagged VLAN ID : 2

Untagged VLAN ID : 1, 3

1539 packets output

122085 bytes, 480 multicasts, 266 broadcasts, 0 pauses

2243 packets input

172338 bytes, 1178 multicasts, 270 broadcasts, 0 pauses

0 CRC errors

0 long frames

从上面的信息可以看出PVID为1,Tagged VLAN ID为2,而Untagged VLAN ID为1和3。

然后我们可以分别查看VLAN2和VLAN3的信息如下:

dis vlan 2

VLAN ID: 2

VLAN Type: static

Route Interface: not configured

Description: VLAN 0002

Tagged Ports:

Ethernet0/1

Untagged Ports:

Ethernet0/9 Ethernet0/10 Ethernet0/11

Ethernet0/12 Ethernet0/13 Ethernet0/14

Ethernet0/15 Ethernet0/16

dis vlan 3

VLAN ID: 3

VLAN Type: static

Route Interface: not configured

Description: VLAN 0003

Tagged Ports: none

Untagged Ports:

Ethernet0/1 Ethernet0/17 Ethernet0/18

Ethernet0/19 Ethernet0/20 Ethernet0/21

Ethernet0/22 Ethernet0/23 Ethernet0/24

在VLAN2中,已经有一个tagged port:e0/1。

实际上对于一个以太网帧来说,从主机到交换机接入端口这一段是没有VLAN tag的,这是因为一般的计算机并不能识别VLAN tag的。而当以太网帧在通过Hybrid端口发往另一台交换机之前,就已经打上了相应的VLAN tag以作区别。对于来自不同VLAN的帧,Hybrid端口会根据配置作不同的处理。

以上面的配置为例,当一个从VLAN2来的帧从S3026A的Hybrid端口e0/1发往对端S3526C的e0/1时,S3026A的e0/1端口不会对它作任何处理,而当这个帧到达对端时,(对端也是一样的配置)S3526C的e0/1端口会检查它的VLAN tag,发现VLAN2是Tagged VLAN ID,于是S3526C的e0/1端口不会改变以太网帧的tag,并向相应正确的端口进行转发。

当一个从VLAN3来的帧从S3026A的Hybrid端口e0/1发往对端S3526C的e0/1时,则会被去掉VLAN3的tag。当这个帧到达对端时,(对端也是一样的配置)S3526C的e0/1端口会检查它的VLAN tag,发现是没有VLAN tag的,则认为该帧属于VLAN 1(PVID为1),不会向VLAN 3的端口转发。

这样配置完成后,VLAN2内的PC可以互相ping通,VLAN3内部的PC不能够互相ping通。

如果我们设置Hybrid端口的PVID为3,这样,没有VLAN tag的帧将被认为属于VLAN 3,VLAN3内的主机可以通信。

[S3026A-Ethernet0/1]port hybrid pvid vlan 3

在交换机S3026B的端口e0/1和S3526C的端口e0/1、e0/2上进行相同的配置。

dis int e0/1

Ethernet0/1 is up

Hardware is Fast Ethernet, Hardware address is 00e0-fc07-708f

Auto-duplex(Full), Auto-speed(100M), 100_BASE_TX

Flow control: disabled

Broadcast MAX-ratio: 100%

PVID: 3

Mdi type: auto

Port link-type: hybrid

Tagged VLAN ID : 2

Untagged VLAN ID : 1, 3

4962 packets output

395464 bytes, 523 multicasts, 959 broadcasts, 0 pauses

5105 packets input

410851 bytes, 1222 multicasts, 405 broadcasts, 0 pauses

0 CRC errors

0 long frames

小结:

Hybrid端口是介于Access端口和Trunk端口之间的一种端口属性,通过Hybrid端口的设置,可以配置部分VLAN的帧可以打上VLAN标记,另一部分VLAN在通过交换机间链路时,不打VLAN标记,从而实现对部分VLAN隔离的目的。当然,如果您对所有VLAN在Hybrid端口都配置为Untagged,那么交换机之间的所有VLAN都被隔离,满足一些特殊应用。

实验四:PVLAN配置

华为vlan具体配置(电脑如何配vlan)

从VLAN的帧格式我们知道VLAN ID域占用12个bit位,所以可以表示的VLAN范围为:0-4095(实际上用户可用的为1-4094)。这样的一个范围对于任何一个企业局域网或者是校园网都可以说已经足够,但是运营商在小区宽带接入的快速发展中,形成了不计其数的用户,而这些用户又不希望受到其它用户的直接访问和攻击。这时候我们如果为每个用户都分配一个VLAN ID来隔离他们,就显得VLAN ID不够用。利用PVLAN,即双层VLAN技术就可以很好的解决这一问题。

在PVLAN中,一台交换机上存在Primary vlan和Secondary vlan。一个Primary vlan和多个Secondary vlan对应,Primary vlan包含所对应的所有Secondary vlaN中包含的端口和上行端口,这样对上层交换机来说,只须识别下层交换机中的Primary vlan,而不必关心Primary vlan中包含的Secondary vlaN,简化了配置,节省了VLAN资源。用户可以采用PVLAN实现二层报文的隔离,为每个用户分配一个Secondary VLAN,每个vlan中只包含该用户连接的端口和上行端口;如果希望实现用户之间二层报文的互通,也可以将用户连接的端口划入同一个Secondary VLAN中。

如上图所示,S3026A划分了4个VLAN,其中VLAN5为Primary VLAN,VLAN2,3,4为Secondary VLAN。S3026B划分了3个VLAN,VLAN4为Primary VLAN,VLAN2,3为Secondary VLAN。其中Primary VLAN包括e0/1,e0/2,e0/3,e0/4口。完成上面配置后,您会发现,在同一交换机内的不同Secondary VLAN的主机不能够互相访问,所有Secondary VLAN的主机都能够访问Primary VLAN的主机;交换机之间的所有PC都能够互相访问。

1. 具体的配置如下:

(1) 在2台交换机上创建VLAN,并为VLAN分配接口(注意,必须为每一个VLAN划分端口):

[S3026A]vlan 5

[S3026A-vlan5]port Ethernet 0/1 to Ethernet 0/4

[S3026A-vlan5]vlan 2

[S3026A-vlan2]port Ethernet 0/5 to Ethernet 0/8

[S3026A-vlan2]vlan 3

[S3026A-vlan3]port Ethernet 0/9 to Ethernet 0/11

[S3026A-vlan3]vlan 4

[S3026A-vlan4]port Ethernet 0/12 to Ethernet 0/16

[S3026B]vlan 4

[S3026B-vlan4]port Ethernet 0/1 to Ethernet 0/4

[S3026B-vlan4]vlan 2

[S3026B-vlan2]port Ethernet 0/9 to Ethernet 0/16

[S3026B-vlan2]vlan 3

[S3026B-vlan3]port Ethernet 0/17 to Ethernet 0/24

(2) 配置S3026A的VLAN5为Primary VLAN,VLAN2,3,4为Secondary VLAN,建立Primary VLAN和Secondary VLAN的映射关系;配置S3026B的VLAN4为Primary VLAN,VLAN2,3为Secondary VLAN,建立Primary VLAN和Secondary VLAN的映射关系。

[S3026A]vlan 5

[S3026A-vlan5]isolate-user-vlan enable //设置VLAN类型为Primary VLAN

[S3026A-vlan5]quit

[S3026A]isolate-user-vlan 5 secondary 2 3 4 //配置Primary VLAN和Secondary VLAN间的映射关系

[S3026B]vlan 4

[S3026B-vlan4]isolate-user-vlan enable

[S3026B-vlan4]quit

[S3026B]isolate-user-vlan 4 secondary 2 3

完成上述配置之后,我们可以查看S3026A上的配置信息如下:

[S3026A]dis current-configuration

#

sysname S3026A

#

radius scheme default

#

aaa authentication-scheme Default radius next local

aaa accounting-scheme Default enable offline

#

interface Aux0/0

#

vlan 1

#

vlan 2

#

vlan 3

#

vlan 4

#

vlan 5

isolate-user-vlan enable

#

interface Ethernet0/1

port link-type hybrid

port hybrid vlan 2 to 5 untagged

port hybrid pvid vlan 5

#

interface Ethernet0/2

port link-type hybrid

port hybrid vlan 2 to 5 untagged

port hybrid pvid vlan 5

#

interface Ethernet0/3

port link-type hybrid

port hybrid vlan 2 to 5 untagged

port hybrid pvid vlan 5

#

interface Ethernet0/4

port link-type hybrid

port hybrid vlan 2 to 5 untagged

port hybrid pvid vlan 5

#

interface Ethernet0/5

port link-type hybrid

port hybrid vlan 2 5 untagged

port hybrid pvid vlan 2

#

interface Ethernet0/6

port link-type hybrid

port hybrid vlan 2 5 untagged

port hybrid pvid vlan 2

#

interface Ethernet0/7

port link-type hybrid

port hybrid vlan 2 5 untagged

port hybrid pvid vlan 2

#

interface Ethernet0/8

port link-type hybrid

port hybrid vlan 2 5 untagged

port hybrid pvid vlan 2

#

interface Ethernet0/9

port link-type hybrid

port hybrid vlan 3 5 untagged

port hybrid pvid vlan 3

#

interface Ethernet0/10

port link-type hybrid

port hybrid vlan 3 5 untagged

port hybrid pvid vlan 3

#

interface Ethernet0/11

port link-type hybrid

port hybrid vlan 3 5 untagged

port hybrid pvid vlan 3

#

interface Ethernet0/12

port link-type hybrid

port hybrid vlan 4 to 5 untagged

port hybrid pvid vlan 4

#

interface Ethernet0/13

port link-type hybrid

port hybrid vlan 4 to 5 untagged

port hybrid pvid vlan 4

#

interface Ethernet0/14

port link-type hybrid

port hybrid vlan 4 to 5 untagged

port hybrid pvid vlan 4

#

interface Ethernet0/15

port link-type hybrid

port hybrid vlan 4 to 5 untagged

port hybrid pvid vlan 4

#

interface Ethernet0/16

port link-type hybrid

port hybrid vlan 4 to 5 untagged

port hybrid pvid vlan 4

#

interface Ethernet0/17

#

interface Ethernet0/18

#

interface Ethernet0/19

#

interface Ethernet0/20

#

interface Ethernet0/21

#

interface Ethernet0/22

#

interface Ethernet0/23

#

interface Ethernet0/24

#

interface NULL0

#

cluster

#

isolate-user-vlan 5 secondary 2 to 4

#

user-interface aux 0

user-interface vty 0 4

#

从上面的信息中可以看出,PVLAN实际上是通过前一个实验中的hybrid端口来实现。即通过配置一系列的hybrid端口,并对来自不同VLAN的帧进行不同的VLAN tag处理,来达到隔离VLAN的目的。

配置完成后,在同一交换机内的不同Secondary VLAN的主机不能够互相访问,所有Secondary VLAN的主机都能够访问Primary VLAN的主机;交换机之间的所有PC都能够互相访问。在交换机S3026A上使用display vlan 5命令可以看到,同一交换机的所有VLAN的所有端口都属于VLAN5,也就是说VLAN2,3和4是VLAN5的更细化的VLAN。

[S3026A]display vlan 5

VLAN ID: 5

VLAN Type: static

Isolate-user-VLAN type : isolate-user-VLAN

Route Interface: not configured

Description: VLAN 0005

Tagged Ports: none

Untagged Ports:

Ethernet0/1 Ethernet0/2 Ethernet0/3

Ethernet0/4 Ethernet0/5 Ethernet0/6

Ethernet0/7 Ethernet0/8 Ethernet0/9

Ethernet0/10 Ethernet0/11 Ethernet0/12

Ethernet0/13 Ethernet0/14 Ethernet0/15

Ethernet0/16

接下来我们可以用如下的方法来测试不同VLAN间主机的连通性:

1. 准备两台PC机PCA和PCB,然后配置PCA IP地址为10.1.1.2/24,PCB IP地址为10.1.1.3/24。

2. 将PCA连接到交换机S3026A的端口e0/5上,将PCB分别连接到交换机S3026A的端口e0/9和e0/12上,从PCA ping PCB,看是否能够ping通。

3. 将PCB连接到交换机S3026A的端口e0/2上,从PCA ping PCB,看是否能够ping通。

4. 将PCB连接到交换机S3026B的任一端口上,从PCA ping PCB,看是否能够ping通。

在测试连通性的过程中,大家可以参考前一个实验中对hybrid端口的解释,并对照前面的配置信息,来思考一下,为什么会ping得通或者ping不通?

实际上从配置信息中可以看出在S3026A中划分给VLAN5的hybrid端口PVID都为5,同理划分给VLAN2,3,4的hybrid端口PVID分别为相应的VLAN ID,这就造成了在同一交换机内的不同Secondary VLAN的主机不能够互相访问。而VLAN5作为Primary VLAN,实际上包含了所有的端口,所以所有Secondary VLAN的主机都能够访问Primary VLAN的主机。在交换机之间,由于通过e0/1相连,而e0/1又划分在各自的Primary VLAN,PVID为各自的Primary VLAN ID,因此通过e0/1的帧会加上对方的Primary VLAN ID,可以访问对方所有的端口。