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
目录
相关文章
|
4月前
wslconfig 配置
wslconfig 配置
80 0
|
7月前
|
存储 算法 Linux
VDO卷的配置
在CentOS 7环境下,VDO通过重删和压缩技术节省磁盘空间,使1T磁盘可存储1.5T数据,降低成本。创建VDO步骤包括:添加64GB新硬盘,安装vdo和kmod-kvdo软件,使用`vdo create`命令创建VDO卷,如`vdo create --name=myvdo --device=/dev/sdb --vdoLogicalSize=200G`。之后,可通过`vdo list`、`vdo status`和`vdostats`检查状态和空间使用。最后,格式化VDO卷,创建挂载点并挂载,完成设置。
74 0
|
7月前
|
Ubuntu 安全 算法
UbuntuSSH配置
UbuntuSSH配置
93 0
|
关系型数据库 MySQL PHP
PHP环境搭建(配置)
PHP环境搭建(配置)
48 0
springdatasource:全部配置
springdatasource:全部配置
79 0
|
Shell Linux 程序员
vs2015配置vcpkg
vs2015配置vcpkg
413 0
|
安全 Shell 网络安全
安全配置
一、 密码配置1、 全局明文密码:控制路由器从用户模式登录到特权模式的密码,显示为明文。Router (confi g)#enable password yujieRouter (config)#Router>enablePassword:明文密码加密:输入明文密码后,通过该命令将密码加密。Router (config)#service password-encryptionRouter(config)#2、 全局密文密码:控制路由器从用户模式登录到特权模式的密码,显示为密文。Router(config)#enable secret cntc-edu.comRoute(通过设置可使用用户在本地
安全配置
|
运维
一个配置引发的血案
一个配置引发的血案一个配置引发的血案,记一次线上事故的复盘。 一天晚上的业务高峰期,出现了超时(数据加载不出来的情况)。 联想到前一天有发版的工作,第一功能上并没有太大的调整,此次发版内容更多的是新增的功能,用户使用量也较少,基本可以排除因功能导致的问题;第二是否中间件出现问题,因数据的交互,有80%是和redis交互,从慢日志查询中未发现有异常情况;第三隐约有人说过用于负载的服务,昨天发版关闭掉了一台。
1308 0
|
Ubuntu Java Linux
|
SQL 存储 关系型数据库