在 Cisco 路由器上啟用 NAT 僅需三步:定義內部網段 ACL、指定 Inside/Outside 介面、套用 NAT 規則。本文提供「動態 PAT (Overload)」與「靜態 Port Mapping」兩種最常用模式的極簡指令集,適合快速部署與備查。
! 1. 定義內部允許 NAT 的網段
access-list 1 permit 192.168.1.0 0.0.0.255
! 2. 指定 Inside/Outside 介面
interface FastEthernet0/0
ip nat inside
!
interface FastEthernet0/1
ip nat outside
!
! 3. 套用 PAT 規則 (Overload 關鍵字實現多對一)
ip nat inside source list 1 interface FastEthernet0/1 overload
! 將公網 IP 202.99.111.2:2121 映射至內部 192.168.0.101:21 (FTP)
ip nat inside source static tcp 192.168.0.101 21 202.99.111.2 2121 extendable
extendable:允許同一 Inside Local 映射多個 Outside Global (多公網 IP 發布同一伺服器)。tcp、udp、icmp。ip nat inside:連接內部私網 (LAN)。ip nat outside:連接外部公網 (WAN/ISP)。show ip nat translations ! 顯示所有 NAT 表項 (Inside/Outside Local/Global)
show ip nat statistics ! 統計轉換次數、介面、位址池使用率
clear ip nat translation * ! 清除動態表項 (謹慎,會中斷現有連線)
debug ip nat ! 即時除錯 (高 CPU,僅限維護窗口)
0.0.0.255 而非 255.255.255.0)。overload 導致一對一 NAT,公網 IP 瞬間耗盡。