Chapter4 Introduction to the Cisco IOS
The Cisco Router User Interface
Cisco Internetwork Operation System(IOS)是 Cisco 的routers和 switches 的核心
Cisco Router IOS
IOS的一些功能:
1.運載網絡協定和功能
2.對産生高速流量的裝置進行連接配接
3.增加網絡安全性
4.提供網絡的可擴充性來簡易化網絡的增長和備援問題
5.可靠的連接配接網絡資源
你可以通過以下方式進入 IOS:
1.通過 router的 console 口,用于本地
2.通過 modem連接配接 auxiliary(Aux)口,用于遠端
3.通過 VTY線路來 telnet
Bringing Up a Router
當啟動 1 個 router的時候,大緻将分為以下幾個階段:
1.開機自檢(power-on self-test,POST)
2.如果 1 正常, 如果 IOS 存在的話,将從它的閃存(flash memory)查找和加載 IOS 到 RAM 中
(2500 系列不加載 RAM 中,直接從閃存中運作).閃存是 1 種電子可擦除隻讀存儲器
(electronically erasable programmable read-only memory,EEPROM)
3.如果1和2正常,接下來它将在非易失性RAM(NVRAM)中查找啟動配置檔案startup-config,
假如沒有找到任何啟動配置檔案,router将進入到setup 模式
Setup Mode
setup模式可以對router進行些配置,但是我們不推薦使用這個方法對router進行配置.它分為
2 種模式:
1.Basic Management
2.Extended Management
在 setup 模式中,[]代表預設設定,你可以使用 Ctrl+C 随時退出 setup 模式
Command-Line Interface
當問你是否進入 setup 模式,選擇 no,即進入指令行模式
Logging into the Router
從使用者模式(user mode)進入到特權模式(exec mode),注意提示符的變化:
Router>enable
Router#
從特權模式退出到使用者模式:
Router#disable
Router>
退出 router指令行:在使用者模式和特權模式下輸入 logout,如下:
Router#logout
Router con0 is now available
Press RETURN to get started
Overview of Router Modes
配置router,需要進入到1個叫做配置模式的模式,在特權模式下輸入configure terminal進入全
局配置模式(global configuration mode),在這之下輸入的指令叫做全局指令,一旦輸入,将對整
個 router産生影響.如下,注意提示符的變化:
Router#config
Configruation from terminal,memory or network
[terminal]?(press Enter)
Router(config)#
參數 terminal,memory和 network 的差別:
1.configure terminal:配置 router 的 running-config,所謂 running-config 即為目前運作在動态
RAM(DRAM)的配置檔案
2.configure memory: 配置 router 的 startup-config,所謂 startup-config 即為存儲在 router 的
NVRAM 裡的配置檔案
3.configure network:配置存儲在 TFTP主機的配置檔案
Interfaces
在全局配置模式下切換 router接口,輸入 interface指令,?用于提示可選參數,為如下:
Router(config)#interface ?
(略)
Serial Serial
前半部分為參數,後半部分為描述,接着輸入 serial 0,進入 router接口配置模式,如下:
Router(config)#interface serial 0
Router(config-if)#
Subinterfaces
在 router 的某個接口劃分邏輯子接口(subinterface),輸入指令進入子接口模式,如下,注意提示
符:
Router(config)#interface fa0/0.?
<0-4294967295> FastEhernet interface number
Router(config)#interface fa0/0.1
Router(config-subif)#
Line Command
進入線路配置模式,注意提示符,如下:
Router(config)#line console 0
Router(config-line)#
Routing Protocol Configurations
給 router配置路由協定,比如 RIP,注意提示符,如下:
Router(config)#router rip
Router(config-router)#
從全局模式退出到特權模式可以使用快捷鍵 Ctrl+Z
Editing and Help Features
一些特寫:
1.在指令行下輸入?,将得到該模式下可以使用的指令清單以及其描述
2.假如你不确定1個指令是如何寫的,比如你隻記得是字母c開頭,你可以輸入c加1個?,将得
到該模式下可以使用的所有指令:
Router#c?
clear clock configuration connect copy
Router#clock ?
set Set the time and date
3.假如你輸入的指令不完整,将得到 1個錯誤提示:Imcomplete command,這樣有助于分析指令
哪出錯了
4.router 支援指令縮寫,比如 show 可以縮寫為 sh,sho,但是假如你像如下那樣輸入了不完整的
縮寫,将得到錯誤提示:Ambiguous command
Router#sh te
% Ambiguous command: sh te
Router#sh te?
tech-support template terminal
一切其他的快捷鍵:
1.Ctrl+A:把光标快速移動到整行的最開始
2.Ctrl+E:把光标快速移動到整行的最末尾
3.Esc+B:後退 1 個單詞 4.Ctrl+B:後退 1 個字元
5.Esc+F:前進1 個單詞
6.Ctrl+F:前進 1 個字元
7.Ctrl+D:删除單獨 1 個字元
8.Backspace:删除單獨 1個字元
9.Ctrl+R:重新顯示 1 行
10.Ctrl+U:擦除 1 整行
11.Ctrl+W:删除 1 個單詞
12.Tab:自動補齊指令
13.Up arrow或者 Ctrl+P:顯示之前最後輸入過的指令
14.Down arrow 或者 Ctrl+N:顯示之前剛剛輸入過的指令
其他的一些關于曆史的指令:
1.show history:顯示最後輸入的 10 條指令,預設是 10條,可以修改該值
2.terminal history size:修改顯示最後輸入過的的指令的數量,預設是 10 條,最大是 256 條
3.show terminal:顯示指令曆史緩存大小,如下:
Router#sh terminal
(略)
History is enabled,history size is 10
(略)
Router#terminal history size ?
<0-256> Size of history buffer
Router#terminal history size 25
Router#sh terminal
(略)
History is enabled,history size is 25
(略)
Gather Basic Routing Information
show version:顯示系統硬體的基本配置和軟體版本,以及配置檔案的名字和來源,還有啟動鏡
象,最後是 configuration register的值
Set Passwords:
有 5 種密碼用于加密你的 Cisco router:
1.控制口(console)
2.輔助口(AUX)
3.VTY
4.enable password
5.enable secret
Enable Passwords
enable password:給console和AUX口加密,防止未授權使用者進入特權模式,但是密碼是非加密
形式
enable secret:給 console 和AUX口加密,防止未授權使用者進入特權模式,密碼是加密形式,并且
一旦起用了這個密碼,将淩駕于 enable password 之上,如果同時設定了 enable password 和
enable secret的情況下,必須輸入不同的密碼,如下:
Router(config)#enable password 123
Router(config)#enable secret 123
The enable password you have chosen is the same as your enable secret.This is not
recommended.Re-enter the enable password
Router(config)#enable secret 321
如果 VTY線路的密碼沒有設定,你将無法使用 telnet 來連上它
Auxiliary Password
配置 AUX密碼:
Router#conf t
Router(config)#line aux ?
<0-0> First line number
Router(config)#line aux 0
Router(config-line)#login
Router(config-line)#password 123
Console Password
配置 console密碼以及一些輔助指令:
Router#conf t
Router(config)#line console ?
<0-0> First line number
Router(config)#line console 0
Router(config-line)#login
Router(config-line)#password 123
Router(config-line)#exec-timeout ?
<0-35791> Timeout in minutes
Router(config-line)#exec-timeout 0 ?
<0-2147483> Timeout in seconds
<cr>
Router(config-line)#exec-timeout 0 0
Router(config-line)#logging synchonous
exec-timeout指令:如果X分鐘X秒不活動的話将自動退出,預設是10分鐘,0 0代表永遠不自
動退出
logging synchronous:光标跟随
Telnet Password
配置 VTY 密碼:如果你的 IOS 不是企業版(Enterprise edition),預設你隻能有 5 條 VTY 線路,
線路 0 到4.配置如下:
Router(config-line)#line vty 0 ?
<1-4> Last Line Number
<cr>
Router(config-line)#line vty 0 4
Router(config-line)#login
Router(config-line)#password 123
剛才說過了,如果你的VTY線路沒有配置密碼的話,你将無法telnet連上它,它會報錯:VTY線
路沒有配置密碼.但是你可以取消VTY密碼,這樣就可以在沒有密碼的情況下進行telnet,處于
安全考慮,此方法不推薦,配置如下:
Router(config-line)#line vty 0 4
Router(config-line)#no login
Encryption Your Passwords
隻有 enable secret 是加密的,當你在特權模式下輸入 sh running-config 顯示DRAM 的配置文
件時,其他密碼将被羅列出來:
Router#sh run
(略)
!
enable secret jhdflkdfg$#sdf
enable password 123
!
(略)
對密碼進行加密:在全局配置模式下使用 service password-encryption 指令
Banners
banner類似智語,問候語.最常用的是 MOTD(message of the day),分界符用于分隔資訊,但是分
隔符不能出現在 MOTD資訊中,如下:
Router(config)#banner motd #
The Router is mine
#
Router(config)#^Z(Ctrl+Z)
Router#exit
Router con0 is now available
Press RETURN to get started
The Router is mine
Router>
其他的 3 種banner:
1.exec banner
2.incoming banner
3.login banner
Router Interfaces
配置 router的接口,一般指令模式采用:interface type number的格式,比如:
Router(config)#int ethernet 0
但是Cisco的2600,3600,4000和7000等系列采用了實體卡槽和子產品化的端口機制.是以,指令
變化為:interface type slot/port,比如:
Router(config)#int fastethernet 0
% Imcomplete command
Router(config)#int fastethernet 0?
/
Router(config)#int fastethernet 0/?
<0-1> Fastethernet interface number
Router(config)#int fastethernet 0/1
配置連接配接器的媒體類型,使用 media-type 指令,不過這個一般是自動檢測,如下:
Router(config)#int fa 0/0
Router(config-if)#media-type ?
100BaseX Use RJ45 for -TX; SC F0 for –FX
MII Use MII connector
Bring Up an Interface
打開和關閉1個接口,分别使用shutdown和no shutdown指令,當你關閉某個接口的時候,使用
sh interfaces指令可以檢視接口狀态,并且你将看到以下輸出:
Router#sh int e0
Ethernet0 is administratively down,line protocol is down
(略)
接口是關閉的,是以你要手動打開它,如下:
Router#conf t
Router(config)#int e0
Router(config-if)#no shut
Router(config-if)#^Z
Router#sh int e0
Ethernet is up,line protocol is up
(略)
Configuring an IP Address on an Interface
給某個接口配置 IP位址,使用 ip address [address] [mask]指令,如下: Router(config)#int e0
Router(config-if)#ip address 172.16.10.2 255.255.255.0
記得把接口打開:
Router(config-if)#no shut
Router(config-if)#^Z
如果你需要在 1 個接口添加第二個子網位址,在末尾使用 secondary 參數,這将替換現有 IP 地
址,如下:
Router(config)#int e0
Router(config-if)#ip address 172.16.20.2 255.255.255.0 secondary
Router(config-if)#^Z
來驗證下:
Router#sh run
(略)
!
interface Ethernet0
ip address 172.16.20.2 255.255.255.0 secondary
ip address 172.16.10.2 255.255.255.0
!
Serial Interface Commands
Serial口一般是連接配接在CSU/DSU等類型的提供時鐘頻率的裝置上.但是,假如你在個實驗環境
裡采用了背對背配置,那麼1端将作為DCE裝置提供時鐘頻率.預設Cisco的router都是DTE,
是以你必須讓 1 個 serial接口來提供時鐘頻率,采用的指令是:clock rate,如下:
Router(config)#int s0
Router(config-if)#clock rate ?
Speed (bits per second)
1200
(略)
56000
64000
(略)
Router(config-if)#clock rate 64000
% Error: This commands applies only to DCE interfaces
Router(config-if)#int s1
Router(config-if)#clock rate 64000
确定 serial 接口是否是 DCE 線纜使用 sh controllers指令,如下:
Router>sh controllers s 0
HD unit 0, idb=0x297DE8, driver structure at 0x29F3A0
Buffer size 1524 HD unit 0, V.35 DCE cable
Cisco 的 router 的預設 serial 連接配接帶寬是 T-1(1.544Mbps).有的路由協定要以帶寬做為度來進行衡量,是以,我們給它配置帶寬,使用bandwidth 指令,注意參數機關是 kb,如下:
Router(config-if)#bandwidth ?
<1-10000000> Bandwidth in kilobits
Router(config-if)#bandwidth 64
Hostnames
給router配置主機名,使用hostname指令,這個是本地标志,不影響router在Internet上的工作,
注意回車立即生效,如下:
Router(config)#hostname Noko
Noko(config)#hostname Noco
Noco(config)#
Descriptions
description 指令:本地标志,可以給接口加描述,以便用于區分,如下:
Noco(config)#int e0
Noco(config-if)#description Sales LAN
Noco(config-if)#^Z
來驗證下:
Noco#sh int e0
(略)
Description: Sales LAN
(略)
Viewing and Saving Configurations
将 running-config(DRAM)的檔案複制到 startup-config(NVRAM)裡,使用 copy running-config
startup-config 指令:
Noco#copy run start
可以使用 erase startup-config 指令删除startup-config 檔案,如下:
Noco#erase startup-config
(略)
Noco#sh start
%% Non-volatile configuration memory is not present
假如在這個情況下在特權模式使用 reload 指令重新啟動 router,将進入 setup模式
Verifying Your Configuration
ping:采用了 ICMP echo requests和 replies
traceroute:使用 ICMP和 IP TTL 來跟蹤包所經過的路徑
Verifying with the show ip interface Command
show ip interface:提供 router接口的層3 資訊,包括:
1.接口狀态
2.IP 位址和掩碼
3.通路清單(access-list)資訊
4.一些其他的基本的 IP資訊
Using the show ip interface brief Command
show ip interface brief:和 show ip interface類似,隻是提供簡潔點的總結資訊
Using the show controllers Command
sh controllers:顯示實體接口的資訊,還提供 serial 口線纜資訊,如下:
Router#sh controllers serial 0/0
(略)
buffer size 1524 HD unit 0, V.35 DTE cable
(略)
Router#sh controllers serial 0/1
(略)
buffer size 1524 HD unit 1, V.35 DCE cable
(略)
轉載于:https://blog.51cto.com/tianlang/121602