文章目录
一、了解VLAN
1.1VLAN的含义
- VLAN又名“虚拟局域网”,将网络从逻辑上划分为多个虚拟网络
- VLAN分为静态(基于端口的划分)VLAN和动态VLAN(基于MAC地址的划分)
- VLAN的标识:在以太网中实现中继,有ISL和IEEE802.1q两种封装类型
- VLAN范围:通常为1–4094
- VLAN的优势:控制广播,增强网络安全性,简化网络管理
二、VLAN配置实验
2.1实现PC1、PC3和PC5之间互通,PC2和PC4互通
1)分别设置好主机的IP地址
2)在SW1上添加VLAN,并将各接口分配到对应的vlan中,在E0/0/4接口设置trunk模式
[SW1]vlan batch 10 20
[SW1]int e0/0/1
[SW1-Ethernet0/0/1]port link-type access
[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]port link-type access
[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]port link-type access
[SW1-Ethernet0/0/3]int e0/0/5
[SW1-Ethernet0/0/5]port link-type access
[SW1-Ethernet0/0/5]q
[SW1]port-group zu
[SW1-port-group-zu]
Apr 6 2021 15:07:37-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 24, the
change loop count is 0, and the maximum number of records is 4095.
[SW1-port-group-zu]
[SW1-port-group-zu]gr
[SW1-port-group-zu]group-member e0/0/1 e0/0/3
[SW1-port-group-zu]port link-type access
[SW1-port-group-zu]port default vlan 10
[SW1-port-group-zu]q
[SW1]port-group zu2
[SW1-port-group-zu2]
Apr 6 2021 15:25:57-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 25, the
change loop count is 0, and the maximum number of records is 4095.
[SW1-port-group-zu2]gr
[SW1-port-group-zu2]group-member e0/0/2 e0/0/5
[SW1-port-group-zu2]port link-type access
[SW1-port-group-zu2]port default vlan 20
[SW1-port-group-zu2]q
[SW1]int e0/0/4
[SW1-Ethernet0/0/4]port link-type trunk
[SW1-Ethernet0/0/4]port trunk allow-pass vlan all
3)查看SW1的vlan配置
[SW1]dis 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:Eth0/0/4(U) Eth0/0/6(D) Eth0/0/7(D) Eth0/0/8(D)
Eth0/0/9(D) Eth0/0/10(D) Eth0/0/11(D) Eth0/0/12(D)
Eth0/0/13(D) Eth0/0/14(D) Eth0/0/15(D) Eth0/0/16(D)
Eth0/0/17(D) Eth0/0/18(D) Eth0/0/19(D) Eth0/0/20(D)
Eth0/0/21(D) Eth0/0/22(D) GE0/0/1(D) GE0/0/2(D)
Eth-Trunk0(D)
10 common UT:Eth0/0/1(U) Eth0/0/3(U)
TG:Eth0/0/4(U)
20 common UT:Eth0/0/2(U) Eth0/0/5(U)
TG:Eth0/0/4(U)
VID Status Property MAC-LRN Statistics Description
--------------------------------------------------------------------------------
1 enable default enable disable VLAN 0001
10 enable default enable disable VLAN 0010
20 enable default enable disable VLAN 0020
4)在SW2中设置VLAN,并在将各接口加入对应的vlan中,在E0/0/3接口设置trunk模式,再查看vlan表
[SW2]int e0/0/1
[SW2-Ethernet0/0/1]port link-type access
[SW2-Ethernet0/0/1]port default vlan 20
[SW2-Ethernet0/0/1]int e0/0/2 q
[SW2-Ethernet0/0/2]port link-type access
[SW2-Ethernet0/0/2]port default vlan 10
[SW2-Ethernet0/0/1]int e0/0/3
[SW2-Ethernet0/0/3]port link-type trunk
[SW2-Ethernet0/0/3]port trunk allow-pass vlan all
[SW2-Ethernet0/0/3]q
[SW2]dis 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:Eth0/0/3(U) Eth0/0/4(D) Eth0/0/5(D) Eth0/0/6(D)
Eth0/0/7(D) Eth0/0/8(D) Eth0/0/9(D) Eth0/0/10(D)
Eth0/0/11(D) Eth0/0/12(D) Eth0/0/13(D) Eth0/0/14(D)
Eth0/0/15(D) Eth0/0/16(D) Eth0/0/17(D) Eth0/0/18(D)
Eth0/0/19(D) Eth0/0/20(D) Eth0/0/21(D) Eth0/0/22(D)
GE0/0/1(D) GE0/0/2(D) Eth-Trunk0(D)
10 common UT:Eth0/0/2(U)
TG:Eth0/0/3(U)
20 common UT:Eth0/0/1(U)
TG:Eth0/0/3(U)
VID Status Property MAC-LRN Statistics Description
--------------------------------------------------------------------------------
1 enable default enable disable VLAN 0001
10 enable default enable disable VLAN 0010
20 enable default enable disable VLAN 0020
5)此时PC1和PC3能ping通PC5,PC2能ping通PC4
PC>ping 192.168.1.5
Ping 192.168.1.5: 32 data bytes, Press Ctrl_C to break
From 192.168.1.5: bytes=32 seq=1 ttl=128 time=62 ms
From 192.168.1.5: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.1.5: bytes=32 seq=3 ttl=128 time=62 ms
From 192.168.1.5: bytes=32 seq=4 ttl=128 time=63 ms
From 192.168.1.5: bytes=32 seq=5 ttl=128 time=62 ms
--- 192.168.1.5 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.2.2
Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break
From 192.168.2.2: bytes=32 seq=1 ttl=128 time=62 ms
From 192.168.2.2: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.2.2: bytes=32 seq=3 ttl=128 time=62 ms
From 192.168.2.2: bytes=32 seq=4 ttl=128 time=47 ms
From 192.168.2.2: bytes=32 seq=5 ttl=128 time=46 ms
--- 192.168.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 46/56/63 ms
2.2实现PC2和PC4能ping通PC6
6)分别配置好R1,R2的接口的IP地址,并设置好静态路由,由于我在上方将SW1的E0/0/5接口配置了vlan为20,那么R1的GE0/0/0接口IP地址可设置为PC1和PC2的网关192.168.2.1/24,这时PC2和PC4就都能ping通PC6
PC>ping 192.168.10.1
Ping 192.168.10.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.10.1: bytes=32 seq=2 ttl=126 time=47 ms
From 192.168.10.1: bytes=32 seq=3 ttl=126 time=32 ms
From 192.168.10.1: bytes=32 seq=4 ttl=126 time=31 ms
From 192.168.10.1: bytes=32 seq=5 ttl=126 time=47 ms
--- 192.168.10.1 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/39/47 ms
三、配置单臂路由实现下图中设备信息互通
1)配置好PC1、PC2和PC3的IP地址,子网掩码和网关
2)在SW1上添加vlan,并将e0/0/1、e0/0/2和e0/0/3接口分配到对应的vlan中,在e0/0/4中添加trunk模式,添所有的vlan都能通过,最后查看vlan配置
[SW1]vlan batch 10 20 30
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW1]int e0/0/1
[SW1-Ethernet0/0/1]port link-type access
[SW1-Ethernet0/0/1]port default vlan 10
[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]port link-type access
Apr 6 2021 16:54:24-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 8, the c
hange loop count is 0, and the maximum number of records is 4095.
[SW1-Ethernet0/0/2]port default vlan 20
[SW1-Ethernet0/0/2]int e0/03
[SW1-Ethernet0/0/3]port link-type access
[SW1-Ethernet0/0/3]port default vlan 30
Apr 6 2021 16:55:44-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 10, the
change loop count is 0, and the maximum number of records is 4095.
[SW1-Ethernet0/0/3]int e0/0/4
[SW1-Ethernet0/0/4]port link-type trunk
[SW1-Ethernet0/0/4]
Apr 6 2021 17:10:44-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 12, the
change loop count is 0, and the maximum number of records is 4095.
[SW1-Ethernet0/0/4]port trunk allow-pass vlan all
[SW1-Ethernet0/0/4]
Apr 6 2021 17:22:15-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 13, the
change loop count is 0, and the maximum number of records is 4095.
[SW1]dis vlan
The total number of vlans is : 4
--------------------------------------------------------------------------------
U: Up; D: Down; TG: Tagged; UT: Untagged;
MP: Vlan-mapping; ST: Vlan-stacking;
#: ProtocolTransparent-vlan; *: Management-vlan;
--------------------------------------------------------------------------------
VID Type Ports
--------------------------------------------------------------------------------
1 common UT:Eth0/0/4(U) Eth0/0/5(D) Eth0/0/6(D) Eth0/0/7(D)
Eth0/0/8(D) Eth0/0/9(D) Eth0/0/10(D) Eth0/0/11(D)
Eth0/0/12(D) Eth0/0/13(D) Eth0/0/14(D) Eth0/0/15(D)
Eth0/0/16(D) Eth0/0/17(D) Eth0/0/18(D) Eth0/0/19(D)
Eth0/0/20(D) Eth0/0/21(D) Eth0/0/22(D) GE0/0/1(D)
GE0/0/2(D)
10 common UT:Eth0/0/1(U)
TG:Eth0/0/4(U)
20 common UT:Eth0/0/2(U)
TG:Eth0/0/4(U)
30 common UT:Eth0/0/3(U)
TG:Eth0/0/4(U)
VID Status Property MAC-LRN Statistics Description
--------------------------------------------------------------------------------
1 enable default enable disable VLAN 0001
10 enable default enable disable VLAN 0010
20 enable default enable disable VLAN 0020
30 enable default enable disable VLAN 0030
3)在R1路由器配置单臂路由,并放通所有vlan,开启ARP广播
[R1]int g0/0/0.1
[R1-GigabitEthernet0/0/0.1]ip address 192.168.1.254 24
[R1-GigabitEthernet0/0/0.1]dot1q termination vid 10
Apr 6 2021 17:32:10-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]arp broadcast enable
[R1-GigabitEthernet0/0/0.1]int g0/0/0.2
[R1-GigabitEthernet0/0/0.2]ip address 192.168.2.254 24
[R1-GigabitEthernet0/0/0.2]dot1q termination vid 20
[R1-GigabitEthernet0/0/0.2]
Apr 6 2021 17:33:14-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]arp broadcast enable
[R1-GigabitEthernet0/0/0.1]int g0/0/0.3
[R1-GigabitEthernet0/0/0.3]ip address 192.168.3.254 24
[R1-GigabitEthernet0/0/0.3]dot1q termination vid 30
[R1-GigabitEthernet0/0/0.3]
Apr 6 2021 17:38:11-08:00 R1 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP
on the interface GigabitEthernet0/0/0.3 has entered the UP state.
[R1-GigabitEthernet0/0/0.3]arp broadcast enable
4)PC1、PC2和PC3互相ping测试通信
PC>ping 192.168.2.1
Ping 192.168.2.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.2.1: bytes=32 seq=2 ttl=127 time=62 ms
From 192.168.2.1: bytes=32 seq=3 ttl=127 time=63 ms
From 192.168.2.1: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.2.1: bytes=32 seq=5 ttl=127 time=78 ms
--- 192.168.2.1 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/70/78 ms
PC>ping 192.168.3.1
Ping 192.168.3.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.3.1: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.3.1: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.3.1: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.3.1: bytes=32 seq=5 ttl=127 time=94 ms
--- 192.168.3.1 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/82/94 ms
PC>ping 192.168.1.1
Ping 192.168.1.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.1.1: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.1.1: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.1.1: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.1.1: bytes=32 seq=5 ttl=127 time=78 ms
--- 192.168.1.1 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/78/78 ms