一、实验目的
-
掌握VLAN、VRRP、STP和Eth-Trunk的基本配置方法。
-
实现内网与外网的通信,并确保网络的高可用性和冗余性。
-
理解DHCP、OSPF和NAT在网络中的应用。
二、实验环境
-
网络拓扑:如图所示,包含两台三层交换机(SW1、SW2)、两台二层交换机(SW3、SW4)、一台路由器(R1)、一台ISP路由器,以及四台PC。
-
设备配置:
-
VLAN划分:VLAN2、VLAN3、VLAN10、VLAN20。
-
IP地址分配:内网使用172.16.0.0/16,外网使用12.0.0.0/24。
-
冗余技术:VRRP用于网关冗余,STP用于环路保护,Eth-Trunk用于链路聚合。
-
三、需求分析
1. VLAN配置
-
需求:内网IP地址使用172.16.0.0/16分配,所有PC通过DHCP获取IP地址。
-
分析:
-
VLAN用于隔离广播域,提高网络安全性。
-
VLAN2和VLAN3分别分配给不同的用户组,VLAN10和VLAN20用于连接三层交换机和路由器。
-
Access端口用于连接PC,Trunk端口用于交换机之间的通信。
-
2. 冗余与负载均衡
-
需求:SW1和SW2之间互为备份,使用VRRP、STP和Eth-Trunk。
-
分析:
-
Eth-Trunk用于链路聚合,提高带宽和冗余性。
-
VRRP用于网关冗余,确保网络故障时的快速切换。
-
STP用于防止环路,优化流量。
-
3. DHCP服务
-
需求:所有PC通过DHCP获取IP地址。
-
分析:
-
DHCP服务简化了IP地址管理,避免手动配置的错误。
-
在SW1和SW2上配置DHCP,确保冗余性。
-
4. 路由与NAT
-
需求:内外网通信,ISP只能配置IP地址。
-
分析:
-
OSPF用于内网路由,确保所有网段可达。
-
NAT用于将内网私有地址转换为公网地址,实现访问外网。
-
5. STP配置
-
需求:配置STP,准备根桥。
-
分析:
-
MSTP用于优化VLAN流量,防止环路。
-
四、实验步骤
1. VLAN配置
二层交换机(SW3、SW4)
-
SW3配置:
[SW3]vlan batch 2 to 3 [SW3-GigabitEthernet0/0/1]port link-type access [SW3-GigabitEthernet0/0/1]port default vlan 2 [SW3-GigabitEthernet0/0/2]port link-type access [SW3-GigabitEthernet0/0/2]port default vlan 3 [SW3]port-group group-member g0/0/3 g0/0/4 [SW3-port-group]port link-type trunk [SW3-port-group]port trunk allow-pass vlan 2 3
-
SW4配置:
[SW4]vlan batch 2 to 3 [SW4-GigabitEthernet0/0/1]port link-type access [SW4-GigabitEthernet0/0/1]port default vlan 2 [SW4-GigabitEthernet0/0/2]port link-type access [SW4-GigabitEthernet0/0/2]port default vlan 3 [SW4]port-group group-member g0/0/3 g0/0/4 [SW4-port-group]port link-type trunk [SW4-port-group]port trunk allow-pass vlan 2 3
三层交换机(SW1、SW2)
-
SW1配置:
[SW1]vlan batch 2 3 10 20 [SW1]int Eth-Trunk 0 [SW1-Eth-Trunk0]port link-type trunk [SW1-Eth-Trunk0]port trunk allow-pass vlan 2 3 [SW1]port-group group-member g0/0/3 to g0/0/4 [SW1-port-group]port link-type trunk [SW1-port-group]port trunk allow-pass vlan 2 3 [SW1]int g0/0/5 [SW1-GigabitEthernet0/0/5]port link-type access [SW1-GigabitEthernet0/0/5]port default vlan 10
-
SW2配置:
[SW2]vlan batch 2 3 10 20 [SW2]int Eth-Trunk 0 [SW2-Eth-Trunk0]port link-type trunk [SW2-Eth-Trunk0]port trunk allow-pass vlan 2 3 [SW2]port-group group-member g0/0/3 to g0/0/4 [SW2-port-group]port link-type trunk [SW2-port-group]port trunk allow-pass vlan 2 3 [SW2]int g0/0/5 [SW2-GigabitEthernet0/0/5]port link-type access [SW2-GigabitEthernet0/0/5]port default vlan 20
2. Eth-Trunk配置
-
SW1配置:
[SW1]int Eth-Trunk 0 [SW1-Eth-Trunk0]trunkport g0/0/1 g0/0/2
-
SW2配置:
[SW2]int Eth-Trunk 0 [SW2-Eth-Trunk0]trunkport g0/0/1 g0/0/2
3. VLAN接口IP配置
-
SW1配置:
[SW1]int Vlanif 2 [SW1-Vlanif2]ip address 172.16.0.1 255.255.255.192 [SW1]int Vlanif 3 [SW1-Vlanif3]ip address 172.16.0.65 255.255.255.192 [SW1]int Vlanif 10 [SW1-Vlanif10]ip address 172.16.0.129 255.255.255.192
-
SW2配置:
[SW2]int Vlanif 2 [SW2-Vlanif2]ip address 172.16.0.2 255.255.255.192 [SW2]int Vlanif 3 [SW2-Vlanif3]ip address 172.16.0.66 255.255.255.192 [SW2]int Vlanif 20 [SW2-Vlanif20]ip address 172.16.0.193 255.255.255.192
4. 路由器配置
-
R1配置:
[R1-GigabitEthernet0/0/1]ip address 172.16.0.130 255.255.255.192 [R1-GigabitEthernet0/0/2]ip address 172.16.0.194 255.255.255.192 [R1-GigabitEthernet0/0/0]ip address 12.0.0.1 255.255.255.0
-
ISP配置:
[ISP-GigabitEthernet0/0/0]ip address 12.0.0.2 255.255.255.0 [ISP-LoopBack0]ip address 2.2.2.2 255.255.255.0
5. STP配置
-
SW1配置:
[SW1]stp enable [SW1]stp mode mstp [SW1]stp region-configuration [SW1-mst-region]region-name aa [SW1-mst-region]instance 1 vlan 2 [SW1-mst-region]instance 2 vlan 3 [SW1-mst-region]active region-configuration [SW1]stp instance 1 root primary [SW1]stp instance 2 root secondary
-
SW2配置:
[SW2]stp enable [SW2]stp mode mstp [SW2]stp region-configuration [SW2-mst-region]region-name aa [SW2-mst-region]instance 1 vlan 2 [SW2-mst-region]instance 2 vlan 3 [SW2-mst-region]active region-configuration [SW2]stp instance 1 root secondary [SW2]stp instance 2 root primary
-
SW3和SW4配置:
[SW3]stp enable [SW3]stp mode mstp [SW3]stp region-configuration [SW3-mst-region]region-name aa [SW3-mst-region]instance 1 vlan 2 [SW3-mst-region]instance 2 vlan 3 [SW3-mst-region]active region-configuration [SW3]port-group group-member GigabitEthernet 0/0/1 to 0/0/2 [SW3-port-group]stp edged-port enable [SW3]stp bpdu-protection
dis stp brief 查看 sw1和sw2
6. VRRP配置
-
SW1配置:
[SW1-Vlanif2]vrrp vrid 1 virtual-ip 172.16.0.62 [SW1-Vlanif2]vrrp vrid 1 priority 120 [SW1-Vlanif2]vrrp vrid 1 track interface g0/0/5 reduced 30 [SW1-Vlanif3]vrrp vrid 2 virtual-ip 172.16.0.126
-
SW2配置:
[SW2-Vlanif2]vrrp vrid 1 virtual-ip 172.16.0.62 [SW2-Vlanif3]vrrp vrid 2 virtual-ip 172.16.0.126 [SW2-Vlanif3]vrrp vrid 2 priority 120 [SW2-Vlanif3]vrrp vrid 2 track interface Vlanif 20 reduced 30
dis vrrp brief查看
7. DHCP配置
-
SW1配置:
[SW1]dhcp enable [SW1]ip pool vlan2 [SW1-ip-pool-vlan2]network 172.16.0.0 mask 255.255.255.192 [SW1-ip-pool-lan2]gateway-list 172.16.0.62 [SW1]int Vlanif 2 [SW1-Vlanif2]dhcp select global [SW1]ip pool vlan3 [SW1-ip-pool-vlan3]network 172.16.0.64 mask 255.255.255.192 [SW1-ip-pool-vlan3]gateway-list 172.16.0.126 [SW1]int Vlanif 3 [SW1-Vlanif3]dhcp select global
-
SW2配置:
[SW2]dhcp enable [SW2]ip pool vlan2 [SW2-ip-pool-vlan2]network 172.16.0.0 mask 255.255.255.192 [SW2-ip-pool-vlan2]gateway-list 172.16.0.62 [SW2]int Vlanif 2 [SW2-Vlanif2]dhcp select global [SW2]ip pool vlan3 [SW2-ip-pool-vlan3]network 172.16.0.64 mask 255.255.255.192 [SW2-ip-pool-vlan3]gateway-list 172.16.0.126 [SW2]int Vlanif 3 [SW2-Vlanif3]dhcp select global
查看各PC获取的ip
8. OSPF配置
-
R1配置:
[R1]ospf 1 router-id 1.1.1.1 [R1-ospf-1]area 0 [R1-ospf-1-area-0.0.0.0]network 172.16.0.128 0.0.0.63 [R1-ospf-1-area-0.0.0.0]network 172.16.0.192 0.0.0.63
-
SW1配置:
[SW1]ospf 1 router-id 2.2.2.2 [SW1-ospf-1]area 0 [SW1-ospf-1-area-0.0.0.0]network 172.16.0.128 0.0.0.63 [SW1-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.0.63 [SW1-ospf-1-area-0.0.0.0]network 172.16.0.64 0.0.0.63
-
SW2配置:
[SW2]ospf 1 router-id 3.3.3.3 [SW2-ospf-1]area 0 [SW2-ospf-1-area-0.0.0.0]network 172.16.0.192 0.0.0.63 [SW2-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.0.63 [SW2-ospf-1-area-0.0.0.0]network 172.16.0.64 0.0.0.63
9. NAT配置
-
R1配置:
[R1]ip route-static 0.0.0.0 0 12.0.0.2 [R1]acl 2000 [R1-acl-basic-2000]rule permit source 172.16.0.0 0.0.0.255 [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]nat outbound 2000 [R1]ospf 1 [R1-ospf-1]default-route-advertise
五、实验结果
-
VLAN通信测试:
-
同一VLAN内的PC可以互相通信。
-
不同VLAN的PC通过三层交换机可以互通。
-
-
VRRP冗余测试:
-
关闭SW1的VLAN2接口,SW2自动接管虚拟IP,PC仍能正常访问网络。
-
-
DHCP测试:
-
所有PC通过DHCP成功获取IP地址。(上面已展示)
-
-
内外网通信测试:
-
内网PC可以访问ISP的LoopBack地址(2.2.2.2)。
-