从实践中了解VLAN!

本文详细介绍了VLAN的概念、配置方法,包括静态和动态VLAN的划分,以及如何通过配置VLAN实现不同设备之间的互通。通过实验步骤展示了在SW1和SW2上设置VLAN,确保PC1、PC3、PC5和PC2、PC4之间的通信。同时,通过配置单臂路由,利用R1路由器实现了不同VLAN间的PC1、PC2、PC3和PC6的通信。实验中涉及到了IP地址设置、静态路由以及ARP广播的启用。
摘要由CSDN通过智能技术生成

一、了解VLAN

1.1VLAN的含义

  • VLAN又名“虚拟局域网”,将网络从逻辑上划分为多个虚拟网络
  • VLAN分为静态(基于端口的划分)VLAN和动态VLAN(基于MAC地址的划分)
  • VLAN的标识:在以太网中实现中继,有ISL和IEEE802.1q两种封装类型
  • VLAN范围:通常为1–4094
  • VLAN的优势:控制广播,增强网络安全性,简化网络管理

二、VLAN配置实验

在这里插入图片描述

2.1实现PC1、PC3和PC5之间互通,PC2和PC4互通

1)分别设置好主机的IP地址
2)在SW1上添加VLAN,并将各接口分配到对应的vlan中,在E0/0/4接口设置trunk模式

[SW1]vlan batch 10 20
[SW1]int e0/0/1
[SW1-Ethernet0/0/1]port link-type access
[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]port link-type access
[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]port link-type access
[SW1-Ethernet0/0/3]int e0/0/5
[SW1-Ethernet0/0/5]port link-type access
[SW1-Ethernet0/0/5]q
[SW1]port-group zu
[SW1-port-group-zu]
Apr  6 2021 15:07:37-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 24, the 
change loop count is 0, and the maximum number of records is 4095.
[SW1-port-group-zu]
[SW1-port-group-zu]gr	
[SW1-port-group-zu]group-member e0/0/1 e0/0/3
[SW1-port-group-zu]port link-type access
[SW1-port-group-zu]port default vlan 10
[SW1-port-group-zu]q
[SW1]port-group zu2
[SW1-port-group-zu2]
Apr  6 2021 15:25:57-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 25, the 
change loop count is 0, and the maximum number of records is 4095.
[SW1-port-group-zu2]gr	
[SW1-port-group-zu2]group-member e0/0/2 e0/0/5	
[SW1-port-group-zu2]port link-type access
[SW1-port-group-zu2]port default vlan 20
[SW1-port-group-zu2]q
[SW1]int e0/0/4
[SW1-Ethernet0/0/4]port link-type trunk 
[SW1-Ethernet0/0/4]port trunk allow-pass vlan all

3)查看SW1的vlan配置

[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:Eth0/0/4(U)     Eth0/0/6(D)     Eth0/0/7(D)     Eth0/0/8(D)     
                Eth0/0/9(D)     Eth0/0/10(D)    Eth0/0/11(D)    Eth0/0/12(D)    
                Eth0/0/13(D)    Eth0/0/14(D)    Eth0/0/15(D)    Eth0/0/16(D)    
                Eth0/0/17(D)    Eth0/0/18(D)    Eth0/0/19(D)    Eth0/0/20(D)    
                Eth0/0/21(D)    Eth0/0/22(D)    GE0/0/1(D)      GE0/0/2(D)      
                Eth-Trunk0(D)                                                   

10   common  UT:Eth0/0/1(U)     Eth0/0/3(U)                                     

             TG:Eth0/0/4(U)                                                     

20   common  UT:Eth0/0/2(U)     Eth0/0/5(U)                                     

             TG:Eth0/0/4(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  

4)在SW2中设置VLAN,并在将各接口加入对应的vlan中,在E0/0/3接口设置trunk模式,再查看vlan表

[SW2]int e0/0/1
[SW2-Ethernet0/0/1]port link-type access 
[SW2-Ethernet0/0/1]port default vlan 20
[SW2-Ethernet0/0/1]int e0/0/2                                 q
[SW2-Ethernet0/0/2]port link-type access 
[SW2-Ethernet0/0/2]port default vlan 10
[SW2-Ethernet0/0/1]int e0/0/3  
[SW2-Ethernet0/0/3]port link-type trunk 
[SW2-Ethernet0/0/3]port trunk allow-pass vlan all
[SW2-Ethernet0/0/3]q
[SW2]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:Eth0/0/3(U)     Eth0/0/4(D)     Eth0/0/5(D)     Eth0/0/6(D)     
                Eth0/0/7(D)     Eth0/0/8(D)     Eth0/0/9(D)     Eth0/0/10(D)    
                Eth0/0/11(D)    Eth0/0/12(D)    Eth0/0/13(D)    Eth0/0/14(D)    
                Eth0/0/15(D)    Eth0/0/16(D)    Eth0/0/17(D)    Eth0/0/18(D)    
                Eth0/0/19(D)    Eth0/0/20(D)    Eth0/0/21(D)    Eth0/0/22(D)    
                GE0/0/1(D)      GE0/0/2(D)      Eth-Trunk0(D)                   

10   common  UT:Eth0/0/2(U)                                                     
             TG:Eth0/0/3(U)                                                     

20   common  UT:Eth0/0/1(U)                                                     
             TG:Eth0/0/3(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                                       

5)此时PC1和PC3能ping通PC5,PC2能ping通PC4

PC>ping 192.168.1.5

Ping 192.168.1.5: 32 data bytes, Press Ctrl_C to break
From 192.168.1.5: bytes=32 seq=1 ttl=128 time=62 ms
From 192.168.1.5: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.1.5: bytes=32 seq=3 ttl=128 time=62 ms
From 192.168.1.5: bytes=32 seq=4 ttl=128 time=63 ms
From 192.168.1.5: bytes=32 seq=5 ttl=128 time=62 ms

--- 192.168.1.5 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 62/62/63 ms
PC>ping 192.168.2.2

Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break
From 192.168.2.2: bytes=32 seq=1 ttl=128 time=62 ms
From 192.168.2.2: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.2.2: bytes=32 seq=3 ttl=128 time=62 ms
From 192.168.2.2: bytes=32 seq=4 ttl=128 time=47 ms
From 192.168.2.2: bytes=32 seq=5 ttl=128 time=46 ms

--- 192.168.2.2 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 46/56/63 ms

2.2实现PC2和PC4能ping通PC6

6)分别配置好R1,R2的接口的IP地址,并设置好静态路由,由于我在上方将SW1的E0/0/5接口配置了vlan为20,那么R1的GE0/0/0接口IP地址可设置为PC1和PC2的网关192.168.2.1/24,这时PC2和PC4就都能ping通PC6

PC>ping 192.168.10.1

Ping 192.168.10.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.10.1: bytes=32 seq=2 ttl=126 time=47 ms
From 192.168.10.1: bytes=32 seq=3 ttl=126 time=32 ms
From 192.168.10.1: bytes=32 seq=4 ttl=126 time=31 ms
From 192.168.10.1: bytes=32 seq=5 ttl=126 time=47 ms

--- 192.168.10.1 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/39/47 ms

三、配置单臂路由实现下图中设备信息互通

在这里插入图片描述
1)配置好PC1、PC2和PC3的IP地址,子网掩码和网关
2)在SW1上添加vlan,并将e0/0/1、e0/0/2和e0/0/3接口分配到对应的vlan中,在e0/0/4中添加trunk模式,添所有的vlan都能通过,最后查看vlan配置

[SW1]vlan batch  10 20 30
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW1]int e0/0/1
[SW1-Ethernet0/0/1]port link-type access 
[SW1-Ethernet0/0/1]port default vlan 10
[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]port link-type access 
Apr  6 2021 16:54:24-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 8, the c
hange loop count is 0, and the maximum number of records is 4095. 
[SW1-Ethernet0/0/2]port default vlan 20
[SW1-Ethernet0/0/2]int e0/03
[SW1-Ethernet0/0/3]port link-type access 
[SW1-Ethernet0/0/3]port default vlan 30
Apr  6 2021 16:55:44-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-Ethernet0/0/3]int e0/0/4
[SW1-Ethernet0/0/4]port link-type trunk 
[SW1-Ethernet0/0/4]
Apr  6 2021 17:10:44-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 12, the 
change loop count is 0, and the maximum number of records is 4095.
[SW1-Ethernet0/0/4]port trunk allow-pass vlan all
[SW1-Ethernet0/0/4]
Apr  6 2021 17:22:15-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 13, the 
change loop count is 0, and the maximum number of records is 4095.
[SW1]dis vlan
The total number of vlans is : 4
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

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

10   common  UT:Eth0/0/1(U)                                                     
             TG:Eth0/0/4(U)                                                     

20   common  UT:Eth0/0/2(U)                                                     
             TG:Eth0/0/4(U)                                                     

30   common  UT:Eth0/0/3(U)                                                     

             TG:Eth0/0/4(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                         
30   enable  default       enable  disable    VLAN 0030        

3)在R1路由器配置单臂路由,并放通所有vlan,开启ARP广播

[R1]int g0/0/0.1
[R1-GigabitEthernet0/0/0.1]ip address 192.168.1.254 24
[R1-GigabitEthernet0/0/0.1]dot1q termination vid 10
Apr  6 2021 17:32:10-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/0.1 has entered the UP state. 
[R1-GigabitEthernet0/0/0.1]arp broadcast enable
[R1-GigabitEthernet0/0/0.1]int g0/0/0.2
[R1-GigabitEthernet0/0/0.2]ip address 192.168.2.254 24
[R1-GigabitEthernet0/0/0.2]dot1q termination vid 20
[R1-GigabitEthernet0/0/0.2]
Apr  6 2021 17:33:14-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP 
on the interface GigabitEthernet0/0/0.2 has entered the UP state. 
[R1-GigabitEthernet0/0/0.2]arp broadcast enable 
[R1-GigabitEthernet0/0/0.1]int g0/0/0.3
[R1-GigabitEthernet0/0/0.3]ip address 192.168.3.254 24
[R1-GigabitEthernet0/0/0.3]dot1q termination vid 30
[R1-GigabitEthernet0/0/0.3]
Apr  6 2021 17:38:11-08:00 R1 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP 
on the interface GigabitEthernet0/0/0.3 has entered the UP state. 
[R1-GigabitEthernet0/0/0.3]arp broadcast enable

4)PC1、PC2和PC3互相ping测试通信

PC>ping 192.168.2.1

Ping 192.168.2.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.2.1: bytes=32 seq=2 ttl=127 time=62 ms
From 192.168.2.1: bytes=32 seq=3 ttl=127 time=63 ms
From 192.168.2.1: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.2.1: bytes=32 seq=5 ttl=127 time=78 ms

--- 192.168.2.1 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/70/78 ms

PC>ping 192.168.3.1

Ping 192.168.3.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.3.1: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.3.1: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.3.1: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.3.1: bytes=32 seq=5 ttl=127 time=94 ms

--- 192.168.3.1 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/82/94 ms
PC>ping 192.168.1.1

Ping 192.168.1.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.1.1: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.1.1: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.1.1: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.1.1: bytes=32 seq=5 ttl=127 time=78 ms

--- 192.168.1.1 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/78/78 ms
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值