路由器是網路邊界核心,管理平面一旦失守,整個網路將面臨全盤皆輸。本文整理 20 條生產環境必備的安全強化指令,涵蓋存取控制、認證加密、服務精簡、日誌審計、時間同步、介面保護等六大面向。
username admin privilege 15 secret Str0ngP@ssw0rd!
secret 使用 MD5 雜湊,privilege 15 登入即進特權模式。
aaa new-model
aaa authentication login default local
line con 0
login authentication default
line aux 0
login authentication default
line vty 0 4
login authentication default
transport input ssh
統一認證策略,VTY 僅允許 SSH。
enable secret C1$coEn@ble!
MD5 加密,運行配置不顯示明文。
service password-encryption
將現有及未來所有明文密碼(line password、enable password、BGP/OSPF 金鑰等)以 Type 7 加密顯示(可逆,仍建議改用 secret)。
hostname Core-Router-TPE
便於日誌辨識、網管系統對應、故障排查溝通。
ip domain-name corp.example.com
no ip http server
no ip http secure-server
除非使用 Cisco Configuration Professional(CCP)等圖形化管理工具,否則關閉 Web 管理面降低攻擊面。
ip name-server 8.8.8.8 168.95.1.1
! 或
no ip domain-lookup
避免誤輸入指令觸發 DNS 查詢導致 CLI 凍結。
alias exec sr show running-config
alias exec si show ip route
alias exec sl show logging
輸入 sr 等同 show running-config。
clock timezone CST 8
clock summer-time CDT recurring
ntp server 162.159.200.123 prefer
ntp server 162.159.200.1
啟動時自動對時,確保日誌時間戳準確,利於事件關聯分析。
line con 0
logging synchronous
line aux 0
logging synchronous
line vty 0 4
logging synchronous
line vty 0 4
exec-timeout 30 0 ! 30 分鐘無操作斷線,0 秒
生產環境建議保留合理逾時,配合 AAA 記帳審計。
logging buffered 65536
logging host 192.168.1.50 transport udp port 514
logging trap notifications
logging source-interface Loopback0
本地緩衝 64KB,關鍵事件即時傳送至 Syslog 伺服器,採用 Loopback 介面為來源 IP 確保可達性。
interface GigabitEthernet0/3
shutdown
description UNUSED-DO-NOT-USE
interface GigabitEthernet0/0
no cdp enable
no lldp transmit
no lldp receive
access-list 199 permit tcp any host 192.168.1.1 eq 22
access-list 199 permit icmp any host 192.168.1.1
access-list 199 deny ip any any
class-map type control-plane match-any CPP-ALLOW
match access-group 199
policy-map type control-plane CPP-POLICY
class CPP-ALLOW
police 1000000 conform transmit exceed drop
class class-default
drop
control-plane
service-policy input CPP-POLICY
限制送往 CPU 的管理流量,防禦 DoS。
interface GigabitEthernet0/1
ip verify unicast source reachable-via rx allow-default
archive
path scp://backup-user:Pass@192.168.1.100/router-configs/$h
maximum 14
write-memory
time-period 1440
每次 write memory 自動推送備份,保留 14 版本,亦每日定時備份。
archive
log config
logging enable
logging size 500
notify syslog
hidekeys
記錄誰、何時、何指令變更,支援 configure replace 回滾。
show running-config | include (username|enable secret|aaa|logging|ntp|ip http|service password)show logging 確認 Syslog 送達。show ntp associations 確認 NTP 同步。show control-plane 檢視 CoPP 統計。安全非一次性專案,而是持續流程。將上述 20 條指令納入標準化部署範本、自動化合規稽核(如 Netmiko、Ansible、Cisco DNA Center),並定期滾動密碼、金鑰、審計日誌,才能構建韌性管理平面。