拓扑图:
需求:
1.PC1、PC3属于vlan 2
2.PC2、PC4属于vlan 3
3.通过DHCP使得PC获取IP地址信息
4.全网可达
配置路由器
1.创建虚拟接口
[Huawei]int g0/0/0.1
[Huawei-GigabitEthernet0/0/0.1]dot1q t
[Huawei-GigabitEthernet0/0/0.1]dot1q termination vid 2
[Huawei-GigabitEthernet0/0/0.1]ip add 192.168.1.10 24
Error: The specified address conflicts with another address.
[Huawei-GigabitEthernet0/0/0.1]arp broadcast enable
[Huawei-GigabitEthernet0/0/0.1]int g0/0/0.2
[Huawei-GigabitEthernet0/0/0.2]dot1q termination vid 3
[Huawei-GigabitEthernet0/0/0.2]ip add 192.168.2.10 24
2.开启DHCP服务
[Huawei]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[Huawei]ip pool v2
[Huawei-ip-pool-v2]network 192.168.1.0 mask 24
[Huawei-ip-pool-v2]gateway-list 192.168.1.10
[Huawei-ip-pool-v2]q
[Huawei]ip pool v3
Info: It's successful to create an IP address pool.
[Huawei-ip-pool-v3]network 192.168.2.0 mask 24
[Huawei-ip-pool-v3]gateway-list 192.168.2.10
[Huawei-ip-pool-v3]q
[Huawei]int g0/0/0.1
[Huawei-GigabitEthernet0/0/0.1]dhcp select global
[Huawei-GigabitEthernet0/0/0.1]int g0/0/0.2
[Huawei-GigabitEthernet0/0/0.2]dhcp select global
配置交换机
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sy sw1
[sw1]vlan batch 2 to 3
[sw1]int g0/0/2
[sw1-GigabitEthernet0/0/2]port link-type access
[sw1-GigabitEthernet0/0/2]port default vlan 2
[sw1-GigabitEthernet0/0/2]int g0/0/3
[sw1-GigabitEthernet0/0/3]port link-type access
[sw1-GigabitEthernet0/0/3]port default vlan 3
[sw1-GigabitEthernet0/0/3]q
[sw1]int g0/0/1
[sw1-GigabitEthernet0/0/1]port link-type access
[sw1-GigabitEthernet0/0/1]port link-type trunk
[sw1-GigabitEthernet0/0/1]port trunk allow-pass vlan 2 to 3
[sw1]int g0/0/4
[sw1-GigabitEthernet0/0/4]port link-type trunk
[sw1-GigabitEthernet0/0/4]port trunk allow-pass vlan 2 to 3
(注:如果在交换机与路由器、交换机与交换机之间没有使用trunk命令的话网络不通)
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sy sw2
[sw2]vlan batch 2 to 3
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw2]int g0/0/2
[sw2-GigabitEthernet0/0/2]port link-type access
[sw2-GigabitEthernet0/0/2]port default vlan 2
[sw2-GigabitEthernet0/0/2]int g0/0/3
[sw2-GigabitEthernet0/0/3]port link-type access
[sw2-GigabitEthernet0/0/3]port default vlan 2
[sw2-GigabitEthernet0/0/3]port default vlan 3
<sw2>sys
Enter system view, return user view with Ctrl+Z.
[sw2]int g0/0/1
[sw2-GigabitEthernet0/0/1]port link-type trunk
[sw2-GigabitEthernet0/0/1]port trunk allow-pass vlan 2 to 3
结果(PC间能否ping通)
PC1:(以PC1、PC4为例)
PC>ping 192.168.1.254
Ping 192.168.1.254: 32 data bytes, Press Ctrl_C to break
From 192.168.1.254: bytes=32 seq=1 ttl=128 time<1 ms
From 192.168.1.254: bytes=32 seq=2 ttl=128 time<1 ms
From 192.168.1.254: bytes=32 seq=3 ttl=128 time<1 ms
From 192.168.1.254: bytes=32 seq=4 ttl=128 time<1 ms
From 192.168.1.254: bytes=32 seq=5 ttl=128 time<1 ms
--- 192.168.1.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 0/0/0 ms
PC>ping 192.168.2.254
Ping 192.168.2.254: 32 data bytes, Press Ctrl_C to break
From 192.168.2.254: bytes=32 seq=1 ttl=127 time=78 ms
From 192.168.2.254: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.2.254: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.2.254: bytes=32 seq=4 ttl=127 time=94 ms
From 192.168.2.254: bytes=32 seq=5 ttl=127 time=78 ms
--- 192.168.2.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 78/81/94 ms
PC>ping 192.168.2.253
Ping 192.168.2.253: 32 data bytes, Press Ctrl_C to break
From 192.168.2.253: bytes=32 seq=1 ttl=127 time=109 ms
From 192.168.2.253: bytes=32 seq=2 ttl=127 time=110 ms
From 192.168.2.253: bytes=32 seq=3 ttl=127 time=109 ms
From 192.168.2.253: bytes=32 seq=4 ttl=127 time=94 ms
From 192.168.2.253: bytes=32 seq=5 ttl=127 time=109 ms
PC4:
PC>ping 192.168.1.254
Ping 192.168.1.254: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.1.254: bytes=32 seq=2 ttl=127 time=110 ms
From 192.168.1.254: bytes=32 seq=3 ttl=127 time=94 ms
From 192.168.1.254: bytes=32 seq=4 ttl=127 time=109 ms
From 192.168.1.254: bytes=32 seq=5 ttl=127 time=109 ms
--- 192.168.1.254 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/105/110 ms
PC>ping 192.168.2.254
Ping 192.168.2.254: 32 data bytes, Press Ctrl_C to break
From 192.168.2.254: bytes=32 seq=1 ttl=128 time=62 ms
From 192.168.2.254: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.2.254: bytes=32 seq=3 ttl=128 time=62 ms
From 192.168.2.254: bytes=32 seq=4 ttl=128 time=63 ms
From 192.168.2.254: bytes=32 seq=5 ttl=128 time=62 ms
--- 192.168.2.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/62/63 ms
PC>ping 192.168.1.253
Ping 192.168.1.253: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.1.253: bytes=32 seq=2 ttl=127 time=125 ms
From 192.168.1.253: bytes=32 seq=3 ttl=127 time=125 ms
From 192.168.1.253: bytes=32 seq=4 ttl=127 time=125 ms
From 192.168.1.253: bytes=32 seq=5 ttl=127 time=125 ms
--- 192.168.1.253 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/125/125 ms