Private VLAN 实验

实验拓扑


图 1-1

注:如无特别说明,描述中的 R1 或 SW1 对应拓扑中设备名称末尾数字为 1 的设备,R2 或 SW2 对应拓扑中设备名称末尾数字为 2 的设备,以此类推;另外,同一网段中,IP 地址的主机位为其设备编号,如 R3 的 g0/0 接口若在 192.168.1.0/24 网段,则其 IP 地址为 192.168.1.3/24,以此类推


实验需求

  1. 按照图示配置 IP 地址
  2. 在 SW1 上配置 Private VLAN,Primary VLAN 为 Vlan30,Secondary VLAN 为 Vlan10 和 Vlan20
  3. SW2 通过 Vlan100 下行连接 SW1,要求 PC3 和 PC4 都能以 Vlan100 访问 PC5

实验解法

  1. 配置 IP 地址部分略

  2. 在 SW1 上配置 Private VLAN,Primary VLAN 为 Vlan30,Secondary VLAN 为 Vlan10 和 Vlan20

      分析:根据需求,通过配置 Private VLAN 来使 Secondary VLAN 对上行设备不可见,实现 VLAN 复用的效果
      VLAN30 为 Prmary VLAN,Vlan10 和 Vlan20 为其 Secondary VLAN,把连接上行设备的接口 G1/0/3 口配置为上行接口,连接终端的 G1/0/1 和 G1/0/2 口配置为客户端接口

    步骤 1:在 SW1 上创建 Vlan10,Vlan20,Vlan30

    [SW1]vlan 10
    [SW1]vlan 20
    [SW1]vlan 30
    

    步骤 2:在 SW1 上配置 Vlan10 为 Prmary VLAN,Secondary VLAN 为 Vlan10 和 Vlan20

    [SW1-vlan30]private-vlan primary 
    [SW1-vlan30]private-vlan secondary 10 20
    

    步骤 3:在 SW1 上配置 G1/0/3 口为上行接口,G1/0/1 和 G1/0/2 口为下行接口,并把 G1/0/1 口加入 Vlan10,把 G1/0/2 口加入 Vlan20

    [SW1-GigabitEthernet1/0/3]port private-vlan 30 promiscuous
    [SW1-GigabitEthernet1/0/1]port access vlan 10
    [SW1-GigabitEthernet1/0/1]port private-vlan host 
    [SW1-GigabitEthernet1/0/2]port access vlan 20
    [SW1-GigabitEthernet1/0/2]port private-vlan host 
    
  3. SW2 通过 Vlan100 下行连接 SW1,要求 PC3 和 PC4 都能以 Vlan100 访问 PC5

      分析:根据 Private VLAN 原理,SW1 向 G1/0/3 接口发出的所有 Vlan 的数据帧都将剥离 tag 发出,SW2 收到的必定是未携带 tag 的数据帧,把 SW2 的 G1/0/2 和 G1/0/2 口都以 Access 类型加入 Vlan100,SW2 就会把收到的 SW1 转发过来的数据帧重新打上 Vlan 100 的 tag,从而实现 PC3 和 PC4 都能够以 Vlan100 访问 PC5
      
    步骤 1:在 SW2 上创建 Vlan100,并把 G1/0/1 和 G1/0/2 口以 Access 类型加入 Vlan100

    [SW2]vlan 100
    [SW2-vlan100]port g1/0/1
    [SW2-vlan100]port g1/0/2
    

    效果测试:PC3 和 PC4 都能够 Ping 通 PC5

    <PC3>ping 192.168.1.1
    Ping 192.168.1.1 (192.168.1.1): 56 data bytes, press CTRL_C to break
    56 bytes from 192.168.1.1: icmp_seq=0 ttl=255 time=166.000 ms
    56 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=58.000 ms
    56 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=53.000 ms
    56 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=67.000 ms
    56 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=56.000 ms
    
    
    <PC4>ping 192.168.1.1
    Ping 192.168.1.1 (192.168.1.1): 56 data bytes, press CTRL_C to break
    56 bytes from 192.168.1.1: icmp_seq=0 ttl=255 time=166.000 ms
    56 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=58.000 ms
    56 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=53.000 ms
    56 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=67.000 ms
    56 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=56.000 ms