一、实验拓扑
二、实验需求
三、实验步骤及思路
由于vlan2所在的网段和其他vlan所在的网段不同,所以vlan2由路由器的子接口管理,其他vlan由物理接口统一管理
1.设置子接口与物理接口
[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 #配置封装标准,从此接口进出时要封装vlan id
[R1-GigabitEthernet0/0/0.1]arp broadcast enable #开启子接口的arp广播功能
[R1]inter g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.2.1 24
2.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
3.配置交换机
创建所需要的VLAN
[SW1]vlan batch 2 to 6
[SW2]vlan batch 2 to 6
[SW3]vlan batch 2 to 6
4.设置access接口口
将连接PC1和PC2的两个端口g0/0/3和g0/0/2端口设置为access并划分到vlan2
[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
5.设置trunk干道
因为PC2可以访问PC4\5\6,所以vlan3\5\6可以通过trunk干道,vlan4不需要通过,因为PC4不允许访问PC5\6
g0/0/1接口也需要设置为trunk,允许vlan3\5\6通过且携带标签,将pvid设为1
[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
因为PC1\3也可以访问PC2\4\5\6,但由于PC1\3和后者不在同一个网段,访问或者需要借助路由器实现,按照设计,PC1\3来到192.168.2.0/24网段时的出接口是R1的物理接口,没有任何vlan的封装,只需要确保到PC2\4\5\6的出接口允许vlan1通过且剥离vlan1即可
6.设置PC2\4\5\6的接入口
由于PC2\4可以被任何流量访问,故设置为hybrid pvid3\4 U1to6,即所有VLAN都可以访问,但进入此接口时要贴上标签vlan3\4
[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除了不能被vlan4的PC4访问以外,其余流量均可以访问,所以设置为hybrid pvid5 U1to3 5to6
[SW2-GigabitEthernet0/0/2]port hybrid untagged vlan 1 to 3 5 to 6
由于PC6不能被vlan4的PC4和vlan5的PC5访问,其余流量可以访问,所以设置为hybrid pvid 6 U1to3 6
[SW2-GigabitEthernet0/0/3]port hybrid untagged vlan 1 to 3 6
7.设置SW1到R1的出接口
PC1\3在访问网关时要到路由器的子接口,进子接口前必须有vlan2的封装,故出交换机的g0/0/1的时候不能撕标签,而其他流量到路由器都是走物理接口需要将自带的标签撕掉所以g0/0/1的配置是hybrid pvid1 U1 3to6 T2
[SW1-GigabitEthernet0/0/1]port hybrid untagged vlan 1 3 to 6
[SW1-GigabitEthernet0/0/1]port hybrid tagged vlan 2
四、测试
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=128 time=47 ms
From 192.168.2.253: bytes=32 seq=2 ttl=128 time=31 ms
From 192.168.2.253: bytes=32 seq=3 ttl=128 time=32 ms
From 192.168.2.253: bytes=32 seq=4 ttl=128 time=31 ms
From 192.168.2.253: bytes=32 seq=5 ttl=128 time=31 ms
--- 192.168.2.253 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 31/34/47 ms
PC>ping 192.168.2.252
Ping 192.168.2.252: 32 data bytes, Press Ctrl_C to break
From 192.168.2.252: bytes=32 seq=1 ttl=128 time=47 ms
From 192.168.2.252: bytes=32 seq=2 ttl=128 time=47 ms
From 192.168.2.252: bytes=32 seq=3 ttl=128 time=62 ms
From 192.168.2.252: bytes=32 seq=4 ttl=128 time=47 ms
From 192.168.2.252: bytes=32 seq=5 ttl=128 time=78 ms
--- 192.168.2.252 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/56/78 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=47 ms
From 192.168.2.254: bytes=32 seq=5 ttl=128 time=63 ms
--- 192.168.2.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/59/63 ms
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
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
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