大家好,又见面了,我是你们的朋友全栈君。
实验环境:
1、当检测IP在192.168.10.0./24时,PC接入交换机时,将其划分为VLAN 10,且可以和VLAN 10的服务器通信
2、当检测IP在192.168.20.0/24时,PC接入交换机时,将其划分为VLAN 20,且可以和VLAN 20的服务器通信
SW1
<Huawei>system-view //进入全局配置模式
[Huawei]undo info-center enable //关闭信息告警提示
[Huawei]sysname SW1 //改名
[SW1]VLAN batch 10 20 //创建VLAN10和VLAN20
[SW1]interface g0/0/1 //进入接口
[SW1-GigabitEthernet0/0/1]port link-type trunk //配置为trunk链路
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20 //允许VLAN10和VLAN20通过
[SW1-GigabitEthernet0/0/1]quit //退出
[SW1]
SW2
<Huawei>system-view //进入全局配置模式
[Huawei]undo info-center enable //关闭信息告警提示
[Huawei]sysname SW2 //改名
[SW2]vlan batch 10 20 //创建VLAN10和VLAN20
[SW2]interface g0/0/2 //进入接口
[SW2-GigabitEthernet0/0/2]port link-type access //配置为access链路
[SW2-GigabitEthernet0/0/2]port default vlan 10 //允许VLAN10通过
[SW2-GigabitEthernet0/0/2]quit //退出
[SW2]interface g0/0/3 //进入接口
[SW2-GigabitEthernet0/0/3]port link-type access //配置为access链路
[SW2-GigabitEthernet0/0/3]port default vlan 20 //允许VLAN20通过
[SW2-GigabitEthernet0/0/3]quit //退出
[SW2]interface g0/0/1 //进入接口
[SW2-GigabitEthernet0/0/1]port link-type trunk //配置为trunk链路
[SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20 //允许VLAN10和VLAN20通过
[SW2-GigabitEthernet0/0/1]quit //退出
[SW2]
SW1
[SW1]interface g0/0/2 //进入接口
[SW1-GigabitEthernet0/0/2]port hybrid untagged vlan 10 20 //配置混合接口
[SW1-GigabitEthernet0/0/2]ip-subnet-vlan enable //启动基于IP地址学习VLAN
[SW1-GigabitEthernet0/0/2]quit //退出
[SW1]vlan 10 /进入VLAN 10
[SW1-vlan10]ip-subnet-vlan ip 192.168.10.0 24 //绑定IP地址
[SW1-vlan10]quit //退出
[SW1]vlan 20 //进入VLAN 20
[SW1-vlan20]ip-subnet-vlan ip 192.168.20.0 24 //绑定IP地址
[SW1-vlan20]quit //退出
[SW1]
SW1
[SW1]dis ip-subnet-vlan vlan all //查看IP地址对应的VLAN
----------------------------------------------------------------
Vlan Index IpAddress SubnetMask Priority
----------------------------------------------------------------
10 1 192.168.10.0 255.255.255.0 0
20 1 192.168.20.0 255.255.255.0 0
----------------------------------------------------------------
ip-subnet-vlan count: 2 total count: 2
[SW1]
PC1
PC>ping 192.168.10.10 //pingVLAN 10的计算机
Ping 192.168.10.10: 32 data bytes, Press Ctrl_C to break
From 192.168.10.10: bytes=32 seq=1 ttl=128 time=94 ms
From 192.168.10.10: bytes=32 seq=2 ttl=128 time=62 ms
From 192.168.10.10: bytes=32 seq=3 ttl=128 time=125 ms
From 192.168.10.10: bytes=32 seq=4 ttl=128 time=78 ms
From 192.168.10.10: bytes=32 seq=5 ttl=128 time=63 ms //可以ping通
--- 192.168.10.10 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/84/125 ms
PC2
PC>ping 192.168.20.20 //pingVLAN 20的计算机
Ping 192.168.20.20: 32 data bytes, Press Ctrl_C to break
From 192.168.20.20: bytes=32 seq=1 ttl=128 time=78 ms
From 192.168.20.20: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.20.20: bytes=32 seq=3 ttl=128 time=78 ms
From 192.168.20.20: bytes=32 seq=4 ttl=128 time=78 ms
From 192.168.20.20: bytes=32 seq=5 ttl=128 time=62 ms //可以ping通
--- 192.168.20.20 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/71/78 ms
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/138552.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...