mcpField
C
configuring-pfsense-firewall-rules

configuring-pfsense-firewall-rules

github.com/mukul975安全35.2k140 次安装8 周前更新
代码仓库

关于 configuring-pfsense-firewall-rules

该技能面向网络管理员,介绍如何使用 pfSense 配置网络分区、防火墙访问规则和 NAT。内容还包括 VPN、日志监控、配置备份与规则测试。

主要功能

  1. 01配置接口与 VLAN 网络分区
  2. 02创建分区访问控制规则
  3. 03设置 NAT 端口转发
  4. 04启用日志、备份和规则测试

适用场景

  1. 01隔离办公、访客和 IoT 网络
  2. 02限制不同 VLAN 间的流量
  3. 03将内部服务通过 NAT 对外提供

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill configuring-pfsense-firewall-rules

安装后在 Claude Code 中输入/configuring-pfsense-firewall-rules确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

配置 pfSense 防火墙规则

何时使用

  • 部署边界防火墙或内部防火墙,以对网络区域(DMZ、内部、访客、IoT)进行分段和保护
  • 创建精细的访问控制规则,以限制 VLAN 和网段之间的流量
  • 配置 NAT 规则,将端口转发到暴露在互联网上的内部服务
  • 使用 IPsec 或 OpenVPN 设置站点到站点或远程访问 VPN 隧道
  • 针对服务质量需求实施流量整形和带宽管理

请勿使用 作为单个系统上基于主机的防火墙的替代品,在没有专用硬件加速的情况下用于 SSL/TLS 深度数据包检测,或作为唯一的安全控制措施而不辅以 IDS/IPS。

先决条件

  • 在具有至少两个网络接口的专用硬件或虚拟机上安装 pfSense 2.7+
  • 能访问 pfSense WebConfigurator(默认:https://192.168.1.1)
  • 显示所有接口、VLAN 和所需流量走向的网络拓扑图
  • 为每个网络区域规划好 DNS 和 DHCP 配置
  • 了解 TCP/IP、NAT 和有状态防火墙概念

工作流

第 1 步:配置网络接口和 VLAN

访问 pfSense WebConfigurator 并定义接口:

Navigate: Interfaces > Assignments

WAN Interface (igb0):
  - Type: DHCP or Static IP from ISP
  - Block private networks: Enabled
  - Block bogon networks: Enabled

LAN Interface (igb1):
  - IPv4: 10.10.1.1/24
  - Description: CORPORATE_LAN

Create VLANs:
  Navigate: Interfaces > VLANs > Add
  - VLAN 10 on igb1: DMZ (10.10.10.1/24)
  - VLAN 20 on igb1: SERVERS (10.10.20.1/24)
  - VLAN 30 on igb1: GUEST (10.10.30.1/24)
  - VLAN 40 on igb1: IOT (10.10.40.1/24)

Assign VLANs:
  Navigate: Interfaces > Assignments > Add each VLAN
  Enable each interface and assign the gateway IP
第 2 步:为每个区域配置 DHCP 和 DNS
Navigate: Services > DHCP Server

CORPORATE_LAN (10.10.1.0/24):
  Range: 10.10.1.100 - 10.10.1.200
  DNS: 10.10.20.10 (internal DNS server)
  Gateway: 10.10.1.1

DMZ (10.10.10.0/24):
  Range: 10.10.10.100 - 10.10.10.200
  DNS: 10.10.20.10
  Gateway: 10.10.10.1

GUEST (10.10.30.0/24):
  Range: 10.10.30.100 - 10.10.30.200
  DNS: 1.1.1.1, 8.8.8.8 (public DNS only)
  Gateway: 10.10.30.1

Navigate: Services > DNS Resolver
  Enable DNS Resolver on all interfaces except GUEST
  Enable DNSSEC
  Configure forwarding to upstream DNS servers
第 3 步:创建防火墙规则别名
Navigate: Firewall > Aliases

RFC1918_Networks:
  Type: Network
  Values: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16

WebPorts:
  Type: Port
  Values: 80, 443

ManagementPorts:
  Type: Port
  Values: 22, 3389, 5900

CriticalServers:
  Type: Host
  Values: 10.10.20.10, 10.10.20.11, 10.10.20.12

BlockedCountries:
  Type: URL Table
  URL: https://www.ipdeny.com/ipblocks/data/aggregated/cn-aggregated.zone
  Update: 24 hours
第 4 步:按区域实施防火墙规则
Navigate: Firewall > Rules

=== WAN Rules ===
# Block all inbound by default (implicit deny)
# Allow established/related traffic (automatic in pfSense stateful mode)

# Allow inbound to DMZ web server (via NAT)
Action: Pass | Interface: WAN | Protocol: TCP
Source: any | Destination: WAN Address | Port: 80, 443
Description: Allow HTTP/HTTPS to DMZ web server

=== LAN Rules ===
# Allow LAN to access internal servers
Action: Pass | Interface: LAN | Protocol: TCP
Source: LAN net | Destination: SERVERS net | Port: WebPorts, 3306, 5432
Description: Allow LAN to internal web and database servers

# Allow LAN to internet
Action: Pass | Interface: LAN | Protocol: any
Source: LAN net | Destination: ! RFC1918_Networks
Description: Allow LAN to internet (block inter-VLAN via RFC1918 exclusion)

# Block LAN to IoT (explicit deny before implicit allow)
Action: Block | Interface: LAN | Protocol: any
Source: LAN net | Destination: IOT net
Description: Block direct LAN to IoT communication

=== DMZ Rules ===
# Allow DMZ web servers to query internal DNS
Action: Pass | Interface: DMZ | Protocol: TCP/UDP
Source: DMZ net | Destination: 10.10.20.10 | Port: 53
Description: Allow DMZ DNS queries to internal resolver

# Allow DMZ to internet for updates only
Action: Pass | Interface: DMZ | Protocol: TCP
Source: DMZ net | Destination: any | Port: 80, 443
Description: Allow DMZ outbound HTTP/HTTPS for updates

# Block all other DMZ traffic
Action: Block | Interface: DMZ | Protocol: any
Source: DMZ net | Destination: any
Description: Default deny for DMZ

=== GUEST Rules ===
# Allow guest to internet only (DNS and web)
Action: Pass | Interface: GUEST | Protocol: TCP/UDP
Source: GUEST net | Destination: ! RFC1918_Networks | Port: 53, 80, 443
Description: Allow guest internet access only

# Block all guest to internal
Action: Block | Interface: GUEST | Protocol: any
Source: GUEST net | Destination: RFC1918_Networks
Description: Block guest access to all internal networks

=== IOT Rules ===
# Allow IoT to specific cloud endpoints
Action: Pass | Interface: IOT | Protocol: TCP
Source: IOT net | Destination: ! RFC1918_Networks | Port: 443, 8883
Description: Allow IoT HTTPS and MQTT to cloud

# Block IoT inter-device communication
Action: Block | Interface: IOT | Protocol: any
Source: IOT net | Destination: IOT net
Description: Prevent IoT lateral movement

# Block IoT to all internal networks
Action: Block | Interface: IOT | Protocol: any
Source: IOT net | Destination: RFC1918_Networks
Description: Block IoT access to internal
第 5 步:配置 NAT 规则
Navigate: Firewall > NAT > Port Forward

# Web server in DMZ
Interface: WAN | Protocol: TCP
Destination: WAN address | Port: 443
Redirect target IP: 10.10.10.50 | Port: 443
NAT Reflection: Enable
Description: HTTPS to DMZ web server

# SSH jump host (non-standard port)
Interface: WAN | Protocol: TCP
Destination: WAN address | Port: 2222
Redirect target IP: 10.10.20.11 | Port: 22
Description: SSH to internal jump host via port 2222

Navigate: Firewall > NAT > Outbound
Mode: Hybrid Outbound NAT
# Add rule for DMZ servers to use a dedicated public IP
Interface: WAN | Source: 10.10.10.0/24
Translation Address: <dedicated_public_ip>
Description: DMZ outbound NAT via dedicated IP
第 6 步:启用日志记录和监控
Navigate: Status > System Logs > Settings
  Remote Logging: Enable
  Remote log servers: 10.10.20.15:514 (Syslog/SIEM)
  Log firewall default blocks: Enabled

Navigate: Firewall > Rules
  Enable logging on critical rules:
  - All BLOCK rules
  - WAN inbound PASS rules
  - Inter-VLAN PASS rules

Navigate: Diagnostics > pfTop
  Monitor real-time connection states and bandwidth usage

Install pfBlockerNG package:
  Navigate: System > Package Manager > Available Packages
  Install pfBlockerNG-devel
  Configure IP blocklists (Spamhaus DROP, Emerging Threats)
  Configure DNSBL for malware domain blocking
第 7 步:备份并测试配置
# Export configuration backup
Navigate: Diagnostics > Backup & Restore
Download XML configuration file

# Test rules from each zone
# From LAN:
curl -I https://10.10.20.10  # Should succeed (LAN to SERVERS)
curl -I https://10.10.40.5   # Should fail (LAN to IOT blocked)

# From GUEST:
curl -I https://www.google.com  # Should succeed (internet)
curl -I https://10.10.20.10     # Should fail (guest to internal blocked)

# From DMZ:
nslookup google.com 10.10.20.10  # Should succeed (DNS allowed)
ssh 10.10.1.50                    # Should fail (DMZ to LAN blocked)

# Verify logging
Navigate: Status > System Logs > Firewall
Check that blocked and passed traffic is logging correctly

# Schedule automated config backups
Navigate: Diagnostics > AutoConfigBackup
Enable automatic backups to Netgate cloud or local storage

关键概念

术语定义
有状态防火墙跟踪网络连接状态的防火墙,可自动允许已建立会话的返回流量,无需显式规则
别名pfSense 中 IP 地址、网络或端口的命名分组,可简化规则管理并提高可读性
NAT(网络地址转换)在内部网络和外部网络之间转换 IP 地址,包括用于从外部访问内部服务的端口转发
浮动规则可同时应用于多个接口的 pfSense 规则,在处理各接口规则之前处理
pfBlockerNGpfSense 软件包,集成 IP 信誉阻止列表和基于 DNS 的阻止列表,实现自动化威胁阻止
规则处理顺序pfSense 在每个接口选项卡中自上而下评估规则;首个匹配项生效,未匹配的流量默认被阻止

工具与系统

  • pfSense 2.7+:基于 FreeBSD 的开源防火墙和路由平台,具有基于 Web 的管理和丰富的软件包生态系统
  • pfBlockerNG:IP 和 DNS 阻止列表软件包,用于集成自动化威胁情报
  • Snort/Suricata 软件包:以 pfSense 软件包形式提供的 IDS/IPS 集成,用于内联流量检测
  • OpenVPN/IPsec:内置 VPN 实现,用于站点到站点和远程访问连接
  • Netgate AutoConfigBackup:基于云的配置备份服务,用于 pfSense 灾难恢复

常见场景

场景:使用 pfSense 对小型企业网络进行网段划分

背景:一家医疗机构需要对其网络进行网段划分,以满足 HIPAA 要求。他们有一条互联网连接、一台电子健康记录(EHR)服务器、员工工作站、一个访客 WiFi 网络,以及医疗 IoT 设备(生命体征监测仪、影像设备)。预算限制要求采用开源解决方案。

方法:

  1. 在 Netgate 4100 设备上部署 pfSense,配备四个物理接口(WAN、LAN、DMZ、MGMT)
  2. 为员工(VLAN 10)、EHR 服务器(VLAN 20)、访客 WiFi(VLAN 30)和医疗设备(VLAN 40)创建 VLAN
  3. 配置严格规则:员工 VLAN 仅可通过 HTTPS 访问 EHR 服务器;医疗设备仅可在特定端口上与 EHR 服务器通信;访客 WiFi 仅能访问互联网,不可进行任何内部路由
  4. 启用 pfBlockerNG,并配置医疗行业专用威胁情报源和恶意域名拦截
  5. 配置出站 NAT,防止内部 IP 地址泄露到互联网
  6. 启用全面日志记录,并通过 syslog 将所有防火墙日志转发到 SIEM
  7. 设置自动化配置备份,并记录规则库以满足审计合规要求

陷阱:

  • 创建过于宽松的规则(“allow any any”),而不是基于特定端口的规则
  • 忘记规则处理顺序——将宽泛的 PASS 规则放在特定的 BLOCK 规则之上
  • 未在关键规则上启用日志记录,导致事件调查无法进行
  • 允许 IoT 设备不受限制地访问互联网,形成潜在的数据外泄路径

输出格式

## pfSense Firewall Configuration Report

**Device**: pfSense 2.7.2 on Netgate 4100
**Interfaces**: WAN (igb0), LAN (igb1), DMZ (igb2), MGMT (igb3)
**VLANs**: 4 configured (Staff, Servers, Guest, IoT)
**Total Rules**: 28 active rules across all interfaces

### Rule Summary by Interface

| Interface | Pass Rules | Block Rules | Logging Enabled |
|-----------|-----------|-------------|-----------------|
| WAN | 2 | 1 (default) | Yes |
| LAN | 4 | 2 | Yes (blocks) |
| DMZ | 3 | 1 (default) | Yes |
| GUEST | 1 | 2 | Yes |
| IOT | 1 | 3 | Yes |

### Security Controls
- pfBlockerNG: 12 IP blocklists + DNSBL enabled
- Snort IDS: Running on WAN and LAN interfaces
- VPN: OpenVPN remote access configured with MFA
- Logging: All traffic forwarded to SIEM (10.10.20.15)

评论

支持 Markdown