首页 > 其他分享 >VLAN通信

VLAN通信

时间:2023-07-12 16:25:05浏览次数:29  
标签:int Ethernet0 VLAN GigabitEthernet0 通信 up Huawei SW2

VLAN之间通信

再次提及,vlan是虚拟局域网,用于分隔广播域,解决广播风暴。但是vlan之间无法直接通信。所有我们要用三层交换、单臂路由来实现vlan之间的通信。

单臂路由

实现不同VLAN通信

链路类型

  • 交换机连接主机的端口为access链路

  • 交换机连接路由器的端口为Trunk链路

子接口

  • 路由器的物理接口可以被划分成多个逻辑接口

  • 每个子接口对应一个VLAN网段的网关

原理

路由器重新封装MAC地址、转换VLAN标签。

 

image-20230710154730564

#交换机配置(不同网段通信需要配置网关)
<Huawei>undo t m
<Huawei>sys
[Huawei]vlan batch 10 20
[Huawei]int g0/0/2
[Huawei-GigabitEthernet0/0/2]port link-type access
[Huawei-GigabitEthernet0/0/2]port default vlan 10
[Huawei-GigabitEthernet0/0/2]undo sh

[Huawei-GigabitEthernet0/0/2]int g0/0/3
[Huawei-GigabitEthernet0/0/3]port link-type access
[Huawei-GigabitEthernet0/0/3]port default vlan 20
[Huawei-GigabitEthernet0/0/3]undo sh

[Huawei-GigabitEthernet0/0/3]int g0/0/1
[Huawei-GigabitEthernet0/0/1]port link-type trunk
[Huawei-GigabitEthernet0/0/1]port trunk allow-pass vlan all
[Huawei-GigabitEthernet0/0/1]undo sh

#路由器配置
<Huawei>sys
[Huawei]u t m
[Huawei]int g0/0/0.10
#0-4095划分范围
[Huawei-GigabitEthernet0/0/0.10]dot1q termination vid 10
#“dot1q”里的1是数字1
[Huawei-GigabitEthernet0/0/0.10]ip add 192.168.10.1 24
[Huawei-GigabitEthernet0/0/0.10]arp broadcast enable
#arp协议默认关闭,一定要开启
[Huawei-GigabitEthernet0/0/0.10]undo sh
[Huawei-GigabitEthernet0/0/0.10]int g0/0/0.20
[Huawei-GigabitEthernet0/0/0.20]dot1q termination vid 20
[Huawei-GigabitEthernet0/0/0.20]ip add 192.168.20.1 24
[Huawei-GigabitEthernet0/0/0.20]undo sh
[Huawei-GigabitEthernet0/0/0.20]arp broadcast enable
[Huawei-GigabitEthernet0/0/0.20]q
[Huawei]q
<Huawei>display interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
^down: standby
(e): ETHOAM down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface                   PHY   Protocol InUti OutUti   inErrors outErrors
GigabitEthernet0/0/0       up   down       0%     0%         0         0
GigabitEthernet0/0/0.10     up   up         0%     0%         0         0
GigabitEthernet0/0/0.20     up   up         0%     0%         0         0
GigabitEthernet0/0/1       down down       0%     0%         0         0
GigabitEthernet0/0/2       down down       0%     0%         0         0
NULL0                       up   up(s)       0%     0%         0         0

image-20230710185234779

#LSW1里
<Huawei>
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]p l a
[Huawei-GigabitEthernet0/0/1]p d v 10
[Huawei-GigabitEthernet0/0/1]int g0/0/2
[Huawei-GigabitEthernet0/0/1]undo sh
[Huawei-GigabitEthernet0/0/2]p l a
[Huawei-GigabitEthernet0/0/2]p d v 10
[Huawei-GigabitEthernet0/0/2]int g0/0/3
[Huawei-GigabitEthernet0/0/2]undo sh
[Huawei-GigabitEthernet0/0/3]p l a
[Huawei-GigabitEthernet0/0/3]p d v 20
[Huawei-GigabitEthernet0/0/3]int g0/0/4
[Huawei-GigabitEthernet0/0/3]undo sh
[Huawei-GigabitEthernet0/0/4]p l a
[Huawei-GigabitEthernet0/0/4]p d v 20
[Huawei-GigabitEthernet0/0/4]undo sh

[Huawei-GigabitEthernet0/0/4]int g0/0/5
[Huawei-GigabitEthernet0/0/5]port link-type trunk
[Huawei-GigabitEthernet0/0/5]port trunk allow-pass vlan 10 20
[Huawei-GigabitEthernet0/0/5]undo sh

#LSW2里

<Huawei>u t m
<Huawei>sys
[Huawei]vlan batch 10 20
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]p l a
[Huawei-GigabitEthernet0/0/1]p d v 10
[Huawei-GigabitEthernet0/0/1]int g0/0/2
[Huawei-GigabitEthernet0/0/1]undo sh
[Huawei-GigabitEthernet0/0/2]p l a
[Huawei-GigabitEthernet0/0/2]p d v 20
[Huawei-GigabitEthernet0/0/2]int g0/0/5
[Huawei-GigabitEthernet0/0/2]undo sh
[Huawei-GigabitEthernet0/0/5]p l t
[Huawei-GigabitEthernet0/0/5]p t a v 10 20
[Huawei-GigabitEthernet0/0/5]undo sh

#AR1里

<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0.10
[Huawei-GigabitEthernet0/0/0.10]dot1q ter
[Huawei-GigabitEthernet0/0/0.10]dot1q termination vi
[Huawei-GigabitEthernet0/0/0.10]dot1q termination vid 10
[Huawei-GigabitEthernet0/0/0.10]ip add 192.168.1.254 24
#分别配置网关与不同网络段的主机网关对应
[Huawei-GigabitEthernet0/0/0.10]arp br
[Huawei-GigabitEthernet0/0/0.10]arp broadcast ena
[Huawei-GigabitEthernet0/0/0.10]arp broadcast enable
[Huawei-GigabitEthernet0/0/0.10]undo sh
[Huawei-GigabitEthernet0/0/0.10]undo shutdown
Info: Interface GigabitEthernet0/0/0.10 is not shutdown.
[Huawei-GigabitEthernet0/0/0.10]int g0/0/0.20
[Huawei-GigabitEthernet0/0/0.20]dot1q termination vid 20
[Huawei-GigabitEthernet0/0/0.20]ip add 192.168.2.254 24
[Huawei-GigabitEthernet0/0/0.20]undo shutdown
Info: Interface GigabitEthernet0/0/0.20 is not shutdown.
[Huawei-GigabitEthernet0/0/0.20]arp broadcast enable

不同网段之间终端可联通则成功

image-20230710185413837

 

三层交换

三层交换可以实现VLAN间通信(vlanif=vlaninterface)

 

实验一

 

image-20230711095648452

 

<Huawei>u t m
<Huawei>sys
[Huawei]vlan b 10 20 30
##创建10 20 30 三条vlan
[Huawei]int e0/0/1
[Huawei-Ethernet0/0/1]p l a
[Huawei-Ethernet0/0/1]p d v 10
[Huawei-Ethernet0/0/1]int e0/0/2
[Huawei-Ethernet0/0/1]undo sh
##undo shoutdown 作用在真实交换机上
[Huawei-Ethernet0/0/2]p l a
[Huawei-Ethernet0/0/2]p d v 20
[Huawei-Ethernet0/0/2]int e0/0/3
[Huawei-Ethernet0/0/2]undo sh

[Huawei-Ethernet0/0/3]p l a
[Huawei-Ethernet0/0/3]p d v 30
[Huawei-Ethernet0/0/3]undo sh
[Huawei-Ethernet0/0/3]int e0/0/4
[Huawei-Ethernet0/0/4]p l t
[Huawei-Ethernet0/0/4]p t a v a
[Huawei-Ethernet0/0/4]dis th
#
interface Ethernet0/0/4
port link-type trunk
port trunk allow-pass vlan 2 to 4094
#
return

#在三层交换机上配置
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]p l t
[SW2-GigabitEthernet0/0/1]p t a v a
[SW2-GigabitEthernet0/0/1]q
[SW2]vlan batch 10 20 30
[SW2]int vlanif 10
[SW2-Vlanif10]ip address 192.168.1.254 24    
[SW2-Vlanif10]int vlanif 20
[SW2-Vlanif20]ip address 192.168.2.254 24
[SW2-Vlanif20]int vlanif 30
[SW2-Vlanif30]ip address 192.168.3.254 24
[SW2-Vlanif30]dis ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 5
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
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.1.254/24     up         up        
Vlanif20                         192.168.2.254/24     up         up        
Vlanif30                         192.168.3.254/24     up         up  

测试PC3pingPC1,连通,成功。

image-20230711103421849

倘若三层路由器上连接另一台路由器与主机呢

实验二

image-20230711155539510

####LSW1中设置不同端口下的模式
[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]p l a
[SW1-Ethernet0/0/1]p d v 10
##prot default vlan 10
[SW1-Ethernet0/0/1]undo sh

[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]p l a
[SW1-Ethernet0/0/2]p d v 20
[SW1-Ethernet0/0/2]undo sh

[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]p l a
[SW1-Ethernet0/0/3]p d v 30
[SW1-Ethernet0/0/3]undo sh

[SW1-Ethernet0/0/3]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l t
[SW1-GigabitEthernet0/0/1]p t a v a
##prot trunk allow-pass vlan all

####LSW2中设置不同端口
<Huawei>u t m
<Huawei>sys
[Huawei]sys SW2
[SW2]vlan batch 10 20 30 100
##创建vlan分别接纳四段网络
[SW2]
[SW2]int g0/0/2
[SW2-GigabitEthernet0/0/2]p l a
[SW2-GigabitEthernet0/0/2]p d v 100
[SW2-GigabitEthernet0/0/2]int g0/0/1
[SW2-GigabitEthernet0/0/1]p l t
[SW2-GigabitEthernet0/0/1]p t a v a
##之后针对不同子接口添加地址
[SW2]int vlanif 10
[SW2-Vlanif10]ip address 192.168.1.254 24
[SW2-Vlanif10]int vlanif 20
[SW2-Vlanif20]ip address 192.168.2.254 24
[SW2-Vlanif20]int vlanif 30
[SW2-Vlanif30]ip address 192.168.3.254 24
[SW2-Vlanif30]int vlanif 100
[SW2-Vlanif100]ip address 192.168.4.1 24
[SW2-Vlanif100]dis ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 6
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 5
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.1.254/24     up         up        
Vlanif20                         192.168.2.254/24     up         up        
Vlanif30                         192.168.3.254/24     up         up        
Vlanif100                         192.168.4.1/24       up         up        
[SW2-Vlanif100]ip route-static 192.168.5.0 24 192.168.4.2
 

标签:int,Ethernet0,VLAN,GigabitEthernet0,通信,up,Huawei,SW2
From: https://www.cnblogs.com/bacolate/p/17547778.html

相关文章

  • ROS 的三种通信方式 2a82329219bf47c9a8f48a534ab31af7
    ROS的三种通信方式注意以下所有代码均基于:ubuntuROSDate18.04LTSMelodicMoreniaMay23rd,2018 May,2023写在最前,ROS1主要有三种通信方式,分别是:话题通信服务通信参数通信话题通信(Topic)话题通信主要是指通过发布和订阅服务的方式,来进行匿名的通信,一方......
  • VLAN虚拟局域网
    目录一、VLAN的简介和优点二、VLAN的种类和范围三、静态VLAN配置四、实验实验1实验2实验3总结一、VLAN的简介和优点VLAN的概念虚拟局域网(VLAN)是一组逻辑上的设备和用户,这些设备和用户并不受物理位置的限制,可以根据功能、部门及应用等因素将它们组织起来,相互之间的通信就好像......
  • labview与西门子1200 S7通信 PLC不用写通信程序,上位机直接读
    labview与西门子1200S7通信PLC不用写通信程序,上位机直接读写DB块,不是调用DLL,labviewS7协议,简单好用YID:6930654641311183......
  • Dubbo 我手写几行代码,就把通信模式给你解释清楚!
    作者:小傅哥博客:https://bugstack.cn原文:https://bugstack.cn/md/road-map/road-map.html沉淀、分享、成长,让自己和他人都能有所收获!......
  • 进程通信之套接字(TCP)
    1、服务器端1#include<stdio.h>2#include<sys/socket.h>//套接字3#include<netinet/in.h>4#include<string.h>5#include<stdlib.h>6#include<arpa/inet.h>//字节序转换7#include<unistd.h>89//可以正常运行了;1011#def......
  • C# 进程间通过内存映射文件通信
    内存映射文件(Memory-mappedfiles)是一种很好的进程间通信方式,它暴露了底层的细节,具有很强的扩展性以及性能。这里展示一个利用内存映射文件制作的变量同步工具。该工具当前存在的问题是:每次会同步变量的所有字段,不能针对某个字段进行同步。没有使用双缓冲,超出64位的字段......
  • Java-Day-30( 多用户即时通信系统 —— 登录 + 获取在线用户列表 )
    Java-Day-30多用户即时通信系统需求分析用户登录拉取在线用户列表无异常退出私聊群聊发文件服务器推送新闻用户登录功能说明我们暂时人为规定用户名/id=100,密码123456就可以登录,其他用户不能登录后面使用HashMap模拟数据库,可以多个用户登录思路......
  • Java-Day-31( 多用户即时通信系统 —— 无异常退出 + 私聊 + 群发 )
    Java-Day-31多用户即时通信系统无异常退出问题指出:客户端输入9退出的是输出在控制台的主线程,退出的是主菜单,并没有真正的退出因为客户端启动后,相当于是开启了一个进程,在这个进程中启动了一个主线程(main线程),在main主线程中又启动了一个客户端的线程(ClientConn......
  • vlan
    vlan是工作在数据链路层的,经常和交换机打交道。交换机提供更多接口。(2层交换机)其中,交换机有级联、堆叠两种方法来提高更多接口。vlan是什么vlan虚拟局域网,逻辑上划分网络地址(并非隔绝网段,只是分隔广播域,解决广播风暴,泛洪)为什么需要vlan:连在交换机上的主机都在同一个广播域,只是......
  • java串口通信
    java串口通信importjava.io.*;importjava.util.*;importgnu.io.*;publicclassSerialTestimplementsSerialPortEventListener{SerialPortserialPort;//串口名称privatestaticfinalStringPORT_NAME="/dev/ttyUSB0";//波特率priv......