2008年6月21日 星期六

CISCO Router&Switch 操作小技巧

前言:
這篇文章主要要表達就是CISCO Router和CISCO Switch 於指令操作的小技巧,方便網管朋友在管理CISCO設備的時候可以更容易由螢幕輸出的訊息中找到需要的關鍵資訊。
再看這篇文章的同時建議使用者可以順便複習一下CCNA課程中基本的指令。
若您要練習本篇所提及的技巧建議手上要有一顆CISCO Router(ISO 12.x)或是Dynamips模擬器。


CISCO Router&Switch 操作小技巧

發佈日期: 2008/06/13
版本:Version1
發佈網址:http://WWW.ITPro.tw
作者:呂堃楠 Email:Mark@mail.itpro.tw MSN : Mark.ITPro@hotmail.com
文章歡迎轉貼,轉貼時請註名出處。

前言:
這篇文章主要要表達就是CISCO Router和CISCO Switch 於指令操作的小技巧,方便網管朋友在管理CISCO設備的時候可以更容易由螢幕輸出的訊息中找到需要的關鍵資訊。
再看這篇文章的同時建議使用者可以順便複習一下CCNA課程中基本的指令。
若您要練習本篇所提及的技巧建議手上要有一顆CISCO Router(ISO 12.x)或是Dynamips模擬器。

在本文中堃哥將文章分成兩個部份:
第一部份是(一)基本命令講解。
第二部份是(二)技巧練習。

(一)基本命令講解1.1 Show Running-configure Current operating configuration 使用sh run顯示當前設定檔

輸出範例如下:
ITPro-Labs#sh run
Building configuration...
Current configuration : 2153 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
hostname ITPro-Labs
boot-start-marker
boot-end-marker
enable secret 5 $1$9hCY$O3nRYLpuYDXPaSLh95uTA.
aaa new-model
ip cef
ip sla monitor 10
type tcpConnect dest-ipaddr 1.1.1.2 dest-port 23 source-ipaddr 1.1.1.1 source-port 22392
frequency 3600
ip sla monitor schedule 10 life forever start-time now
frame-relay de-list 1 protocol ip
frame-relay de-list 1 protocol ip list 101
...(後省略)

上面顯示目前Router的設定,倘若要由眾多設定資訊中找到特定的關鍵可以使用下面參數

1.1.1 Show Running-configure 加上參數 | include [關鍵字]這句話的意思是有眾多顯示畫面的設定檔中找到我們輸入"特定"的關鍵字,例如我們要於上面的設定檔中找到
Router啟用sla則我們可以輸入 sh run | i sla 顯示結果如下
ip sla monitor 10
ip sla monitor schedule 10 life forever start-time now
系統會將Running-Configure中關於sla的關鍵字給找出來。
◎有使用Linux或是UnIX的朋友對上述的命令應該不陌生其實這就是管線的概念將螢幕輸出的資訊透過 | 管線然後使用 include其實也就是 unix 中的 grep 找到特定的資訊。

1.1.2 Show Running-configure 加上參數 | begin [關鍵字]
這句話的意思是找尋設定檔中將我們輸入的關鍵字"之後"的資訊都顯示出來,
簡單的說如果我們要找sla之後的訊息我們可以輸入sh run | b sla 顯示結果如下
ip sla monitor 10 ----sla之後均顯示出來
type tcpConnect dest-ipaddr 1.1.1.2 dest-port 23 source-ipaddr 1.1.1.1 source-port
22392 frequency 3600
ip sla monitor schedule 10 life forever start-time now
frame-relay de-list 1 protocol ip
frame-relay de-list 1 protocol ip list 101
比對前面的輸出範例會發現 sla關鍵字之前的訊息都消失了,系統只會顯示sla之後的訊息,這是一個相當有用的命令,例如我們要找尋Running-Configure中關於eigrp的資訊我們可以輸入,Sh run | b router eigrp 如此系統就只會顯示出eigrp之後的命令,可以很方便的找到關於EIGRP的訊息。

1.1.3 Show Running-configure 加上參數 | exclude [關鍵字]
這句話的意思是找尋設定檔中將我們輸入的關鍵字以外的資訊都顯示出來,
簡單的說如果我們"排除"sla所有的訊息我們可以輸入sh run | e sla 顯示結果如下

Building configuration...
Current configuration : 2153 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
hostname ITPro-Labs
boot-start-marker
boot-end-marker
enable secret 5 $1$9hCY$O3nRYLpuYDXPaSLh95uTA.
aaa new-model
ip cef
type tcpConnect dest-ipaddr 1.1.1.2 dest-port 23 source-ipaddr 1.1.1.1 source-port 22392
frame-relay de-list 1 protocol ip
frame-relay de-list 1 protocol ip
由上述範例輸出我們可以清楚看見關於 sla的命令已經被排除了。

1.4 Show Running-configure 加上參數 /[關鍵字] 符號這句話的意思是找尋設定檔中將我們輸入的關鍵字之後的資訊都顯示出來用法和 include類似差別在於當我們使用Show Running-configure在看設定檔時如果設定檔過長通常底下會出現 --More-- 的訊息要我們進行換頁此時我們可以輸入 /[關鍵字]
直接由 Show Running-configure找到我們要的資訊十分的方便大家可以練習一下使用/[關鍵字]和include [關鍵字]兩者之間有什麼不同。

重點整理
使用 參數 | include [關鍵字]
找尋螢幕中特定關鍵字

使用 參數 | begin [關鍵字]
顯示螢幕中特定關鍵字之後的字串

使用 參數 | exclude [關鍵字]
排除螢幕中特定關鍵字

使用 參數 /[關鍵字]
找尋螢幕中特定關鍵字

(二)技巧練習
熟悉上面技巧之後我們可以立刻將它用於我們實務環境中

Q2.1找出所有Router介面哪些介面是顯示 Down的 ??
A2.1我們可以輸入 ITPro-Labs#sh int | i down
顯示如下:
FastEthernet0/1 is administratively down, line protocol is down
Serial1/0 is up, line protocol is down
Serial1/1 is up, line protocol is down
LMI enq sent 175, LMI stat recvd 0, LMI upd recvd 0, DTE LMI down
0 carrier transitions DCD=down DSR=down DTR=up RTS=up CTS=down
Serial1/2 is administratively down, line protocol is down
LMI enq sent 0, LMI stat recvd 0, LMI upd recvd 0, DTE LMI down
0 carrier transitions DCD=down DSR=down DTR=up RTS=up CTS=down
Serial1/3 is administratively down, line protocol is down
1 carrier transitions DCD=down DSR=down DTR=up RTS=up CTS=down

可以將所有介面關於Down的資訊全部找出來。

Q2.2利用 sh ip route找出所以關於 5.5.5.0 的路由 ??
A2.2我們可以輸入 sh ip route | i 5.5.5.0
顯示如下:
ITPro-Labs#sh ip route | i 5.5.5.0
C 5.5.5.0 is directly connected, Loopback5

如此則可以再上萬條路由中輕鬆找到我們想知道的路由資訊。

結語!
上述簡單的小技巧可方便於眾多資訊中找到我們需要的,熟悉上述資訊對於我們日常Debug 網路有很大的幫助,希望上述資訊對正在學習CISCO相關知識的使用者有幫助,若對文章有任何問題請寫Email告訴我,謝謝。

沒有留言:

張貼留言