三层交换机实验
·
一、实验拓扑

二、实验需求
-
vlan基于图中分配
-
所有PC通过DHCP获取IP地址
-
未知路由通过OSPF获取,整个拓扑为单区域,area 0
-
全网可达
三、配置思路
1.二层交换机的vlan创建及接口划分
2.三层虚拟接口 vlanif接口 的创建
3.OSPF基础配置
4.配置DHCP,PC获取IP并测试
四、代码整理
SW3 配置(二层接入)
<Huawei> system-view [Huawei] sysname SW3 [SW3] vlan batch 10 20 # 连接 PC1 [SW3] interface g 0/0/2 [SW3-Ethernet0/0/1] port link-type access [SW3-Ethernet0/0/1] port default vlan 10 [SW3-Ethernet0/0/1] quit # 连接 PC2 [SW3] interface g 0/0/3 [SW3-Ethernet0/0/2] port link-type access [SW3-Ethernet0/0/2] port default vlan 20 [SW3-Ethernet0/0/2] quit # 连接 SW1 的上行 Trunk [SW3] interface GigabitEthernet 0/0/1 [SW3-GigabitEthernet0/0/1] port link-type trunk [SW3-GigabitEthernet0/0/1] port trunk allow-pass vlan 10 20 [SW3-GigabitEthernet0/0/1] quit
SW4 配置(二层接入)
<Huawei> system-view [Huawei] sysname SW4 [SW4] vlan batch 30 40 # 连接 PC3 [SW4] interface g 0/0/2 [SW4-Ethernet0/0/1] port link-type access [SW4-Ethernet0/0/1] port default vlan 30 [SW4-Ethernet0/0/1] quit # 连接 PC4 [SW4] interface g 0/0/3 [SW4-Ethernet0/0/2] port link-type access [SW4-Ethernet0/0/2] port default vlan 40 [SW4-Ethernet0/0/2] quit # 连接 SW2 的上行 Trunk [SW4] interface GigabitEthernet 0/0/1 [SW4-GigabitEthernet0/0/1] port link-type trunk [SW4-GigabitEthernet0/0/1] port trunk allow-pass vlan 30 40 [SW4-GigabitEthernet0/0/1] quit
SW1 配置(核心路由、网关、OSPF、DHCP)
<Huawei> system-view [Huawei] sysname SW1 [SW1] vlan batch 10 20 100 # 1. 下行连接 SW3 的 Trunk [SW1] interface GigabitEthernet 0/0/1 [SW1-GigabitEthernet0/0/1] port link-type trunk [SW1-GigabitEthernet0/0/1] port trunk allow-pass vlan 10 20 [SW1-GigabitEthernet0/0/1] quit # 2. 互联连接 SW2 的接口(Access 模式) [SW1] interface GigabitEthernet 0/0/2 [SW1-GigabitEthernet0/0/2] port link-type access [SW1-GigabitEthernet0/0/2] port default vlan 100 [SW1-GigabitEthernet0/0/2] quit # 3. 配置 VLANIF 网关 [SW1] interface Vlanif 10 [SW1-Vlanif10] ip address 192.168.10.254 24 [SW1-Vlanif10] quit [SW1] interface Vlanif 20 [SW1-Vlanif20] ip address 192.168.20.254 24 [SW1-Vlanif20] quit # 4. 配置互联 IP (VLAN100) [SW1] interface Vlanif 100 [SW1-Vlanif100] ip address 10.1.100.1 24 [SW1-Vlanif100] quit # 5. DHCP 配置 开启dhcp-->创建地址池-->让网关可以获取全局地址池 [SW1] dhcp enable [SW1] ip pool vlan10 [SW1-ip-pool-vlan10] network 192.168.10.0 mask 255.255.255.0 [SW1-ip-pool-vlan10] gateway-list 192.168.10.254 [SW1-ip-pool-vlan10] dns-list 114.114.114.114 [SW1-ip-pool-vlan10] quit [SW1] ip pool vlan20 [SW1-ip-pool-vlan20] network 192.168.20.0 mask 255.255.255.0 [SW1-ip-pool-vlan20] gateway-list 192.168.20.254 [SW1-ip-pool-vlan20] dns-list 114.114.114.114 [SW1-ip-pool-vlan20] quit [SW1] interface Vlanif 10 [SW1-Vlanif10] dhcp select global [SW1-Vlanif10] quit [SW1] interface Vlanif 20 [SW1-Vlanif20] dhcp select global [SW1-Vlanif20] quit # 6. OSPF 配置 (单区域 Area 0) 假设sw1和sw2是两台路由器,sw1直连网段只有两个,要实现互通,要共享自己的网段(宣告自己所在的网段),获取除了自己直连网段之外的其他网段。 [SW1] ospf 1 router-id 1.1.1.1 [SW1-ospf-1] area 0 [SW1-ospf-1-area-0.0.0.0] network 192.168.10.0 0.0.0.255 [SW1-ospf-1-area-0.0.0.0] network 192.168.20.0 0.0.0.255 [SW1-ospf-1-area-0.0.0.0] network 10.1.100.0 0.0.0.255 [SW1-ospf-1-area-0.0.0.0] quit
SW2 配置(核心路由、网关、OSPF、DHCP)
<Huawei> system-view [Huawei] sysname SW2 [SW2] vlan batch 30 40 100 # 1. 下行连接 SW4 的 Trunk [SW2] interface GigabitEthernet 0/0/2 [SW2-GigabitEthernet0/0/2] port link-type trunk [SW2-GigabitEthernet0/0/2] port trunk allow-pass vlan 30 40 配置trunk,允许vlan30 40 可以通过 [SW2-GigabitEthernet0/0/2] quit # 2. 互联连接 SW1 的接口(Access 模式) [SW2] interface GigabitEthernet 0/0/1 [SW2-GigabitEthernet0/0/1] port link-type access [SW2-GigabitEthernet0/0/1] port default vlan 100 [SW2-GigabitEthernet0/0/1] quit # 3. 配置 VLANIF 网关 [SW2] interface Vlanif 30 [SW2-Vlanif30] ip address 192.168.30.254 24 [SW2-Vlanif30] quit [SW2] interface Vlanif 40 [SW2-Vlanif40] ip address 192.168.40.254 24 [SW2-Vlanif40] quit # 4. 配置互联 IP (VLAN100) [SW2] interface Vlanif 100 [SW2-Vlanif100] ip address 10.1.100.2 24 [SW2-Vlanif100] quit # 5. DHCP 配置 [SW2] dhcp enable [SW2] ip pool vlan30 [SW2-ip-pool-vlan30] network 192.168.30.0 mask 255.255.255.0 [SW2-ip-pool-vlan30] gateway-list 192.168.30.254 [SW2-ip-pool-vlan30] dns-list 114.114.114.114 [SW2-ip-pool-vlan30] quit [SW2] ip pool vlan40 [SW2-ip-pool-vlan40] network 192.168.40.0 mask 255.255.255.0 [SW2-ip-pool-vlan40] gateway-list 192.168.40.254 [SW2-ip-pool-vlan40] dns-list 114.114.114.114 [SW2-ip-pool-vlan40] quit [SW2] interface Vlanif 30 [SW2-Vlanif30] dhcp select global [SW2-Vlanif30] quit [SW2] interface Vlanif 40 [SW2-Vlanif40] dhcp select global [SW2-Vlanif40] quit # 6. OSPF 配置 (单区域 Area 0) [SW2] ospf 1 router-id 2.2.2.2 [SW2-ospf-1] area 0 [SW2-ospf-1-area-0.0.0.0] network 192.168.30.0 0.0.0.255 [SW2-ospf-1-area-0.0.0.0] network 192.168.40.0 0.0.0.255 [SW2-ospf-1-area-0.0.0.0] network 10.1.100.0 0.0.0.255 [SW2-ospf-1-area-0.0.0.0] quit
最后:PC 端设置与测试
-
双击 PC1~PC4,在“基础配置”里将 IPv4 选为 DHCP,点击“应用”。
-
在 PC 命令行输入
ipconfig,检查是否获取到对应的 IP 和网关。 -
在 PC1 上执行
ping 192.168.40.X(PC4的 IP),测试全网互通(建议连 ping 两次,第一次可能因为模拟器 ARP 解析丢包,第二次一定是 0% 丢失)。
五、验收

1.验收设备接口vlan划分情况(使用 display port vlan active查看后截图)
SW1:

SW2:
SW3:
SW4:
2.验收 vlanif接口 的配置(使用 display ip interface brief 获取接口IP的情况)
SW1:

SW2:
3.验收OSPF配置情况(如图所示)

SW1: 
SW2:

4.验收OSPF的邻居建立情况(使用 display ospf peer brief 查看邻居关系)
SW1:

5.验收OSPF路由获取情况(使用 display ip routing-table protocol ospf 查看
OSPF路由表)
SW1:

SW2:

6.验收DHCP下发IP情况(PC使用 ipconfig 查看)
PC1:

PC2:

PC3:

PC4:

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐



所有评论(0)