cisco IOS cookbook 中文精簡版 2-23 路由器管理

 2.1.  創建命令別名
提問 爲常用的命令創建簡潔的別名
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#alias exec rt show ip route
Router1(config)#alias exec on show ip ospf neighbor
Router1(config)#end
Router1#
註釋 show aliases命令可以輸出當前配置的別名

2.2.  管理路由器ARP緩存
提問 修改ARP表條目超時時長
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#interface Ethernet0
Router1(config-if)#arp timeout 600
Router1(config-if)#end
Router1#
註釋 缺省情況爲4個小時,同時思科沒有提供命令能單獨的清除某個ARP緩存,只能通過clear arp 命令來清除整個ARP表

2.3.  路由器Buffer調整
提問 手動調整路由器Buffer分配來使其工作的更高效
回答 路由器維護兩個Buffer池,public buffers和interface buffers
調整public buffers
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#buffers big initial 100
Router1(config)#buffers big max-free 200
Router1(config)#buffers big min-free 50
Router1(config)#buffers big permanent 50
Router1(config)#end
Router1#
調整interface buffers
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#buffers Ethernet0 initial 200
Router1(config)#buffers Ethernet0 max-free 300
Router1(config)#buffers Ethernet0 min-free 50
Router1(config)#buffers Ethernet0 permanent 50
Router1(config)#end
Router1#
註釋 一般不建議修改,如果修改,建議首先使用show buffers命令來查看當前buffer使用情況,調整完以後建議使用show memory來查看內存使用情況

2.4.  自動調整路由器Buffer
提問 希望路由器根據自己的情況自動進行buffer分配調整
回答
Router#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#buffers tune automatic
Router(config)#end                    
Router#
註釋 此命令引自IOS 12.3(14)T,使用show buffers tune命令來查看自動調整情況

2.5.  使用CDP協議
提問 希望獲得相連網絡設備的信息
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#cdp run
Router1(config)#interface Serial0/0
Router1(config-if)#cdp enable
Router1(config-if)#exit
Router1(config)#interface FastEthernet0/0
Router1(config-if)#no cdp enable
Router1(config-if)#exit
Router1(config)#interface FastEthernet1/0
Router1(config-if)#cdp enable
Router1(config-if)#end
Router1#
註釋 CDP(Cisco Discovery Protocol)是思科專有的協議,用於發現相連的思科設備,幫助瞭解網絡拓樸,缺省是啓用的,使用show cdp neighbor detail 命令可以查看相連設備的詳細信息

2.6.  禁止CDP協議
提問 爲了安全期間不想讓鄰近設備發現自己設備的信息
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#cdp run
Router1(config)#interface FastEthernet0/0
Router1(config-if)#no cdp enable
Router1(config-if)#end
Router1#

註釋 爲了安全期間可以在邊界設備上禁止CDP
2.7.  小服務的開啓
提問 開啓或者禁用一些類似finger的小服務
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#service tcp-small-servers   (no service tcp-small-servers
Router1(config)#service udp-small-servers    (no sercie udp-small-servers)
Router1(config)#end
Router1#
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#ip finger  (no ip finger)
Router1#
註釋 tcp和udp的小服務指開啓路由器的echo,discard,daytime和chargen服務,爲了安全期間都建議將其關閉

2.8.  啓用路由器HTTP訪問
提問 通過瀏覽器來配置和管理路由器
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#access-list 75 permit 172.25.1.1
Router1(config)#access-list 75 deny any
Router1(config)#ip http server
Router1(config)#ip http access-class 75
Router1(config)#end
Router1#

註釋 由於IOS 12.1(5)之前存在HTTP訪問的高危漏洞,所以如果你的IOS版本小於此版本建議不要開啓此服務

2.9.  啓用路由器安全HTTPS訪問
提問 通過加密的訪問HTTP訪問路由器
回答
Core#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Core(config)#ip http secure-server
Core(config)#end
Core#

註釋 IOS 12.2(14)S之後引入此特性,建議先用no ip http server命令關閉非加密的HTTP訪問,然後開啓安全的訪問,同時可以使用ip http secure-port  8080
命令來更改訪問端口

2.10.  使用靜態主機名映射
提問 在路由器上配置靜態的主機映射表,從而使用主機名而不是IP地址來訪問設備
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#ip host freebsd 172.25.1.1
Router1(config)#ip host router2 10.1.1.1 172.22.1.4
Router1(config)#end
Router1#
註釋 可以對一個主機名映射很多IP地址來提供冗餘訪問,show hosts命令來驗證

2.11.  啓用DNS服務
提問 路由器使用DNS服務器來解析主機名
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#ip domain-lookup
Router1(config)#ip domain-name oreilly.com
Router1(config)#ip name-server 172.25.1.1
Router1(config)#ip name-server 10.1.20.5  
Router1(config)#end
Router1#

註釋 從IOS 12.2開始,思科使用了ip domain lookup.來代替ip domain-lookup 類似的ip domain-nameip domain name代替

2.12.  禁用域名解析
提問 禁用域名解析,防止路由器自動對打錯的命令的進行DNS查詢
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#no ip domain-lookup
Router1(config)#end
Router1#
如果需要啓用DNS查詢主機名,但是又爲了避免打錯命令查詢的情況可以使用如下的變通方法
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line vty 0 4
Router1(config-line)#transport preferred none
Router1(config-line)#end
Router1#
註釋 對後一個命令的稍微解釋一下,正常情況下都知道可以直接使用主機名回車路由器會認爲時telnet 到此設備,可以省略掉telnet的命令,原因是因爲transport preferred缺省是telnet,如果配置爲none就必須使用telnet命令來進行設備登錄,命令打錯也不會出現地址解析的問題了。
2.13.  配置路由器特定時間重啓
提問 需要路由器在特定時間自動重啓
回答
Router1#reload in 20
Reload scheduled for 11:33:53 EST Sat Feb 1 2003 (in 20 minutes)
Proceed with reload? [confirm]
Router1#
Router1#reload at 14:00 Feb 2
Reload scheduled for 14:00:00 EST Sun Feb 2 2003 (in 26 hours and 44 minutes)
Proceed with reload? [confirm]
Router1#
註釋 很有用的命令,當你在對路由器配置進行修改前可以先行輸入此命令,然後進行修改但是不保存配置,這樣可以防止把自己鎖在路由器之外。可以使用reload cancel命令來取消定時重啓
2.14.  定時執行配置命令
提問 週期性的定時執行某個命令
回答
Router#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#kron policy-list NEOSHI
Router(config-kron-policy)#cli write memory
Router(config-kron-policy)#exit
Router(config)#kron occurrence  DAILYat5 at  17:00 recurring
Router(config-kron-occurrence)#policy-list NEOSHI
Router(config-kron-occurrence)#end
Router#

註釋 從IOS12.3(1)開始引入了這個類似Unix Cron的特性,不過也有一些缺點,只能運行EXEC模式下的命令,不能運行配置模式下的命令,同時輸入的命令不能是交互性的,比如不能輸入copy running-config startup-config來保存配置,因爲是需要確認的,必須使用write memory來代替
2.15.  顯示路由器CPU利用率的歷史數據
提問 顯示歷史的路由器CPU利用率
回答
Router# show processes cpu history
Router   03:48:18 PM Monday Apr 17 2006 EDT
                                                              
                                         555559999999999999999
    5                                    444449999999999999999
100                                           ******************
90                                           ******************
80                                           ******************
70                                           ******************
60                                           ******************
50                                      ***********************
40                                      ***********************
30                                      ***********************
20                                      ***********************
10 *                                    ***********************
   0....5....1....1....2....2....3....3....4....4....5....5....
             0    5    0    5    0    5    0    5    0    5   
               CPU% per second (last 60 seconds)
                                                              
    99   1                                                9999
    99   1                                     4          9999
100 **                                                    ***#*#
90 **                                                    **##*#
80 #*                                                    *###*#
70 #*                                                    *###*#
60 #*                                                    *###*#
50 #*                                                    *#####
40 #*                                                    *#####
30 #*                                                    ######
20 ##                                                    ######
10 ##   *                                                ######
   0....5....1....1....2....2....3....3....4....4....5....5....
             0    5    0    5    0    5    0    5    0    5   
               CPU% per minute (last 60 minutes)
              * = maximum CPU%   # = average CPU%
  ……………………………….(由於顯示問題省去此圖).
                   CPU% per hour (last 72 hours)
                  * = maximum CPU%   # = average CPU%

註釋 從IOS12.2(2)T以後思科爲show process cpu命令增加了history的選項,這樣可以看到最長3天的CPU利用率,而以前最多可以看到5分鐘的。輸出圖很不容易看懂,簡單的說最左邊是最新的數據,然後歷史數據會向右移,在每分鐘和每小時的會有峯值和平均值,峯值爲現在每列的上端,不過是豎着排列的。
2.16.  生成意外導出文件(Exception Dump Files)
提問 在路由器發生意外當機的情況下生成導出文件發給TAC進行處理
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#ip ftp source-interface Loopback0
Router1(config)#ip ftp username ijbrown
Router1(config)#ip ftp password ijpassword
Router1(config)#exception protocol ftp
Router1(config)#exception region-size 65536
Router1(config)#exception dump 172.25.1.3
Router1(config)#end
Router1#

註釋 缺省情況下路由器會使用tftp命令進行傳送,不過TFTP有16M的限制所以建議換爲FTP協議。另外爲了防止當機導致文件不能生成,所以使用了exception region-size 65536 來提前保留部分內存給該命令使用。可以先使用write core命令來提前實驗下生成此文件
2.17.  生成接口信息報告
2.18.  生成路由表報告
2.19.  生成ARP表報告
2.20.  生成主機表報告
以上都是使用perl腳本來進行命令輸出的彙總操作,腳本略去

 

原文地址:

http://bbs.51cto.com/thread-306796-1-1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章