預設 Telnet 埠號 23 為眾所周知,自動化掃描腳本、暴力破解工具首選目標。雖 SSH 才是根本解決,但在舊版 IOS 或受限環境下,修改埠號結合 ACL 可顯著降低攻擊面。
Router(config)# line vty 0 4
Router(config-line)# password TelnetP@ssw0rd!
Router(config-line)# login
Router(config-line)# exit
0 4 為 5 條 VTY(0-4),部分機型支援 0-15 或 0-99,以 show line 確認。
Router(config)# line vty 0 4
Router(config-line)# rotary 2
Router(config-line)# exit
rotary N:N 為 1-100 整數。rotary 2 → 埠號 3002。Router(config)# access-list 101 deny tcp any any eq 23 log
Router(config)# access-list 101 permit ip any any
! 若限制管理 IP 段(例:192.168.10.0/24):
Router(config)# access-list 101 permit ip 192.168.10.0 0.0.0.255 any
Router(config)# access-list 101 deny ip any any log
log 關鍵字記錄匹配封包,便於審計。
Router(config)# line vty 0 4
Router(config-line)# access-class 101 in
Router(config-line)# end
Router# write memory
# 客戶端測試新埠號
telnet 192.168.1.1 3002
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
User Access Verification
Password: TelnetP@ssw0rd!
Router>
# 驗證埠 23 已被拒絕
telnet 192.168.1.1 23
Trying 192.168.1.1...
telnet: connect to address 192.168.1.1: Connection refused
! 或超時(視 ACL 部署位置)
line vty 0 4 下 transport input ssh,徹底移除 Telnet 支援。logging trap 將 ACL log 送至 Syslog,配合 SIEM 告警。show control-plane host open-ports 檢視)。in 方向,僅過濾進入路由器的管理流量,不影響路由器主動發起的連線。access-class 僅支援標準/擴展 ACL(1-199, 1300-2699),不支援命名 ACL(舊版 IOS),新版 IOS 15+ 支援命名 ACL。修改 Telnet 埠號結合 ACL 封鎖 23 埠、限制來源 IP,屬於「安全模糊化」手段,能有效阻擋自動化掃描與腳本小子攻擊。但務必以部署 SSH、AAA 集中認證、CoPP、管理平面隔離(VRF/管理 VLAN)為根本防禦體系。