VLAN实验
实验要求如上
分析 sw1,2,3的 001 002都是access接口 只能放通相应的vlan 而且由于电脑不能读懂带有tag的帧 所以使用access接口
配置sw1
修改名字
[Huawei]sys sw1
[sw1]vlan 2
创建vlan
[sw1-vlan2]quit
[sw1]vlan 3
[sw1-vlan3]quit
[sw1]int g0/0/1
进入001口此口只允许放通 vlan2
[sw1-GigabitEthernet0/0/1]port link-type access
将此接口设为access模式
[sw1-GigabitEthernet0/0/1]port default vlan 2
允许放通 vlan2
[sw1-GigabitEthernet0/0/2]port link-type access
[sw1-GigabitEthernet0/0/2]port default vlan 3
允许放通 vlan3
access只能放通一个vlan
配置sw2
[sw2-GigabitEthernet0/0/1]port link-type access
[sw2-GigabitEthernet0/0/1]port default vlan 2
[sw2-GigabitEthernet0/0/2]port link-type access
[sw2-GigabitEthernet0/0/2]port default vlan 3
配置sw3
[sw3-GigabitEthernet0/0/1]port link-type access
[sw3-GigabitEthernet0/0/1]port default vlan 2
[sw3-GigabitEthernet0/0/2]port link-type access
[sw3-GigabitEthernet0/0/2]port default vlan 3
以上过程将access接口配置完成
配置sw1 2之间的trunk接口
[sw1-GigabitEthernet0/0/3]port link-type trunk
[sw1-GigabitEthernet0/0/3]port trunk allow-pass vlan 2 3
[sw2-GigabitEthernet0/0/3]port link-type trunk
[sw2-GigabitEthernet0/0/3]port trunk allow-pass vlan 2 3
将pc1 的IP设为192.168.1.2 pc3的IP设为192.168.1.1
测试可以ping通
设置路由器与交换机之间的接口
[sw2-GigabitEthernet0/0/4]port link-type trunk
[sw2-GigabitEthernet0/0/4]port trunk allow-pass vlan 2 3
[sw3-GigabitEthernet0/0/3]port link-type trunk
[sw3-GigabitEthernet0/0/3]port trunk allow-pass vlan 2 3
开始配置路由器
[Huawei]sys rou
[rou]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
开启dhcp服务
成为dhcp服务器的条件:
有真实的物理网卡
有合法的ip
配置ip
[rou]int g 0/0/0.1
[rou-GigabitEthernet0/0/0.1]ip add 192.168.1.1 24
由于带有tag的帧路由器看不懂 所以要声明如下:
[rou-GigabitEthernet0/0/0.1]dot1q termination vid 2
dot1q 又称 802.1q
要允许路由器接口回应广播包需要开启:
[rou-GigabitEthernet0/0/0.1]arp broadcast enable
创建池子供DHCP服务器使用
如图 我们拥有4个网段
所以声明四个池子
[rou]ip pool 1
Info: It's successful to create an IP address pool.
[rou-ip-pool-1]network 192.168.1.0 mask 24
[rou-ip-pool-1]gateway-list 192.168.1.1
[rou-ip-pool-1]dns-list 8.8.8.8
[rou-ip-pool-1]ip pool 2
Info: It's successful to create an IP address pool.
[rou-ip-pool-2]network 192.168.2.0 mask 24
[rou-ip-pool-2]gateway-list 192.168.2.1
[rou-ip-pool-2]dns-list 8.8.8.8
[rou-ip-pool-2]ip pool 3
Info: It's successful to create an IP address pool.
[rou-ip-pool-3]network 192.168.3.0 mask 24
[rou-ip-pool-3]gateway-list 192.168.3.1
[rou-ip-pool-3]dns-list 8.8.8.8
[rou]ip pool 4
Info: It's successful to create an IP address pool.
[rou-ip-pool-4]network 192.168.4.0 mask 24
[rou-ip-pool-4]gateway-list 192.168.4.1
[rou-ip-pool-4]dns-list 8.8.8.8
[rou-ip-pool-4]in g0/0/0.1
[rou-GigabitEthernet0/0/0.1]dhcp
[rou-GigabitEthernet0/0/0.1]dhcp ?
alarm Alarm
check Check
client DHCP client
option82 <Group> option82 command group
relay DHCP relay
select Select
[rou-GigabitEthernet0/0/0.1]dhcp select global
在000.1口上开启DHCP服务
现在查看vlan 2下的主机IP
可以看到pc1和pc3都有了自己的IP
pc5 6与这几个主机不在一个广播域
以下进行对左侧的vlan 3的DHCP配置
[rou]int g0/0/0.2
创建并进入子接口
[rou-GigabitEthernet0/0/0.2]ip add 192.168.2.1 24
[rou-GigabitEthernet0/0/0.2]dot1q termination vid 3
May 19 2023 11:08:05-08:00 rou %%01IFNET/4/LINK_STATE(l)[5]:The line protocol IP
on the interface GigabitEthernet0/0/0.2 has entered the UP state.
[rou-GigabitEthernet0/0/0.2]arp broadcast enable
[rou-GigabitEthernet0/0/0.2]dhcp select global
可以看到vlan3也能享受DHCP服务了
进行路由器右侧的配置
[rou]int g0/0/1.1
[rou-GigabitEthernet0/0/1.1]ip add 192.168.3.1 24
[rou-GigabitEthernet0/0/1.1]dot1q termination vid 2
May 19 2023 11:12:34-08:00 rou %%01IFNET/4/LINK_STATE(l)[6]:The line protocol IP
on the interface GigabitEthernet0/0/1.1 has entered the UP state.
[rou-GigabitEthernet0/0/1.1]dhcp select global
[rou-GigabitEthernet0/0/1.1]arp broadcast enable
[rou]int g0/0/1.2
[rou-GigabitEthernet0/0/1.2]ip add 192.168.4.1 24
[rou-GigabitEthernet0/0/1.2]dot1q termination vid 3
[rou-GigabitEthernet0/0/1.2]
May 19 2023 11:15:08-08:00 rou %%01IFNET/4/LINK_STATE(l)[7]:The line protocol IP
on the interface GigabitEthernet0/0/1.2 has entered the UP state.
[rou-GigabitEthernet0/0/1.2]dhcp select global
[rou-GigabitEthernet0/0/1.2]arp broadcast enable
由于是直连路由器 不需要配置路由表进行测试
用路由器左侧vlan2设备ping vlan3 以及路由器右侧vlan 2 3 设备 全网可达!!