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 secret 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
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
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
(略)。(Written by 紅頭髮,ChinaITLab BBS)