← 林的博客在博客中阅读

分解实验12:防火墙配置

2026-10-11Network / Huawei

本实验在 eNSP 的 USG6000V 防火墙上完成接口与安全区域划分、安全策略、源 NAT(地址池 100.1.1.10-100.1.1.20)和 NAT Server 端口映射,让内网 PC 访问 Internet,并让 Internet 通过公网地址访问 DMZ 中的 Web 服务器。

1、实验拓扑

设备 接口 IP 地址/掩码 安全区域/角色
Internet GE0/0/0 100.1.1.2/24 用 1 台路由器或者 PC 模拟 Internet
Firewall GE1/0/3 100.1.1.1/24 Untrust
Firewall GE1/0/2 192.168.2.254/24 DMZ
Firewall GE1/0/1 192.168.1.254/24 Trust
Server - 192.168.2.100/24 DMZ 区内部 Web 服务器
Switch GE0/0/24 - 上联 Firewall GE1/0/1
Switch GE0/0/1 - 接 PC1
Switch GE0/0/2 - 接 PC2
PC1 - 192.168.1.1/24 内网主机(Trust)
PC2 - 192.168.1.2/24 内网主机(Trust)
                 Internet(100.1.1.2/24)
                     |
                     | GE1/0/3 100.1.1.1/24(Untrust)
                  Firewall  GE1/0/2 192.168.2.254(DMZ) ------ Server 192.168.2.100/24
                     | GE1/0/1 192.168.1.254/24(Trust)
                     |
                     | GE0/0/24
                   Switch
           GE0/0/1 /      \ GE0/0/2
                PC1          PC2
         192.168.1.1/24   192.168.1.2/24

2、配置要求

  1. 防火墙接口的 IP 地址如拓扑所示,将接口划入相应的安全区域。
  2. 内网主机 PC1 可以主动访问 Internet,但 Internet 无法主动访问 PC1。
  3. 出口防火墙进行 NAT,NAT 公网地址池 100.1.1.10-100.1.1.20。
  4. Internet 可以通过公网地址 100.1.1.100/24 访问目的地址为 192.168.2.100/24 的内部 Web 服务。

3、配置步骤

第 1 步:防火墙初始化配置

提示:eNSP 中防火墙有 USG5500 和 USG6000V,两者配置略有差异。前者是老的 UTM 设备,已经淘汰,现在华为主推的是 USG6000 系列,故实验用 USG6000V。

Recover configuration begin ...
Recover configuration end
Press ENTER to get started.

Login authentication
Username:admin //华为防火墙默认用户名是admin,默认密码是Admin@123。
Password:
The password needs to be changed. Change now? [Y/N]: y //登录提示修改密码,输入y,表示要修改密码。
Please enter old password: //输入旧的密码Admin@123
Please enter new password: //输入新密码Admin@1234(新密码要满足复杂性要求)
Please confirm new password: //再次输入新密码

 Info: Your password has been changed. Save the change to survive a reboot.
*************************************************************************
*        Copyright (C) 2014-2018 Huawei Technologies Co., Ltd.        *
*                        All rights reserved.                         *
*            Without the owner's prior written consent,               *
*       no decompiling or reverse-engineering shall be allowed.       *
*************************************************************************
<USG6000V1> system-view //进入系统模式
[USG6000V1] sysname Firewall //防火墙重命名为Firewall

第 2 步:配置防火墙接口 IP 地址

(1)防火墙接口 IP 配置

[FW] interface GigabitEthernet1/0/1
[FW-GigabitEthernet1/0/1] ip address 192.168.1.254 24
[FW] interface GigabitEthernet1/0/2
[FW-GigabitEthernet1/0/2] ip address 192.168.2.254 24
[FW] interface GigabitEthernet1/0/3
[FW-GigabitEthernet1/0/3] ip address 100.1.1.1 24

注意:原文接口视图提示符写作 [FW-GigabitEthernet0/0/1]、[FW-GigabitEthernet0/0/2]、[FW-GigabitEthernet0/0/3],与所进入的接口 GigabitEthernet1/0/1~1/0/3 不一致,这里按 1/0/x 修正。另外,上一步把设备命名为 Firewall,原文后续命令的提示符有时写作 [FW]、有时写作 [Firewall],指的是同一台防火墙,下文保留原文写法。

(2)Internet 设备接口 IP 配置(用路由器模拟)

<Huawei> system-view
[Huawei] sysname Internet
[Internet] interface GigabitEthernet0/0/0
[Internet-GigabitEthernet0/0/0] ip address 100.1.1.2 24

(3)配置 PC1 和 Server 的 IP 参数

原图为 eNSP 中 PC1 和 Server 的“基础配置”界面截图,参数如下:

设备 IP 地址 子网掩码 网关 其他
PC1 192.168.1.1 255.255.255.0 192.168.1.254 IPv4 静态配置,MAC 54-89-98-CE-5C-66,DNS 0.0.0.0
Server 192.168.2.100 255.255.255.0 192.168.2.254 MAC 54-89-98-E6-0F-3F,域名服务器 0.0.0.0

第 3 步:把防火墙接口加入相应安全域

[FW] firewall zone trust
[FW-zone-trust] add interface GigabitEthernet1/0/1
[FW] firewall zone dmz
[FW-zone-dmz] add interface GigabitEthernet1/0/2
[FW] firewall zone untrust
[FW-zone-untrust] add interface GigabitEthernet1/0/3

第 4 步:配置安全策略,让 trust 区域(192.168.1.0/24)可以访问 Internet

[FW] security-policy //进入安全策略配置
[FW-policy-security] rule name trust_to_untrust
[FW-policy-security-rule-trust_to_untrust] source-zone trust
[FW-policy-security-rule-trust_to_untrust] source-address 192.168.1.0 mask 255.255.255.0
[FW-policy-security-rule-trust_to_untrust] destination-zone untrust
[FW-policy-security-rule-trust_to_untrust] action permit

注意:原文最后一行的提示符写作 [FW-policy-security-rule-policy_sec_deny1],与本规则名 trust_to_untrust 不一致,这里按 trust_to_untrust 修正。

第 5 步:NAT 配置

上述配置虽然放通了 192.168.1.0/24 访问 Internet 的流量,但是由于 192.168.1.0/24 是私有 IP 地址,不能直接进入公网,因此为了让内网用户能够访问公网,还必须配置 NAT。

(1)配置 NAT 地址池,开启端口转换。

[Firewall] nat address-group addressgroup1
[Firewall-address-group-addressgroup1] mode pat
[Firewall-address-group-addressgroup1] section 0 100.1.1.10 100.1.1.20
//地址池编号是0,包含可用公网IP地址从100.1.1.10到100.1.1.20,共11个地址
[Firewall-address-group-addressgroup1] quit
[Firewall]

(2)配置源 NAT 策略 1,实现私网指定网段访问 Internet 时自动进行源地址转换。

[FW] nat-policy
[FW-policy-nat] rule name policy_nat1
[FW-policy-nat-rule-policy_nat1] source-zone trust
[FW-policy-nat-rule-policy_nat1] destination-zone untrust
[FW-policy-nat-rule-policy_nat1] source-address 192.168.1.0 24
[FW-policy-nat-rule-policy_nat1] destination-address any
[FW-policy-nat-rule-policy_nat1] action source-nat address-group addressgroup1 //采用源地址NAT,把192.168.1.0/24转换为addressgroup1的公网地址

第 6 步:PC1 ping Internet,可以通。

PC> ping 100.1.1.2
Ping 100.1.1.2: 32 data bytes, Press Ctrl_C to break
From 100.1.1.2: bytes=32 seq=1 ttl=254 time=31 ms
From 100.1.1.2: bytes=32 seq=2 ttl=254 time=31 ms
From 100.1.1.2: bytes=32 seq=3 ttl=254 time=31 ms
From 100.1.1.2: bytes=32 seq=4 ttl=254 time=47 ms
From 100.1.1.2: bytes=32 seq=5 ttl=254 time=31 ms

防火墙上查看 session 表,已经有了访问项。

[Firewall] display firewall session table
2022-05-13 00:57:33.240
 Current Total Sessions : 5
 icmp  VPN: public --> public  192.168.1.1:63148[100.1.1.20:2054] --> 100.1.1.2:2048
 icmp  VPN: public --> public  192.168.1.1:62892[100.1.1.20:2053] --> 100.1.1.2:2048
 icmp  VPN: public --> public  192.168.1.1:63916[100.1.1.20:2057] --> 100.1.1.2:2048
 icmp  VPN: public --> public  192.168.1.1:63660[100.1.1.20:2056] --> 100.1.1.2:2048
 icmp  VPN: public --> public  192.168.1.1:63404[100.1.1.20:2055] --> 100.1.1.2:2048

第 7 步:PC1 ping Server,不通。

PC>ping 192.168.2.100
Ping 192.168.2.100: 32 data bytes, Press Ctrl_C to break
Request timeout!
Request timeout!
Request timeout!
Request timeout!
Request timeout!

第 8 步:防火墙上放行 trust 到 dmz 区域的流量。

[Firewall] security-policy
[Firewall-policy-security] rule name trust_to_dmz
[Firewall-policy-security-rule-trust_to_dmz] source-zone trust
[Firewall-policy-security-rule-trust_to_dmz] destination-zone dmz
[Firewall-policy-security-rule-trust_to_dmz] action permit

第 9 步:测试 PC1 到 Server 的连通性,可以正常通信。

PC> ping 192.168.2.100
Ping 192.168.2.100: 32 data bytes, Press Ctrl_C to break
From 192.168.2.100: bytes=32 seq=1 ttl=254 time=46 ms
From 192.168.2.100: bytes=32 seq=2 ttl=254 time=32 ms
From 192.168.2.100: bytes=32 seq=3 ttl=254 time=31 ms
From 192.168.2.100: bytes=32 seq=4 ttl=254 time=31 ms
From 192.168.2.100: bytes=32 seq=5 ttl=254 time=31 ms

第 10 步:配置服务器端口映射。

下面的命令,将内部 IP 地址 192.168.2.100 的 80 端口映射到了公网地址 100.1.1.100 的 80 端口,当公网用户访问 100.1.1.100 的 80 端口服务时,自动跳转到内部服务器 192.168.2.100 的 80 端口。

(1)配置安全策略,允许外部网络用户访问 DMZ 区域的 Web 服务器网段。

[FW] security-policy
[FW-policy-security] rule name untrust_to_dmz
[FW-policy-security-rule-untrust_to_dmz] source-zone untrust
[FW-policy-security-rule-untrust_to_dmz] destination-zone dmz
[FW-policy-security-rule-untrust_to_dmz] destination-address 192.168.2.0 24
[FW-policy-security-rule-untrust_to_dmz] action permit

注意:原文规则视图提示符写作 [FW-policy-security-rule-policy1],与所建规则名 untrust_to_dmz 不一致,这里按 untrust_to_dmz 修正。

(2)配置 NAT Server 功能,把内网 Web 服务映射到公网地址。

[FW] nat server policy_web protocol tcp global 100.1.1.100 80 inside 192.168.2.100 80

第 11 步:验证端口映射是否成功,Internet 可以正常访问内部 Web 服务器。

注意:原文此处步骤号写作“第 10 步”,与上一步重复,这里顺延为第 11 步。

(1)在路由器用户模式下,telnet Web 服务器公网,从路由器反馈不能看出是否访问成功。如果桥接到本地 PC,可以直接通过浏览器进行访问。

<Internet> telnet 100.1.1.100 80
  Press CTRL_] to quit telnet mode
  Trying 100.1.1.100 ...
  Connected to 100.1.1.100 ...

(2)查看防火墙 session 表,已经有了访问项。

注意:原文写作“已经有了方向项”,结合第 6 步“已经有了访问项”的说法,这里改为“访问项”。

[Firewall] display firewall session table
2022-05-12 00:58:52.780
 Current Total Sessions : 1
 http  VPN: public --> public  100.1.1.2:49587 --> 100.1.1.100:80[192.168.2.100:80]

(3)查看 Web 服务器的信息显示,Accepted 表示接受,即访问成功。原图为 Server 的“日志信息”界面截图,内容如下:

[2022-05-11 12:30:41]设备初始化完成。
[2022-05-11 12:32:58]设备启动
[2022-05-11 13:13:00]HttpServer:Please select a file directory as HTTP server root
[2022-05-12 08:58:40]HttpServer:Server: Accepted a socket client. fd = 1
[2022-05-12 08:58:40]HttpServer:Server: socket client data. fd = 1, len = 9
[2022-05-12 09:02:27]HttpServer:Server: socket client data. fd = 1, len = 69
[2022-05-12 09:02:27]HttpServer:Server: socket client data. fd = 1, len = 56
[2022-05-12 09:04:14]HttpServer:Server: a socket client closed. fd = 1
[2022-05-12 09:06:39]HttpServer:Server: Accepted a socket client. fd = 1
[2022-05-12 09:06:39]HttpServer:Server: socket client data. fd = 1, len = 9
在完整博客中阅读(目录、搜索、主题)