目录
一、简单的VLAN划分、理解VLAN
二、实现不同VLAN间通信
(一)单臂路由
(二)三层交换机
dis cur 查看当前设备的配置信息
一、简单的VLAN划分、理解VLAN(二层交换机)
A和B属于VLAN 100
C和D属于VLAN 200
与主机之间相连的交换机端口模式为access
交换机与交换机之间用trunk模式
1 SW1配置(SW2类似)
<Huawei>SYS #进入系统模式
[Huawei]sys SW1 #改名
[SW1]undo info-center enable #关闭日志
[SW1]vlan batch 100 200 #创建 VLAN 100 200
[SW1]int g0/0/1 #进入端口g0/0/1端口
[SW1-GigabitEthernet0/0/1]port link-type access #设置端口为access模式
[SW1-GigabitEthernet0/0/1]port default vlan 100 #将端口划分到vlan 100
[SW1-GigabitEthernet0/0/1]int g0/0/2 #对端口2进行设置
[SW1-GigabitEthernet0/0/2]port link-type access
[SW1-GigabitEthernet0/0/2]port default vlan 200
[SW1-GigabitEthernet0/0/2]int g0/0/3 #进入g0/0/3
[SW1-GigabitEthernet0/0/3]port link-type trunk #设置端口模式为trunk汇聚链接
[SW1-GigabitEthernet0/0/3]port trunk allow-pass vlan 100 200 #设置允许通过该端口的vlan
[SW2]q #进入用户视图
<SW2>save #设置完记得保存
2 对A、B、C、D客户机进行设置(以交换机当客户机)
<Huawei>sys
[Huawei]undo info-center enable
[Huawei]sys A
[A]int vlanif1 #进入交换机的默认vlan的接口,注:不同于以 vlan 1进入的方式
[A-Vlanif1]ip add 192.168.1.2 24 #设置ip地址
3 进行连通测试
3.1 对同一个valn 100的A 、B进行连通测试
<B>ping 192.168.1.2
PING 192.168.1.2: 56 data bytes, press CTRL_C to break
Reply from 192.168.1.2: bytes=56 Sequence=1 ttl=255 time=230 ms
Reply from 192.168.1.2: bytes=56 Sequence=2 ttl=255 time=40 ms
Reply from 192.168.1.2: bytes=56 Sequence=3 ttl=255 time=60 ms
Reply from 192.168.1.2: bytes=56 Sequence=4 ttl=255 time=100 ms
Reply from 192.168.1.2: bytes=56 Sequence=5 ttl=255 time=150 ms
--- 192.168.1.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 40/116/230 ms
3.2 对不同VLAN 进行测试 A ping C
<A>ping 192.168.2.2
PING 192.168.2.2: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- 192.168.2.2 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
3.3将D的IP处于和A同一个网段进行联通测试
[D]int vlanif1
[D-Vlanif1]ip add 192.168.1.4 24
[D-Vlanif1]ping 192.168.1.2
PING 192.168.1.2: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- 192.168.1.2 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
4 结论
- 不同VLAN的设备之间不能直接通信, 即使都连在同一个交换机上也不行,此处涉及到arp协议
- 同VLAN下的设备应处于同一广播域
- 当同一vlan的设备处于不同交换机上的时候,交换机与交换机之间用汇聚链接(trunk)进行连接
二、解决不同VLAN之间的通信问题
(一)基于路由器(单臂路由)
图1 图2
这里选择图1的拓扑图进行实验,图2设置类似
需要在与交换机连接的路由器的端口设置子接口
1 对R1设置
<Huawei>sys
[Huawei]sys R1
[R1]undo info-center e
[R1]int g0/0/1.100 #进入vlan子接口,子接口的编号任意,建议与vlan相同,便于理解
[R1-GigabitEthernet0/0/1.100]ip add 192.168.1.1 24 #网关IP
[R1-GigabitEthernet0/0/1.100]dot1q termination vid 100 #过滤广播帧,只转发vlan id =100的报文(dot1q 其中数字1)
[R1-GigabitEthernet0/0/1.100]arp broadcast enable #开启arp广播协议,若不开启则无法进行跨网段通信
[R1-GigabitEthernet0/0/1.100]int g0/0/1.200
[R1-GigabitEthernet0/0/1.200]ip add 192.168.2.1 24
[R1-GigabitEthernet0/0/1.200]dot1q termination vid 200
[R1-GigabitEthernet0/0/1.200]arp broadcast enable
2 对SW1设置
<Huawei>SYS
[Huawei]undo info-center e
[Huawei]sys SW1[SW1]vlan batch 100 200
[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]port link-type trunk #将与路由器相连接的端口设置为trunk模式
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan 100 200 #允许通过该链路的vlan
[SW1-GigabitEthernet0/0/1]q
[SW1]int g0/0/2
[SW1-GigabitEthernet0/0/2]port link-type access #将端口类型设置为access
[SW1-GigabitEthernet0/0/2]port default vlan 100 #将端口划分到vlan 100
[SW1-GigabitEthernet0/0/2]int g0/0/3
[SW1-GigabitEthernet0/0/3]port link-type access
[SW1-GigabitEthernet0/0/3]port default vlan 200
3 对PC设置
###错误点:未设置静态路由导致ping不通(交换机的静态路由相当于指定PC机的网关)!!!
pc1同
<Huawei>sys
[Huawei]undo info-center e
[Huawei]sys PC2
[PC2]int vlanif1 #进入vlanif1设置IP
[PC2-Vlanif1]ip add 192.168.2.2 24
静态路由配置(格式:ip route-static 目的IP地址 mask 下一条ip地址 )!!!
[PC1]ip route-static 0.0.0.0 0.0.0.0 192.168.1.1 #设置一条静态路由去往网关,若是PC设备只需要在网关处填写网关地址即可(此处是交换机代替的PC),设置网关的
此处设置为去往任意IP地址的报文下一跳地址都为 192.168.1.1,最好设置为 [PC1]ip route-static 192.168.2.0 24 192.168.1.1
######未设置静态路由时#########################################
[PC1]ping 192.168.2.1 #不能跨网段通信
PING 192.168.2.1: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- 192.168.2.1 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
[PC1]ping 192.168.1.1 #能ping通同一网段的设备
PING 192.168.1.1: 56 data bytes, press CTRL_C to break
Reply from 192.168.1.1: bytes=56 Sequence=1 ttl=255 time=170 ms
Reply from 192.168.1.1: bytes=56 Sequence=2 ttl=255 time=60 ms
Reply from 192.168.1.1: bytes=56 Sequence=3 ttl=255 time=80 ms
Reply from 192.168.1.1: bytes=56 Sequence=4 ttl=255 time=60 ms
Reply from 192.168.1.1: bytes=56 Sequence=5 ttl=255 time=80 ms
--- 192.168.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 60/90/170 ms
##############################################################3
4 连通测试
PC1 ping PC2
[PC1]ping 192.168.2.2
PING 192.168.2.2: 56 data bytes, press CTRL_C to break
Reply from 192.168.2.2: bytes=56 Sequence=1 ttl=254 time=90 ms
Reply from 192.168.2.2: bytes=56 Sequence=2 ttl=254 time=100 ms
Reply from 192.168.2.2: bytes=56 Sequence=3 ttl=254 time=60 ms
Reply from 192.168.2.2: bytes=56 Sequence=4 ttl=254 time=50 ms
Reply from 192.168.2.2: bytes=56 Sequence=5 ttl=254 time=60 ms
--- 192.168.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 50/72/100 ms
(二)基于三层交换机
交换机当PC机使用时,一定要设置静态路由,下一跳为网关
1 二层交换机SW2、SW3设置
<Huawei>sys
[Huawei]undo info en
[Huawei]sys SW2
[SW2]vlan 100
[SW2-vlan100]int g0/0/2
[SW2-GigabitEthernet0/0/2]port link-type trunk #与交换机连接的端口设置为trunk模式
[SW2-GigabitEthernet0/0/2]port trunk allow-pass vlan 100
[SW2-GigabitEthernet0/0/2]int g0/0/1
[SW2-GigabitEthernet0/0/1]port link-type ac
[SW2-GigabitEthernet0/0/1]port default vlan 100 #与主机设备连接的端口设置为access模式
2 PC设置(PC1与PC2设置类似)
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]undo in en
Info: Information center is disabled.
[Huawei]sys PC1
[PC1]int vlanif1
[PC1-Vlanif1]ip ad 192.168.1.2 24 #设置IP地址
[PC1]ip route-static 192.168.2.0 24 192.168.1.1 #设置通往网关的静态路由!!!
3 三层交换机SW3设置
<Huawei>sys
[Huawei]undo in en
[Huawei]sys SW1
[SW1]vlan batch 100 200 #创建vlan 100 和200
[SW1]int g0/0/2
[SW1-GigabitEthernet0/0/2]port link-type trunk
[SW1-GigabitEthernet0/0/2]port trunk allow-pass vlan 100
[SW1-GigabitEthernet0/0/2]int g0/0/3
[SW1-GigabitEthernet0/0/3]port link-type trunk
[SW1-GigabitEthernet0/0/3]port trunk allow-pass vlan 200
[SW1-GigabitEthernet0/0/3]q
[SW1]int vlan100 #进入vlan100接口
[SW1-Vlanif100]ip ad 192.168.1.1 24 #设置网关地址
[SW1-Vlanif100]int vlan200 #进入vlan200接口
[SW1-Vlanif200]ip ad 192.168.2.1 24 设置网关地址
4 连通性测试 PC1 ping PC2
[PC2]ping 192.168.1.1
PING 192.168.1.1: 56 data bytes, press CTRL_C to break
Reply from 192.168.1.1: bytes=56 Sequence=1 ttl=255 time=50 ms
Reply from 192.168.1.1: bytes=56 Sequence=2 ttl=255 time=50 ms
Reply from 192.168.1.1: bytes=56 Sequence=3 ttl=255 time=60 ms
Reply from 192.168.1.1: bytes=56 Sequence=4 ttl=255 time=80 ms
Reply from 192.168.1.1: bytes=56 Sequence=5 ttl=255 time=60 ms
--- 192.168.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 50/60/80 ms