現代 Cisco 路由器 (ISR 1900/2900/3900/4000 系列) 推薦使用 Zone-Based Policy Firewall (ZBFW),CBAC (Context-Based Access Control) 已不建議新部署。本文整理兩者核心命令對照與 ZBFW 完整配置範例。
# 標準 ACL (1-99, 1300-1999) 僅匹配來源 IP
access-list 10 permit 192.168.1.0 0.0.0.255
# 擴展 ACL (100-199, 2000-2699) 匹配 5 元組
access-list 100 permit tcp 192.168.1.0 0.0.0.255 10.1.2.0 0.0.0.255 eq www
access-list 100 deny tcp 192.168.1.0 0.0.0.255 10.1.2.0 0.0.0.255 eq ftp
access-list 100 permit ip any any # 隱性 deny any any 需顯式允許其餘
ip inspect name MY_FW http
ip inspect name MY_FW ftp
ip inspect name MY_FW tcp
ip inspect name MY_FW udp
interface FastEthernet0/0
description WAN
ip inspect MY_FW out # 在外網介面出方向套用檢查
! 1. 定義區域
zone security INSIDE
zone security OUTSIDE
zone security DMZ
! 2. 定義區域對與策略地圖
class-map type inspect match-any INSIDE_TO_OUTSIDE_CLASS
match protocol http
match protocol https
match protocol dns
match protocol icmp
match protocol tcp
match protocol udp
policy-map type inspect INSIDE_TO_OUTSIDE_PMAP
class type inspect INSIDE_TO_OUTSIDE_CLASS
inspect
class class-default
drop
! 3. 套用區域對
zone-pair security INSIDE_TO_OUTSIDE source INSIDE destination OUTSIDE
service-policy type inspect INSIDE_TO_OUTSIDE_PMAP
zone-pair security OUTSIDE_TO_INSIDE source OUTSIDE destination INSIDE
service-policy type inspect OUTSIDE_TO_INSIDE_PMAP ! 通常只允許特定服務 (如 VPN、公開 Web)
! 4. 介面加入區域
interface GigabitEthernet0/0
description LAN
zone-member security INSIDE
interface GigabitEthernet0/1
description WAN
zone-member security OUTSIDE
! 5. 允許路由器自我管理流量 (Self Zone)
class-map type inspect match-any SELF_CLASS
match protocol tcp destination port 22 ! SSH
match protocol udp destination port 161 ! SNMP
policy-map type inspect SELF_PMAP
class type inspect SELF_CLASS
pass
zone-pair security TO_SELF source OUTSIDE destination self
service-policy type inspect SELF_PMAP
# 查看區域/區域對/策略
show zone security
show zone-pair security
show policy-map type inspect zone-pair
# 查看會話表 (連線追蹤)
show policy-firewall sessions
show policy-firewall stats
# 清除會話 / 統計
clear policy-firewall sessions
clear zone-pair security counters
| 特性 | CBAC | ZBFW |
|---|---|---|
| 架構 | 介面基礎 | 區域基礎 (Zone-Pair) |
| 預設行為 | 介面無檢查則放行 | 區域間無策略則拒絕 (預設安全) |
| 方向控制 | 單向 (in/out) | 雙向獨立策略 (source->destination) |
| Self Zone | 無 (靠 ACL 保護路由器) | 原生支援 (self zone 保護控制平面) |
| 應用層檢查 | 有限 (http, ftp, smtp 等) | 豐富 (含 IM, P2P, 自定義簽名) |
| 高可用 (HA) | 不支援狀態同步 | 支援 Box-to-Box / Zone-based HA 狀態同步 |
| IOS 版本需求 | 12.0(5)T+ | 12.4(6)T+ / 15.0+ 建議 |
結論: 新部署務必使用 ZBFW;現有 CBAC 專案規劃遷移至 ZBFW 以獲得預設拒絕、Self Zone 保護、HA 狀態同步等現代防火牆特性。