VLANIF配置

简介: VLANIF配置

实验原理:

VLANIF接口是一种第三层的逻辑接口,用于在第三层实现不同VLAN 之间的通信。


每个VALN有一个VLANIF接口,并通过该接口在网络层转发 VLAN通信。由于每个VLAN是一个广播域,每个 VLAN 可以被看作是一个 IP 网段,因此可以把 VLANIF 接口当作该VLAN的网关,通过在VLANIF 接口上配置IP地址,并允许其基于IP地址进行第三层分组转发,就可以实现VLAN之间在第三层上的互相通信。


案例:

设备配置


LSW1的配置


<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname LSW1
[LSW1]vlan batch 10 30
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW1]
Sep 17 2023 11:07:12-08:00 LSW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.2
5.191.3.1 configurations have been changed. The current change number is 5, the 
change loop count is 0, and the maximum number of records is 4095.
[LSW1]undo info-center enable
Info: Information center is disabled.
[LSW1]port-group pvlan10
[LSW1-port-group-pvlan10]group-member g0/0/9 to g0/0/12
[LSW1-port-group-pvlan10]port link-type access
[LSW1-GigabitEthernet0/0/9]port link-type access
[LSW1-GigabitEthernet0/0/10]port link-type access
[LSW1-GigabitEthernet0/0/11]port link-type access
[LSW1-GigabitEthernet0/0/12]port link-type access
[LSW1-port-group-pvlan10]port default vlan 10
[LSW1-GigabitEthernet0/0/9]port default vlan 10
[LSW1-GigabitEthernet0/0/10]port default vlan 10
[LSW1-GigabitEthernet0/0/11]port default vlan 10
[LSW1-GigabitEthernet0/0/12]port default vlan 10
[LSW1-port-group-pvlan10]q
[LSW1]port-group pvlan30
[LSW1-port-group-pvlan30]group-member g0/0/13 to g0/0/16
[LSW1-port-group-pvlan30]port link-type access
[LSW1-GigabitEthernet0/0/13]port link-type access
[LSW1-GigabitEthernet0/0/14]port link-type access
[LSW1-GigabitEthernet0/0/15]port link-type access
[LSW1-GigabitEthernet0/0/16]port link-type access
[LSW1-port-group-pvlan30]port default vlan 30
[LSW1-GigabitEthernet0/0/13]port default vlan 30
[LSW1-GigabitEthernet0/0/14]port default vlan 30
[LSW1-GigabitEthernet0/0/15]port default vlan 30
[LSW1-GigabitEthernet0/0/16]port default vlan 30
[LSW1-port-group-pvlan30]qu
[LSW1]interface g0/0/24
[LSW1-GigabitEthernet0/0/24]port link-type trunk
[LSW1-GigabitEthernet0/0/24]port trunk allow-pass vlan 10 30
[LSW1-GigabitEthernet0/0/24]qu
[LSW1]display 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(D)      GE0/0/2(D)      GE0/0/3(D)      GE0/0/4(D)      
                GE0/0/5(D)      GE0/0/6(D)      GE0/0/7(D)      GE0/0/8(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(U)     
10   common  UT:GE0/0/9(U)      GE0/0/10(D)     GE0/0/11(D)     GE0/0/12(D)     
             TG:GE0/0/24(U)                                                     
30   common  UT:GE0/0/13(U)     GE0/0/14(D)     GE0/0/15(D)     GE0/0/16(D)     
             TG:GE0/0/24(U)                                                     
VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------
1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
30   enable  default       enable  disable    VLAN 0030                         
[LSW1]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 2        Routes : 2        
Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0


LSW2也是相同的配置


<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname LSW2
[LSW2]
Sep 17 2023 11:14:23-08:00 LSW2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.2
5.191.3.1 configurations have been changed. The current change number is 4, the 
change loop count is 0, and the maximum number of records is 4095.
[LSW2]undo info-center enable
Info: Information center is disabled.
[LSW2]vlan batch 10 30
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW2]port-group pvlan10
[LSW2-port-group-pvlan10]group-member g0/0/9 to g0/0/12
[LSW2-port-group-pvlan10]port link-type access
[LSW2-GigabitEthernet0/0/9]port link-type access
[LSW2-GigabitEthernet0/0/10]port link-type access
[LSW2-GigabitEthernet0/0/11]port link-type access
[LSW2-GigabitEthernet0/0/12]port link-type access
[LSW2-port-group-pvlan10]port default vlan 10
[LSW2-GigabitEthernet0/0/9]port default vlan 10
[LSW2-GigabitEthernet0/0/10]port default vlan 10
[LSW2-GigabitEthernet0/0/11]port default vlan 10
[LSW2-GigabitEthernet0/0/12]port default vlan 10
[LSW2-port-group-pvlan10]qu
[LSW2]port-group pvlan30
[LSW2-port-group-pvlan30]group-member g0/0/13 to g0/0/16
[LSW2-port-group-pvlan30]port link-type access
[LSW2-GigabitEthernet0/0/13]port link-type access
[LSW2-GigabitEthernet0/0/14]port link-type access
[LSW2-GigabitEthernet0/0/15]port link-type access
[LSW2-GigabitEthernet0/0/16]port link-type access
[LSW2-port-group-pvlan30]port default vlan 30
[LSW2-GigabitEthernet0/0/13]port default vlan 30
[LSW2-GigabitEthernet0/0/14]port default vlan 30
[LSW2-GigabitEthernet0/0/15]port default vlan 30
[LSW2-GigabitEthernet0/0/16]port default vlan 30
[LSW2-port-group-pvlan30]qu
[LSW2]interface g0/0/24
[LSW2-GigabitEthernet0/0/24]port link-type trunk
[LSW2-GigabitEthernet0/0/24]port trunk allow-pass vlan 10 30
[LSW2-GigabitEthernet0/0/24]qu
[LSW2]display 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(D)      GE0/0/2(D)      GE0/0/3(D)      GE0/0/4(D)      
                GE0/0/5(D)      GE0/0/6(D)      GE0/0/7(D)      GE0/0/8(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(U)     
10   common  UT:GE0/0/9(U)      GE0/0/10(D)     GE0/0/11(D)     GE0/0/12(D)     
             TG:GE0/0/24(U)                                                     
30   common  UT:GE0/0/13(U)     GE0/0/14(D)     GE0/0/15(D)     GE0/0/16(D)     
             TG:GE0/0/24(U)                                                     
VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------
1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
30   enable  default       enable  disable    VLAN 0030                         
[LSW2]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 2        Routes : 2        
Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
[LSW2]


在PC-10-1命令窗口中输入以下命令,测试是否能与PC-10-2和PC-30-2通信


PC>ping 192.168.10.12
Ping 192.168.10.12: 32 data bytes, Press Ctrl_C to break
From 192.168.10.12: bytes=32 seq=1 ttl=128 time=78 ms
From 192.168.10.12: bytes=32 seq=2 ttl=128 time=93 ms
From 192.168.10.12: bytes=32 seq=3 ttl=128 time=125 ms
From 192.168.10.12: bytes=32 seq=4 ttl=128 time=94 ms
From 192.168.10.12: bytes=32 seq=5 ttl=128 time=110 ms
--- 192.168.10.12 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 78/100/125 ms
PC>ping 192.168.30.12
Ping 192.168.30.12: 32 data bytes, Press Ctrl_C to break
From 192.168.10.11: Destination host unreachable
From 192.168.10.11: Destination host unreachable
From 192.168.10.11: Destination host unreachable
From 192.168.10.11: Destination host unreachable
From 192.168.10.11: Destination host unreachable
--- 192.168.10.1 ping statistics ---
  5 packet(s) transmitted
  0 packet(s) received
  100.00% packet loss


在PC-30-1命令窗口中输入以下命令,测试是否能与PC-30-2和PC-10-2通信


PC>ping 192.168.30.12
Ping 192.168.30.12: 32 data bytes, Press Ctrl_C to break
From 192.168.30.12: bytes=32 seq=1 ttl=128 time=47 ms
From 192.168.30.12: bytes=32 seq=2 ttl=128 time=78 ms
From 192.168.30.12: bytes=32 seq=3 ttl=128 time=78 ms
From 192.168.30.12: bytes=32 seq=4 ttl=128 time=62 ms
From 192.168.30.12: bytes=32 seq=5 ttl=128 time=109 ms
--- 192.168.30.12 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 47/74/109 ms
PC>ping 192.168.10.12
Ping 192.168.10.12: 32 data bytes, Press Ctrl_C to break
From 192.168.30.11: Destination host unreachable
From 192.168.30.11: Destination host unreachable
From 192.168.30.11: Destination host unreachable
From 192.168.30.11: Destination host unreachable
From 192.168.30.11: Destination host unreachable
--- 192.168.30.1 ping statistics ---
  5 packet(s) transmitted
  0 packet(s) received
  100.00% packet loss

可以看到,在同一vlan的PC可以互相ping通,不在同一PC不能ping通

在交换机LSW1或在LSW2上配置VLANIF都可以,这里选择LSW1


#配置到vlan 10的vlanif接口的ip地址
[LSW1]interface vlanif 10
[LSW1-Vlanif10]ip address 192.168.10.1 24
[LSW1-Vlanif10]qu
#配置到vlan 30的vlanif接口的ip地址
[LSW1]interface vlanif 30
[LSW1-Vlanif30]ip address 192.168.30.1 24
[LSW1-Vlanif30]qu
#查看所有端口的状态
[LSW1]display interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
(e): ETHOAM down
(dl): DLDP down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface                   PHY   Protocol InUti OutUti   inErrors  outErrors
GigabitEthernet0/0/1        down  down        0%     0%          0          0
GigabitEthernet0/0/2        down  down        0%     0%          0          0
GigabitEthernet0/0/3        down  down        0%     0%          0          0
GigabitEthernet0/0/4        down  down        0%     0%          0          0
GigabitEthernet0/0/5        down  down        0%     0%          0          0
GigabitEthernet0/0/6        down  down        0%     0%          0          0
GigabitEthernet0/0/7        down  down        0%     0%          0          0
GigabitEthernet0/0/8        down  down        0%     0%          0          0
GigabitEthernet0/0/9        up    up          0%     0%          0          0
GigabitEthernet0/0/10       down  down        0%     0%          0          0
GigabitEthernet0/0/11       down  down        0%     0%          0          0
GigabitEthernet0/0/12       down  down        0%     0%          0          0
GigabitEthernet0/0/13       up    up          0%     0%          0          0
GigabitEthernet0/0/14       down  down        0%     0%          0          0
GigabitEthernet0/0/15       down  down        0%     0%          0          0
GigabitEthernet0/0/16       down  down        0%     0%          0          0
GigabitEthernet0/0/17       down  down        0%     0%          0          0
GigabitEthernet0/0/18       down  down        0%     0%          0          0
GigabitEthernet0/0/19       down  down        0%     0%          0          0
GigabitEthernet0/0/20       down  down        0%     0%          0          0
GigabitEthernet0/0/21       down  down        0%     0%          0          0
GigabitEthernet0/0/22       down  down        0%     0%          0          0
GigabitEthernet0/0/23       down  down        0%     0%          0          0
GigabitEthernet0/0/24       up    up          0%     0%          0          0
#查看所有端口的ip信息  
[LSW1]display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2
Interface                         IP Address/Mask      Physical   Protocol  
MEth0/0/1                         unassigned           down       down      
NULL0                             unassigned           up         up(s)     
Vlanif1                           unassigned           up         down      
Vlanif10                          192.168.10.1/24      up         up        
Vlanif30                          192.168.30.1/24      up         up 
#查看vlanif接口ip配置
[LSW1]display IP interface vlanif 10
Vlanif10 current state : UP 
Line protocol current state : UP
The Maximum Transmit Unit : 1500 bytes
input packets : 0, bytes : 0, multicasts : 0
output packets : 0, bytes : 0, multicasts : 0
Directed-broadcast packets:
 received packets:            0, sent packets:            0 
 forwarded packets:           0, dropped packets:           0 
Internet Address is 192.168.10.1/24 
Broadcast address : 192.168.10.255
TTL being 1 packet number:         0
TTL invalid packet number:         0
ICMP packet input number:          0
  Echo reply:                      0
  Unreachable:                     0
  Source quench:                   0
  Routing redirect:                0
  Echo request:                    0
  Router advert:                   0
  Router solicit:                  0
  Time exceed:                     0
  IP header bad:                   0
  Timestamp request:               0
  Timestamp reply:                 0
[LSW1]display IP interface vlanif 30
Vlanif30 current state : UP 
Line protocol current state : UP
The Maximum Transmit Unit : 1500 bytes
input packets : 0, bytes : 0, multicasts : 0
output packets : 0, bytes : 0, multicasts : 0
Directed-broadcast packets:
 received packets:            0, sent packets:            0 
 forwarded packets:           0, dropped packets:           0 
Internet Address is 192.168.30.1/24 
Broadcast address : 192.168.30.255
TTL being 1 packet number:         0
TTL invalid packet number:         0
ICMP packet input number:          0
  Echo reply:                      0
  Unreachable:                     0
  Source quench:                   0
  Routing redirect:                0
  Echo request:                    0
  Router advert:                   0
  Router solicit:                  0
  Time exceed:                     0
  IP header bad:                   0
  Timestamp request:               0
  Timestamp reply:                 0
#查看交换机ip路由表
[LSW1]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 6        Routes : 6        
Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
   192.168.10.0/24  Direct  0    0           D   192.168.10.1    Vlanif10
   192.168.10.1/32  Direct  0    0           D   127.0.0.1       Vlanif10
   192.168.30.0/24  Direct  0    0           D   192.168.30.1    Vlanif30
   192.168.30.1/32  Direct  0    0           D   127.0.0.1       Vlanif30
[LSW1]


用ping验证不同vlan之间实现相互通信

此时,在PC-10-1命令窗口中输入以下命令,测试是否能与PC-10-2和PC-30-2通信


通过tracert 192.168.30.12可以看出


192.168.10.11---->192.168.10.1---->192.168.30.12


PC>ping 192.168.10.12
Ping 192.168.10.12: 32 data bytes, Press Ctrl_C to break
From 192.168.10.12: bytes=32 seq=1 ttl=128 time=78 ms
From 192.168.10.12: bytes=32 seq=2 ttl=128 time=94 ms
From 192.168.10.12: bytes=32 seq=3 ttl=128 time=78 ms
From 192.168.10.12: bytes=32 seq=4 ttl=128 time=62 ms
From 192.168.10.12: bytes=32 seq=5 ttl=128 time=62 ms
--- 192.168.10.12 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 62/74/94 ms
PC>ping 192.168.30.12
Ping 192.168.30.12: 32 data bytes, Press Ctrl_C to break
From 192.168.30.12: bytes=32 seq=1 ttl=127 time=125 ms
From 192.168.30.12: bytes=32 seq=2 ttl=127 time=63 ms
From 192.168.30.12: bytes=32 seq=3 ttl=127 time=62 ms
From 192.168.30.12: bytes=32 seq=4 ttl=127 time=62 ms
From 192.168.30.12: bytes=32 seq=5 ttl=127 time=94 ms
--- 192.168.30.12 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 62/81/125 ms
PC>tracert 192.168.30.12
traceroute to 192.168.30.12, 8 hops max
(ICMP), press Ctrl+C to stop
 1  192.168.10.1   31 ms  32 ms  31 ms
 2  192.168.30.12   94 ms  78 ms  94 ms


在PC-30-1命令窗口中输入以下命令,测试是否能与PC-10-2和PC-30-2通信


通过tracert 192.168.10.12可以看出


192.168.30.11---->192.168.30.1---->192.168.10.12


PC>ping 192.168.30.12
Ping 192.168.30.12: 32 data bytes, Press Ctrl_C to break
From 192.168.30.12: bytes=32 seq=1 ttl=128 time=63 ms
From 192.168.30.12: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.30.12: bytes=32 seq=3 ttl=128 time=79 ms
From 192.168.30.12: bytes=32 seq=4 ttl=128 time=62 ms
From 192.168.30.12: bytes=32 seq=5 ttl=128 time=93 ms
--- 192.168.30.12 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 62/72/93 ms
PC>ping 192.168.10.12
Ping 192.168.10.12: 32 data bytes, Press Ctrl_C to break
From 192.168.10.12: bytes=32 seq=1 ttl=127 time=125 ms
From 192.168.10.12: bytes=32 seq=2 ttl=127 time=94 ms
From 192.168.10.12: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.10.12: bytes=32 seq=4 ttl=127 time=93 ms
From 192.168.10.12: bytes=32 seq=5 ttl=127 time=78 ms
--- 192.168.10.12 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 78/93/125 ms
PC>tracert 192.168.10.12
traceroute to 192.168.10.12, 8 hops max
(ICMP), press Ctrl+C to stop
 1  192.168.30.1   32 ms  15 ms  31 ms
 2  192.168.10.12   79 ms  78 ms  78 ms
目录
相关文章
|
Docker Python 容器
Python项目打包成docker镜像,并在docker中运行
Python项目打包成docker镜像,并在docker中运行
2405 0
|
存储 消息中间件 缓存
相比游戏客户端,游戏服务端开发无关紧要吗
感觉游戏服务端,除了更新,保存数据啊、生成随机物品啊、都没什么了,好像游戏开发场景中,服务端已经无关紧要了。看着客户端忙成狗,正在摸鱼的你是否也有过这样的疑问?
1612 0
相比游戏客户端,游戏服务端开发无关紧要吗
|
安全 网络协议 网络虚拟化
[ 网络协议篇 ] vlan 详解之 vlan if 详解
[ 网络协议篇 ] vlan 详解之 vlan if 详解
4006 0
[ 网络协议篇 ] vlan 详解之 vlan if 详解
|
7月前
|
SQL 监控 druid
数据库连接池避坑指南:告别“连接超时”与“资源耗尽”,让系统跑得更快!
数据库连接池是高并发系统的“隐形地雷”。本文直击5大高频坑点:池大小失当、连接泄露、超时配置错误、空闲连接失效、盲目依赖默认值,并附实战避坑方案、监控技巧与云环境适配建议,助你轻松应对秒杀、大促等流量洪峰,保障系统又快又稳!
|
机器学习/深度学习 人工智能 自然语言处理
《深度剖析架构蒸馏与逻辑蒸馏:探寻知识迁移的差异化路径》
架构蒸馏与逻辑蒸馏是知识蒸馏的两大核心技术,分别聚焦于模型结构和决策逻辑的优化。架构蒸馏通过模仿大型模型的拓扑结构,提升小型模型的性能与效率;逻辑蒸馏则提炼大型模型的推理路径,增强小型模型的智能决策能力。二者在实现方式、作用机理和应用场景上各有侧重,可互补应用于资源受限环境下的高效模型部署与复杂任务处理,共同推动人工智能的发展。
557 23
|
消息中间件 NoSQL 架构师
招行面试:亿级秒杀,超卖问题+少卖问题,如何解决?(图解+秒懂+史上最全)
45岁资深架构师尼恩在读者交流群中分享了如何系统化解决高并发下的库存抢购超卖少买问题,特别是针对一线互联网企业的面试题。文章详细解析了秒杀系统的四个阶段(扣库预扣、库存扣减、支付回调、库存补偿),并通过Redis分布式锁和Java代码示例展示了如何防止超卖。此外,还介绍了使用RocketMQ延迟消息和xxl-job定时任务解决少卖问题的方法。尼恩强调,掌握这些技术不仅能提升面试表现,还能增强实际项目中的高并发处理能力。相关答案已收入《尼恩Java面试宝典PDF》V175版本,供后续参考。
|
Unix Linux 开发工具
linux笔记 diff及patch的制作与使用
这篇文章是关于Linux系统中使用`diff`命令生成补丁文件以及使用`patch`命令应用这些补丁的详细教程和实战案例。
1578 2
linux笔记 diff及patch的制作与使用
|
缓存 负载均衡 监控
解决邮件延迟问题
【10月更文挑战第21天】
|
Ubuntu 持续交付 Docker
如何在 Ubuntu 20.04 上安装 Docker和DockerCompose
如何在 Ubuntu 20.04 上安装 Docker和DockerCompose
4081 1