拓扑图
配置交换机
配置vlan 2 vlan 3
<Huawei>sys
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sys
[Huawei]sysname lsw1
[lsw1]vlan 2
[lsw1-vlan2]
[lsw1]vlan 3
[lsw1-vlan3]q
配置接口类型,并划入vlan
[lsw1]int g0/0/2
[lsw1-GigabitEthernet0/0/2]port link-type access
[lsw1-GigabitEthernet0/0/2]port default vlan 2
[lsw1]int g0/0/3
[lsw1-GigabitEthernet0/0/3]port link-type access
[lsw1-GigabitEthernet0/0/3]port default vlan 3
查看vlan
[lsw1-GigabitEthernet0/0/3]display vlan
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up; D: Down; TG: Tagged; UT: Untagged;
MP: Vlan-mapping; ST: Vlan-stacking;
#: ProtocolTransparent-vlan; *: Management-vlan;
--------------------------------------------------------------------------------
VID Type Ports
--------------------------------------------------------------------------------
1 common UT:GE0/0/1(U) GE0/0/4(D) GE0/0/5(D) GE0/0/6(D)
GE0/0/7(D) GE0/0/8(D) GE0/0/9(D) GE0/0/10(D)
GE0/0/11(D) GE0/0/12(D) GE0/0/13(D) GE0/0/14(D)
GE0/0/15(D) GE0/0/16(D) GE0/0/17(D) GE0/0/18(D)
GE0/0/19(D) GE0/0/20(D) GE0/0/21(D) GE0/0/22(D)
GE0/0/23(D) GE0/0/24(D)
2 common UT:GE0/0/2(U)
3 common UT:GE0/0/3(U)
VID Status Property MAC-LRN Statistics Description
--------------------------------------------------------------------------------
1 enable default enable disable VLAN 0001
2 enable default enable disable VLAN 0002
3 enable default enable disable VLAN 0003
设置接口类型并允许所有vlan通过
[lsw1-GigabitEthernet0/0/3]int g0/0/1
[lsw1-GigabitEthernet0/0/1]port link-type trunk
[lsw1-GigabitEthernet0/0/1]
May 8 2023 13:50:40-08:00 lsw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.2
5.191.3.1 configurations have been changed. The current change number is 11, the
change loop count is 0, and the maximum number of records is 4095.
[lsw1-GigabitEthernet0/0/1]port trunk allow-pass vlan all
配置路由器
在接口给vlan下放地址并配置接口ip
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname r1
[r1]int g0/0/0.1
[r1-GigabitEthernet0/0/0.1]dot1q termination vid 2
[r1-GigabitEthernet0/0/0.1]ip accounting
[r1-GigabitEthernet0/0/0.1]ip address 12.1.1.1 24
May 8 2023 13:53:39-08:00 r1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0.1 has entered the UP state.
[r1-GigabitEthernet0/0/0.1]q
[r1]int g0/0/0.2
[r1-GigabitEthernet0/0/0.2]dot1q termination vid 3
[r1-GigabitEthernet0/0/0.2]ip address 23.1.1.1 24
May 8 2023 13:54:25-08:00 r1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/0.2 has entered the UP state.
[r1-GigabitEthernet0/0/0.2]q
配置DHCP
[r1]ip pool 1
Info: It's successful to create an IP address pool.
[r1-ip-pool-1]network 12.1.1.0 mask 24
[r1-ip-pool-1]gateway-list 12.1.1.1
[r1-ip-pool-1]dns-list 8.8.8.8
[r1-ip-pool-1]q
[r1]ip pool 2
Info: It's successful to create an IP address pool.
[r1-ip-pool-2]network 23.1.1.0 mask 24
[r1-ip-pool-2]gateway-list 23.1.1.1
[r1-ip-pool-2]dns-list 8.8.8.8
[r1-ip-pool-2]q
[r1]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[r1]int g0/0/0.1
[r1-GigabitEthernet0/0/0.1]dhcp select global //调用dhcp
[r1-GigabitEthernet0/0/0.1]int g0/0/0.2
[r1-GigabitEthernet0/0/0.2]dhcp select global
给pc应用DHCP
ipconfig命令查看pc是否成功
此时两台pc不能ping通,需要人为开启广播功能使子接口互通
[r1-GigabitEthernet0/0/0.2]arp broadcast enable
[r1-GigabitEthernet0/0/0.2]int g0/0/0.1
[r1-GigabitEthernet0/0/0.1]arp broadcast enable
在pc去ping另一台pc
发现可以ping通