给子接口和物理接口配置ip
[R1]interface g0/0/0.1
[R1-GigabitEthernet0/0/0.1]ip add 192.168.1.1 24
[R1-GigabitEthernet0/0/0.1]dot1q termination vid 2
[R1-GigabitEthernet0/0/0.1]arp broadcast enable
[R1]inter g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.2.1 24
启动DHCP
[R1]dhcp enable
[R1]ip pool a
[R1-ip-pool-a]network 192.168.1.0 mask 24
[R1-ip-pool-a]gateway-list 192.168.1.1
[R1]ip pool b
[R1-ip-pool-a]network 192.168.2.0 mask 24
[R1-ip-pool-a]gateway-list 192.168.2.1
在接口上开启DHCP服务
[R1-GigabitEthernet0/0/0.1]dhcp select global
[R1-GigabitEthernet0/0/0]dhcp select global
创建vlan
[SW1]vlan batch 2 to 6
设置access接口
[SW1]inter g0/0/3
[SW1-GigabitEthernet0/0/3]port link-type access
[SW1-GigabitEthernet0/0/3]port default vlan 2
[SW1]inter g0/0/2
[SW1-GigabitEthernet0/0/2]port link-type access
[SW1-GigabitEthernet0/0/2]port default vlan 2
设置trunk干道
[SW1-GigabitEthernet0/0/6]port link-type trunk
[SW1-GigabitEthernet0/0/6]port trunk allow-pass vlan 3 5 to 6
[SW2-GigabitEthernet0/0/1]port link-type trunk
[SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan 3 5 to 6
设置PC2\4\5\6的接入口
[SW1-GigabitEthernet0/0/4]port hybrid pvid vlan 3
[SW1-GigabitEthernet0/0/4]port hybrid untagged vlan 1 to 6
[SW1-GigabitEthernet0/0/5]port hybrid pvid vlan 4
[SW1-GigabitEthernet0/0/5]port hybrid untagged vlan 1 to 6
PC5除了不能被PC4访问
[SW2-GigabitEthernet0/0/2]port hybrid untagged vlan 1 to 3 5 to 6
PC6不能被PC4和PC5
[SW2-GigabitEthernet0/0/3]port hybrid untagged vlan 1 to 3 6
测试
PC2能ping通PC4\5\6
PC>ping 192.168.2.251
Ping 192.168.2.251: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.2.251: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.2.251: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.2.251: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.2.251: bytes=32 seq=5 ttl=127 time=63 ms
--- 192.168.2.251 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/74/78 ms
PC4不能ping通PC5
PC>
PC>ping 192.168.2.252
Ping 192.168.2.252: 32 data bytes, Press Ctrl_C to break
Request timeout!
Request timeout!
Request timeout!
Request timeout!
Request timeout!
--- 192.168.2.252 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
PC4不能ping通PC5
PC>ping 192.168.2.253
Ping 192.168.2.253: 32 data bytes, Press Ctrl_C to break
From 192.168.2.251: Destination host unreachable
From 192.168.2.251: Destination host unreachable
From 192.168.2.251: Destination host unreachable
From 192.168.2.251: Destination host unreachable
From 192.168.2.251: Destination host unreachable
--- 192.168.2.253 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
PC5不能ping通PC6
PC>ping 192.168.2.254
Ping 192.168.2.254: 32 data bytes, Press Ctrl_C to break
From 192.168.2.252: Destination host unreachable
From 192.168.2.252: Destination host unreachable
From 192.168.2.252: Destination host unreachable
From 192.168.2.252: Destination host unreachable
From 192.168.2.252: Destination host unreachable
--- 192.168.2.254 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
pc1可以访问pc2/4/5/6
PC>ping 192.168.2.251
Ping 192.168.2.251: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.2.251: bytes=32 seq=2 ttl=127 time=94 ms
From 192.168.2.251: bytes=32 seq=3 ttl=127 time=46 ms
From 192.168.2.251: bytes=32 seq=4 ttl=127 time=79 ms
From 192.168.2.251: bytes=32 seq=5 ttl=127 time=78 ms
--- 192.168.2.251 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/74/94 ms
PC>ping 192.168.2.253
Ping 192.168.2.253: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.2.253: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.2.253: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.2.253: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.2.253: bytes=32 seq=5 ttl=127 time=78 ms
--- 192.168.2.253 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/78/78 ms
PC>ping 192.168.2.252
Ping 192.168.2.252: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.2.252: bytes=32 seq=2 ttl=127 time=125 ms
From 192.168.2.252: bytes=32 seq=3 ttl=127 time=94 ms
From 192.168.2.252: bytes=32 seq=4 ttl=127 time=94 ms
From 192.168.2.252: bytes=32 seq=5 ttl=127 time=94 ms
--- 192.168.2.252 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/101/125 ms
PC>ping 192.168.2.254
Ping 192.168.2.254: 32 data bytes, Press Ctrl_C to break
Request timeout!
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=94 ms
From 192.168.2.254: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.2.254: bytes=32 seq=5 ttl=127 time=109 ms
--- 192.168.2.254 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/89/109 ms