交换机具有自我协商功能

可以实现工作工作方式,端口速率的协商==向小兼容

报文的学习=动态mac地址表=300s=老化时间=5分钟,

ARP表=20分钟,

ip与mac的对应关系,

作用用于通信设备进行数据封装的

存在任何需要封装的设备,

MAC 地址表=5分钟,

mac 地址和端口的对应关系,用于交换机中转发数据的

广播域,广播报文传递范围,默认交换机所有接口都处于一个广播域,,

vlan 虚拟局域网,理解成一个虚拟的交换机,

vlan 范围0-4095 可以用的是1-4094

接收方向

配置VLAN

1、终端接口配置vlan用access接口类型

vlan 10 创建Vlan10

vlan batch 10 20 30 连续创建VLAN10 20 30

int g0/0/1  进入接口1

port link-type access  更改接口类型   标签即vlan号,

port default vlan 10 将接口10加入Vlan10

access接口主要应用于交换机和其他终端之间,作用是打标签和剥离标签

2、交换机之间配置vlan用trunk接口类型

int g0/0/3  进入接口

port link-type trunk 更改接口类型

port trunk allow-pass vlan 10 20(all)允许交换机之间相同vlan通讯或者全部vlan通讯

undo port trunk vlan1 关闭vlan1通讯

Trunk接口主要应用于交换机之间,用于vlan之间带标签通信

3、Hybrid的tagger接口状态用于交换机与交换机之间的带标签通讯,untagger接口状态用于交换机和终端设备间的无标签通讯

vlan batch vlan 2 3 100 全局创建Vlan

进入交换机互联接口

int g0/0/1

port link-type hybrid 定义接口类型

port hrbrid tagged vlan 2 3 100允许接口通过带着vlan 2 3 100标签的数据

进入终端互联接口

int g0/0/2

port link-type hybrid 定义接口类型

port hybrid pvid vlan 2 更改接口的PVID

port hybrid untagged vlan 2 100 允许接口通过剥离标签的vlan类型

进入接口3

int g0/0/3

port hybrid pvid 3更改接口的pvid

port hrbrid untagged vlan 3 100 允许通过剥离vlan3 100标签的vlan类型

untag不要理解为剥离标签的动作,而是理解为此接口允许无标签的数据通过,是一种数据状态。过来的数据无标签直接放行,有标签就剥离标签放行

交换机方向过来有标签的,接口剥离标签才能跟下一跳的终端通信;终端方向过来无标签的,接口给打上标签,才能与下一跳的交换设备通信

====================================================================

做一个小实验

创建vlan 和之前创建ospf 相似 都要提前创建

<Huawei>sy 
Enter system view, return user view with Ctrl+Z.
[Huawei]sy SW1
[SW1]
Jul 29 2025 16:29:18-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 4, the c
hange loop count is 0, and the maximum number of records is 4095.
[SW1]dis vlan   未创建vlan 时的vlan   默认vlan 1  所有接口都在这vlan 
The total number of vlans is : 1  
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:GE0/0/1(U)      GE0/0/2(U)      GE0/0/3(U)      GE0/0/4(D)      
                GE0/0/5(D)      GE0/0/6(D)      GE0/0/7(D)      GE0/0/8(D)      
                GE0/0/9(D)      GE0/0/10(D)     GE0/0/11(D)     GE0/0/12(D)     
                GE0/0/13(D)     GE0/0/14(D)     GE0/0/15(D)     GE0/0/16(D)     
                GE0/0/17(D)     GE0/0/18(D)     GE0/0/19(D)     GE0/0/20(D)     
                GE0/0/21(D)     GE0/0/22(D)     GE0/0/23(D)     GE0/0/24(D)     


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------
1    enable  default       enable  disable    VLAN 0001                         
[SW1]vlan 10 
[SW1-vlan10]q
[SW1]vlan 20   创建vlan  q是退出,
Jul 29 2025 16:30:28-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 5, the c
hange loop count is 0, and the maximum number of records is 4095.
[SW1-vlan20]q
[SW1]dis vlan
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:GE0/0/1(U)      GE0/0/2(U)      GE0/0/3(U)      GE0/0/4(D)      
                GE0/0/5(D)      GE0/0/6(D)      GE0/0/7(D)      GE0/0/8(D)      
                GE0/0/9(D)      GE0/0/10(D)     GE0/0/11(D)     GE0/0/12(D)     
                GE0/0/13(D)     GE0/0/14(D)     GE0/0/15(D)     GE0/0/16(D)     
                GE0/0/17(D)     GE0/0/18(D)     GE0/0/19(D)     GE0/0/20(D)     
                GE0/0/21(D)     GE0/0/22(D)     GE0/0/23(D)     GE0/0/24(D)     

10   common  
20   common  
Jul 29 2025 16:30:38-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 6, the c
hange loop count is 0, and the maximum number of records is 4095.

VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------
1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020 

现在进入接口

[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]po	
[SW1-GigabitEthernet0/0/1]port l	
[SW1-GigabitEthernet0/0/1]port link-ty	
[SW1-GigabitEthernet0/0/1]port link-type ? 这里是其他接口类型, hybrid默认是这个类型
  access        Access port
  dot1q-tunnel  QinQ port
  hybrid        Hybrid port
  trunk         Trunk port

[SW1-GigabitEthernet0/0/1]port link-type ac	
[SW1-GigabitEthernet0/0/1]port link-type access 
[SW1-GigabitEthernet0/0/1]dis	
[SW1-GigabitEthernet0/0/1]display th  查看配置,
#
interface GigabitEthernet0/0/1
 port link-type access  有下面这个代表是之前有人配置过,
#
return

接下来在access下添加进vlan

SW1-GigabitEthernet0/0/1]po	
[SW1-GigabitEthernet0/0/1]port de	
[SW1-GigabitEthernet0/0/1]port default v	
[SW1-GigabitEthernet0/0/1]port default vlan 10
[SW1-GigabitEthernet0/0/1]q

然后我们查看一下,

[SW1]dis vlan
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:GE0/0/2(U)      GE0/0/3(U)      GE0/0/4(D)      GE0/0/5(D)      
                GE0/0/6(D)      GE0/0/7(D)      GE0/0/8(D)      GE0/0/9(D)      
                GE0/0/10(D)     GE0/0/11(D)     GE0/0/12(D)     GE0/0/13(D)     
                GE0/0/14(D)     GE0/0/15(D)     GE0/0/16(D)     GE0/0/17(D)     
                GE0/0/18(D)     GE0/0/19(D)     GE0/0/20(D)     GE0/0/21(D)     
                GE0/0/22(D)     GE0/0/23(D)     GE0/0/24(D)                     

10   common  UT:GE0/0/1(U)        接口已经添加进了vlan 10                                               
20   common  

VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------

1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020                         
[SW1]

另一个接口的配置

[SW1]int g0/0/2
[SW1-GigabitEthernet0/0/2]p	
[SW1-GigabitEthernet0/0/2]port t 	
[SW1-GigabitEthernet0/0/2]port type-	
[SW1-GigabitEthernet0/0/2]port type-l	
[SW1-GigabitEthernet0/0/2]port type-	
[SW1-GigabitEthernet0/0/2]port type-	
[SW1-GigabitEthernet0/0/2]port type-?
                               ^
Error: Unrecognized command found at '^' position.
[SW1-GigabitEthernet0/0/2]p	
[SW1-GigabitEthernet0/0/2]port l	
[SW1-GigabitEthernet0/0/2]port link-t	
[SW1-GigabitEthernet0/0/2]p l a  确定其接口状态
[SW1-GigabitEthernet0/0/2]
Jul 29 2025 16:43:29-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 9, the c
hange loop count is 0, and the maximum number of records is 4095.
[SW1-GigabitEthernet0/0/2]p d v 20  划分进vlan 20
[SW1-GigabitEthernet0/0/2]
Jul 29 2025 16:43:49-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 10, the 
change loop count is 0, and the maximum number of records is 4095.
[SW1-GigabitEthernet0/0/2]q
[SW1]dis vlan
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:GE0/0/3(U)      GE0/0/4(D)      GE0/0/5(D)      GE0/0/6(D)      
                GE0/0/7(D)      GE0/0/8(D)      GE0/0/9(D)      GE0/0/10(D)     
                GE0/0/11(D)     GE0/0/12(D)     GE0/0/13(D)     GE0/0/14(D)     
                GE0/0/15(D)     GE0/0/16(D)     GE0/0/17(D)     GE0/0/18(D)     
                GE0/0/19(D)     GE0/0/20(D)     GE0/0/21(D)     GE0/0/22(D)     
                GE0/0/23(D)     GE0/0/24(D)                                     

10   common  UT:GE0/0/1(U)                                                      
20   common  UT:GE0/0/2(U)                                                      


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------
1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020                         
[SW1]

接口3也需要操作的,Trunk接口主要应用于交换机之间,用于vlan之间带标签通信

[SW1]int g0/0/3
[SW1-GigabitEthernet0/0/3]p	
[SW1-GigabitEthernet0/0/3]port l	
[SW1-GigabitEthernet0/0/3]port link-t	
[SW1-GigabitEthernet0/0/3]port link-type tr	
[SW1-GigabitEthernet0/0/3]port link-type trunk  改变接口类型,
[SW1-GigabitEthernet0/0/3]
Jul 29 2025 16:59:49-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 11, the 
change loop count is 0, and the maximum number of records is 4095.
[SW1-GigabitEthernet0/0/3]po	
[SW1-GigabitEthernet0/0/3]port l	
[SW1-GigabitEthernet0/0/3]port link-t	
[SW1-GigabitEthernet0/0/3]port link-type ?
  access        Access port
  dot1q-tunnel  QinQ port
  hybrid        Hybrid port
  trunk         Trunk port

[SW1-GigabitEthernet0/0/3]p	
[SW1-GigabitEthernet0/0/3]port?
  port                                    port-auto-sleep
  port-isolate                            port-mirroring
  port-security                           portal
  portswitch                              
[SW1-GigabitEthernet0/0/3]port ?
  add-tag        Add outer tag based on acl 
  discard        Discard
  link-flap      Link flap 
  link-type      Switch port link type
  mux-vlan       Multiplex vlan
  priority       Specify current port's priority
  trunk          Trunk port
  type           Type 
  vlan-mapping   VLAN Mapping
  vlan-stacking  VLAN Stacking

[SW1-GigabitEthernet0/0/3]port t	
[SW1-GigabitEthernet0/0/3]port trunk ?
  allow-pass  Allowed vlan
  pvid        Specify current port's PVID VLAN characteristics

[SW1-GigabitEthernet0/0/3]port trunk al	
[SW1-GigabitEthernet0/0/3]port trunk allow-pass 

SW2 上操作, 基础配置,

<Huawei>sy
Enter system view, return user view with Ctrl+Z.
[Huawei]sy SW2
[SW2]vlan 10 
Jul 29 2025 16:47:39-08:00 SW2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 4, the c
hange loop count is 0, and the maximum number of records 
[SW2]vlan b	
[SW2]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW2]
Jul 29 2025 16:48:40-08:00 SW2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 5, the c
hange loop count is 0, and the maximum number of records is 4095.
[SW2]int g
           ^
Error:Incomplete command found at '^' position.
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]p l a
确认接口类型,
[SW2-GigabitEthernet0/0/1]p	
[SW2-GigabitEthernet0/0/1]port de	
[SW2-GigabitEthernet0/0/1]port default v	
[SW2-GigabitEthernet0/0/1]port default vlan 10  划分vlan 
[SW2-GigabitEthernet0/0/1]
Jul 29 2025 16:50:30-08:00 SW2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 7, the c
hange loop count is 0, and the maximum number of records is 4095.
[SW2-GigabitEthernet0/0/1]int g0/0/2 进入接口2 然后
[SW2-GigabitEthernet0/0/2]
Jul 29 2025 16:50:53-08:00 SW2 %%01PHY/1/PHY(l)[1]:    GigabitEthernet0/0/2: cha
nge status to down
Jul 29 2025 16:50:54-08:00 SW2 %%01PHY/1/PHY(l)[2]:    GigabitEthernet0/0/2: cha
nge status to up

[SW2-GigabitEthernet0/0/2]p l a 确认类型,
[SW2-GigabitEthernet0/0/2]
Jul 29 2025 16:52:10-08:00 SW2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 8, the c
hange loop count is 0, and the maximum number of records is 4095.
[SW2-GigabitEthernet0/0/2]p d v 20
[SW2-GigabitEthernet0/0/2]dis v	 划分vlan 
[SW2-GigabitEthernet0/0/2]dis vlan
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:GE0/0/3(U)      GE0/0/4(D)      GE0/0/5(D)      GE0/0/6(D)      
                GE0/0/7(D)      GE0/0/8(D)      GE0/0/9(D)      GE0/0/10(D)     
                GE0/0/11(D)     GE0/0/12(D)     GE0/0/13(D)     GE0/0/14(D)     
                GE0/0/15(D)     GE0/0/16(D)     GE0/0/17(D)     GE0/0/18(D)     
                GE0/0/19(D)     GE0/0/20(D)     GE0/0/21(D)     GE0/0/22(D)     
                GE0/0/23(D)     GE0/0/24(D)                                     

10   common  UT:GE0/0/1(U)                                                      
20   common  UT:GE0/0/2(U)                                                      


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------

1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020                         


[SW2]int g0/0/3
[SW2-GigabitEthernet0/0/3]p l t
[SW2-GigabitEthernet0/0/3]p t a v a
[SW2-GigabitEthernet0/0/3]
Jul 29 2025 17:06:10-08:00 SW2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 12, the 
change loop count is 0, and the maximum number of records is 4095.
[SW2-GigabitEthernet0/0/3]p
Jul 29 2025 17:06:14-08:00 SW2 %%01PHY/1/PHY(l)[2]:    GigabitEthernet0/0/1: cha
nge status to down
Jul 29 2025 17:06:15-08:00 SW2 %%01PHY/1/PHY(l)[3]:    GigabitEthernet0/0/1: cha
nge status to up
Error: The interface is already a L2 interface.
[SW2-GigabitEthernet0/0/3]p	
[SW2-GigabitEthernet0/0/3]port t	
[SW2-GigabitEthernet0/0/3]port trunk a	
[SW2-GigabitEthernet0/0/3]port trunk allow-pass  v	
[SW2-GigabitEthernet0/0/3]port trunk allow-pass  vlan a	
[SW2-GigabitEthernet0/0/3]port trunk allow-pass  vlan all