Oamc

防火墙上线配置:区域、策略与 NAT

本页目录

场景

一台防火墙替换掉原来的路由器做出口。和老路由器最大的区别:三个默认区域、默认拒绝、NAT 要和策略一起想。配完不通,九成是区域没划对或者策略没放行。

前置条件

  • 公网地址、网关、内网网段都确认好(例:公网 1.2.3.4/24,内网 192.168.10.0/24)
  • 知道要对外发布哪些服务(例:1.2.3.5:8080 → 192.168.10.100:80)
  • 串口或带外可用,改之前先把管理口划到独立区域
  • 确认设备是华为 USG 还是 H3C SecPath,两家命令差别不小

配置

华为 USG6000 系列:

system-view
sysname FW-Edge

# 接口地址
interface GigabitEthernet1/0/1
 ip address 1.2.3.4 255.255.255.0
 quit
interface GigabitEthernet1/0/2
 ip address 192.168.10.1 255.255.255.0
 quit

# 划区域(关键:不划区域,策略里根本选不到这个口)
firewall zone untrust
 add interface GigabitEthernet1/0/1
 quit
firewall zone trust
 add interface GigabitEthernet1/0/2
 quit

# 默认路由
ip route-static 0.0.0.0 0.0.0.0 1.2.3.1

# 安全策略:内网出去放行
security-policy
 rule name trust_to_untrust
  source-zone trust
  destination-zone untrust
  action permit
  quit
 quit

# 源 NAT:内网共享公网地址出去
nat-policy
 rule name snat_out
  source-zone trust
  destination-zone untrust
  action source-nat easy-ip
  quit
 quit

# 服务器映射:外面访问 1.2.3.5:8080 转到内网 80
nat server web_server protocol tcp global 1.2.3.5 8080 inside 192.168.10.100 80

# 从外网访问服务器要放行(NAT server 不自动放行策略)
security-policy
 rule name untrust_to_web
  source-zone untrust
  destination-zone trust
  destination-address 192.168.10.100 32
  service http
  action permit
  quit
 quit

save

H3C SecPath(V7 写法,细节以设备为准):

system-view
sysname FW-Edge

interface GigabitEthernet1/0/1
 ip address 1.2.3.4 24
 quit
interface GigabitEthernet1/0/2
 ip address 192.168.10.1 24
 quit

security-zone name Untrust
 import interface GigabitEthernet1/0/1
 quit
security-zone name Trust
 import interface GigabitEthernet1/0/2
 quit

ip route-static 0.0.0.0 0 1.2.3.1

security-policy ip
 rule name trust-untrust
  source-zone Trust
  destination-zone Untrust
  action pass
  quit
 quit

acl basic 2000
 rule 5 permit source 192.168.10.0 0.0.0.255
 quit
interface GigabitEthernet1/0/1
 nat outbound 2000
 quit

save force

验证

display zone                       # 接口都在正确的区域里
display security-policy rule all    # 策略顺序和动作
display nat-policy rule all         # NAT 规则
display firewall session table      # 有人访问时的会话
display ip routing-table            # 默认路由

从内网电脑依次测:ping 防火墙内网口 → ping 公网网关 → ping 223.5.5.5 → 打开网页。

再从外网测服务器映射:telnet 1.2.3.5 8080 或者浏览器访问。

回滚

undo nat server web_server
undo security-policy rule name trust_to_untrust
undo nat-policy rule name snat_out
undo ip route-static 0.0.0.0 0.0.0.0 1.2.3.1

最快的止损是把公网线插回老设备,防火墙留在旁边慢慢查。

坑

区域没划,策略里选不到接口

security-policy 里是按区域匹配的,不是按接口。接口没 add 进区域, 策略里就看不见它,现象是「策略明明放行了还是不通」。

  • NAT server 不自动放行。很多人只配了映射,忘了加 untrust→trust 的策略,外面就是连不上。
  • 默认策略是 deny。华为叫 default action deny,H3C 是 default deny。别为了省事改成 permit。
  • easy-ip 是复用出接口地址,公网地址多的话可以用地址池做一对一映射。
  • 改管理口区域之前,先确认还有另一条路能进去(串口/带外),不然改完就把自己关外面了。
  • 策略是有顺序的,从上往下匹配。新加的放行规则要放在拒绝规则上面。
  • 应用层协议(FTP、SIP)需要 ALG/ASPF,光放行端口不够。
  • 双机热备的两台配置必须一致,先配主再同步,见 防火墙双机热备(主备模式)。
  • 版本差异:USG6000 和 USG6600 的 nat-policy 写法基本一致,但更老的 USG5000 用 nat-policy 的早期语法,升级前先看设备文档。