面對 P2P 下載佔用頻寬、惡意嘗試登錄等網絡安全挑戰,思科路由器提供了豐富的流量控制與 AAA 安全機制。本文系統梳理基於 ACL 的端口限速、NBAR 應用識別、CEF rate-limit 限速,以及登錄失敗嘗試記錄與防暴力破解的配置方法。
! 禁止下載
access-list 130 deny tcp any any range 6881 6890
access-list 130 deny tcp any range 6881 6890 any
ip access-group 130 in/out
! 僅限速不封鎖
access-list 130 remark bt
access-list 130 permit tcp any any range 6881 6890
access-list 130 permit tcp any range 6881 6890 any
rate-limit input access-group 130 712000 8000 8000 conform-action transmit exceed-action drop
rate-limit output access-group 130 712000 8000 8000 conform-action transmit exceed-action drop
缺陷: 現代 P2P 軟件支持動態端口、加密傳輸,單純封鎖固定端口效果極差,甚至誤傷正常業務(如 80/8080/2070 等常用端口)。
NBAR (Network-Based Application Recognition) 能夠識別第 4-7 層協議特徵,不依賴固定端口,可精準識別 BT、eDonkey、KaZaA 等 P2P 流量,甚至識別 HTTP URL、DNS、VoIP (H.323/SIP) 等應用層協議。
bittorrent.pdlm, emule.pdlm 等ip nbar pdlm flash:bittorrent.pdlmclass-map match-all bittorrent
match protocol bittorrent
!
policy-map bittorrent-policy
class bittorrent
drop
!
interface FastEthernet0/0
service-policy input bittorrent-policy
service-policy output bittorrent-policy
僅支持 CEF (Cisco Express Forwarding) 的設備可用。配置三步走:
! 1. 啟用 CEF
Router(config)# ip cef
! 2. 定義 ACL 匹配目標網段
Router(config)# access-list 111 permit ip 192.168.1.0 0.0.0.255 any
! 3. 接口應用 rate-limit (入方向限速 2Mbps)
Router(config)# interface FastEthernet 0/1
Router(config-if)# rate-limit input access-group 111 2000000 40000 60000 conform-action transmit exceed-action drop
參數詳解:
2000000 : CIR (承諾信息速率) 2Mbps40000 : Bc (承諾突發大小) 字節60000 : Be (超額突發大小) 字節conform-action transmit : 符合速率轉發exceed-action drop : 超速丟棄自 IOS 12.3 起,結合 AAA 可記錄失敗嘗試並觸發防護:
Router(config)# aaa new-model
Router(config)# aaa authentication attempts login 5 ! 最大嘗試 5 次 (默認 3)
Router(config)# aaa authentication login local-policy local ! 使用本地用戶庫
Router(config)# security authentication failure rate threshold-rate log
! threshold-rate: 每分鐘失敗閾值 (2-1024, 默認 10),觸發 syslog 並延遲 15 秒允許重試
關鍵約束: threshold-rate 必須 ≤ aaa authentication attempts login 設置值,否則連接會在記錄生成前被 AAA 斷開。