实验目的:通过DHCP,为交换机划分不同VLAN
拓扑结构:
路由器配置,代码如下:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[R1]ip pool VLAN10 #创建名为Vlan10的全局地址池
[R1-ip-pool-VLAN10]NET
[R1-ip-pool-VLAN10]network 192.168.10.0 mask 24
[R1-ip-pool-VLAN10]gat
[R1-ip-pool-VLAN10]gateway-list 192.168.10.254
[R1-ip-pool-VLAN10]dns
[R1-ip-pool-VLAN10]dns-list 8.8.8.8
[R1-ip-pool-VLAN10]q
[R1]ip pool VLAN20 #创建名为Vlan20的全局地址池
[R1-ip-pool-VLAN20]network 192.168.20.0 mask 24
[R1-ip-pool-VLAN20]gateway-list 192.168.20.254
[R1-ip-pool-VLAN20]dns-list 8.8.8.8
[R1-ip-pool-VLAN20]q
[R1]int g0/0/0.10 #创建.10子接口
[R1-GigabitEthernet0/0/0.10]dot
[R1-GigabitEthernet0/0/0.10]dot1q termination vid 10
[R1-GigabitEthernet0/0/0.10]arp br
[R1-GigabitEthernet0/0/0.10]arp broadcast enable
[R1-GigabitEthernet0/0/0.10]ip add 192.168.10.254 24
[R1-GigabitEthernet0/0/0.10]dhcp select g
[R1-GigabitEthernet0/0/0.10]dhcp select global
[R1-GigabitEthernet0/0/0.10]q
[R1]int g0/0/0.20 #创建.20子接口
[R1-GigabitEthernet0/0/0.20]dot1q ter
[R1-GigabitEthernet0/0/0.20]dot1q termination v
[R1-GigabitEthernet0/0/0.20]dot1q termination vid 20
[R1-GigabitEthernet0/0/0.20]arp br
[R1-GigabitEthernet0/0/0.20]arp broadcast e
[R1-GigabitEthernet0/0/0.20]arp broadcast enable
[R1-GigabitEthernet0/0/0.20]ip add 192.168.20.254 24
[R1-GigabitEthernet0/0/0.20]dhcp select global
[R1-GigabitEthernet0/0/0.20]q
[R1]
交换机配置如下:
<Huawei>sys
[Huawei]sys sw1
[sw1]vlan
[sw1]vlan b
[sw1]vlan batch 10 20 #创建 10 20两个Vlan
[sw1]dhcp e
[sw1]dhcp enable #开启DHCP
[sw1]int g0/0/10 #连接路由器接口配置Trunk ,并将 Vlan 10 20 放行
[sw1-GigabitEthernet0/0/10]port link-t
[sw1-GigabitEthernet0/0/10]port link-type trunk
[sw1-GigabitEthernet0/0/10]port all
[sw1-GigabitEthernet0/0/10]port trunk allow-pass vlan 10 20
[sw1-GigabitEthernet0/0/10]q
[sw1]int g0/0/1 #将g0/0/1口配置access,并加到vlan 10
[sw1-GigabitEthernet0/0/1]port li
[sw1-GigabitEthernet0/0/1]port link-t
[sw1-GigabitEthernet0/0/1]port link-type a
[sw1-GigabitEthernet0/0/1]port link-type access
[sw1-GigabitEthernet0/0/1]port default v
[sw1-GigabitEthernet0/0/1]port default vlan 10
[sw1]int g0/0/2 #将g0/0/2口配置access,并加到vlan 20
[sw1-GigabitEthernet0/0/2]port link-t
[sw1-GigabitEthernet0/0/2]port link-type access
[sw1-GigabitEthernet0/0/2]port de
[sw1-GigabitEthernet0/0/2]port default v
[sw1-GigabitEthernet0/0/2]port default vlan 20
[sw1-GigabitEthernet0/0/2]q
查看IP获取结果:
PC1:
PC2: