1 案例1:交換機基本命令模式
1.1 問題
本例要求熟練掌握交換機每個模式的配置命令
對於思科交換機來說,主要有2種配置途徑:其一,使用交換機自帶的Console線纜連接到計算機的COM口,然后利用計算機的超級終端軟件直接配置,首次配置通常使用這種方式;其二,通過telnet方式遠程訪問、配置交換機,這種方式要求此交換機已配置有IP地址且已接入計算機網絡,后續課程會學習此訪問方式。
1)通過超級終端訪問交換機
2)交換機工作模式的進入與退出
真實設備環境,如圖-1所示。

圖-1
1.2 方案
本例中的配置練習可采用思科模擬器 —— Cisco Packet Tracer 6.2來實現。
1)安裝Packet Tracer 6.2
雙擊安裝包執行默認安裝,然后將中文語言文件Chinese.ptl解壓到安裝目錄下的多語言文件夾,比如C:\Program Files (x86)\Cisco Packet Tracer 6.0\languages。
雙擊桌面的Cisco Packet Tracer快捷方式以啟動程序,打開菜單“Options”-->“Preferences”-->切換到“Interface”選項卡-->選擇下方的Chinese.ptl-->單擊右下角“Change Language”按鈕,彈出提示時單擊“OK”,如圖-2所示。

圖-2
關閉當前Packet Tracer程序,然后再重新啟動此程序,可發現已經變成中文語言界面了(當前漢化的還不完整),如圖-3所示。

圖-3
2)建立實驗網絡拓撲
在Packet Tracer程序主窗口中,添加一台Cisco 2960交換機、一台普通PC機,並添加Console連接、直通網線連接,如圖-4所示,確認完畢后將當前拓撲結構保存為c2960-pc.pkt文件。

圖-4
其中,連接細節如下:
- 交換機的Console口 <--> PC機的RS 232串口。
- 交換機的FastEthernet0/24接口 <--> PC機的FastEthernet0網卡。
1.3 步驟
實現此案例需要按照如下步驟進行。
步驟一:通過超級終端訪問交換機。
1)配置並打開超級終端
在此前建立的Packet Tracer實驗拓撲環境中,單擊PC機以打開此設備,確認電源已啟動(機箱示意圖上的指示燈為黃綠色),切換到“桌面選項卡”,如圖-5所示,找到其中的“終端”並單擊打開。

圖-5
在彈出的終端配置窗口中,如圖-6所示,單擊“確定”以接受默認值。

圖-6
接下來就可以看到“終端”窗口了,其中顯示了通過Console線連接的交換機初始化信息,回車后可進入交換機的“Switch>”配置系統,如圖-7所示。

圖-7
提示:在Packet Tracer環境中,可直接單擊交換機圖標,然后切換到“命令行”選項卡,也可以進入IOS配置環境。
步驟二:交換機工作模式的進入與退出
1) 交換機工作模式的進入如下:
- Switch>enable //切換為特權模式
- Switch# configure terminal //進入全局配置模式
- Enter configuration commands, one per line. End with CNTL/Z.
- Switch(config)#interface fastEthernet 0/1 //進入接口模式
- Switch(config-if)#
2)交換機工作模式的退出下:
- Switch(config-if)#exit //接口模式退到全局配置模式
- Switch(config)#exit //全局配置模式退到特權模式
- Switch#exit //特權模式退到用戶模式
- Switch>
注:exit 返回上一模式
end 從接口或者特全局配置模式回到特權模式,快捷鍵Ctrl+z同等效果
思科設備命令行不區分大小寫,與Linux命令行不同
命令輸入錯誤卡住時同時按鍵盤ctrl+shift+6這三個鍵即可
2 案例2:交換機命令行基本配置
2.1 問題
修改及查看交換機配置
1)修改交換機主機名
2)查看交換機配置信息
3)查看IOS名稱以及版本信息
2.2 方案
在Packet Tracer程序主窗口中,添加一台Cisco 2960交換機,進入交換機,輸入相關命令進行配置和查看交換機
2.3 步驟
實現此案例需要按照如下步驟進行。
步驟一:修改交換機主機名
進入全局配置模式后,使用hostname指令可以為交換機設置主機名。例如,以下操作可以將主機名設置為s1:
- Switch(config)# hostname s1 //配置主機名
- s1(config)#
步驟二:查看交換機配置信息
查看交換機當前的運行配置:
- 查看交換機當前的運行配置(或write terminal):
- s1# show running-config //查看當前的運行配置
- Building configuration...
- Current configuration : 1052 bytes
- !
- version 12.2
- no service timestamps log datetime msec
- no service timestamps debug datetime msec
- no service password-encryption
- !
- hostname sw1 //已配置主機名
- !
- !
- !
- !
- spanning-tree mode pvst
- !
- interface FastEthernet0/1
- !
- interface FastEthernet0/2
- !
- interface FastEthernet0/3
- !
- interface FastEthernet0/4
- !
- interface FastEthernet0/5
- !
- interface FastEthernet0/6
- !
- interface FastEthernet0/7
- !
- interface FastEthernet0/8
- !
- interface FastEthernet0/9
- !
- interface FastEthernet0/10
- !
- interface FastEthernet0/11
- !
- interface FastEthernet0/12
- !
- interface FastEthernet0/13
- !
- interface FastEthernet0/14
- !
- interface FastEthernet0/15
- !
- interface FastEthernet0/16
- !
- interface FastEthernet0/17
- !
- interface FastEthernet0/18
- !
- interface FastEthernet0/19
- !
- interface FastEthernet0/20
- !
- interface FastEthernet0/21
- !
- interface FastEthernet0/22
- !
- interface FastEthernet0/23
- !
- interface FastEthernet0/24
- !
- interface GigabitEthernet1/1
- !
- interface GigabitEthernet1/2
- !
- interface Vlan1
- no ip address
- shutdown
- !
- !
- line con 0
- !
- line vty 0 4
- login
- line vty 5 15
- login
- !
- !
- end
- sw1#
步驟三:查看IOS名稱以及版本信息
查看ios名稱及版本信息
- s1#show version
- Cisco Internetwork Operating System Software
- IOS (tm) C2950 Software (C2950-I6Q4L2-M), Version 12.1(22)EA4, RELEASE SOFTWARE(fc1)
- Copyright (c) 1986-2005 by cisco Systems, Inc.
- Compiled Wed 18-May-05 22:31 by jharirba
- Image text-base: 0x80010000, data-base: 0x80562000
- ROM: Bootstrap program is is C2950 boot loader
- Switch uptime is 1 minutes, 39 seconds
- System returned to ROM by power-on
- Cisco WS-C2950-24 (RC32300) processor (revision C0) with 21039K bytes of memory.
- Processor board ID FHK0610Z0WC
- Last reset from system-reset
- Running Standard Image
- 24 FastEthernet/IEEE 802.3 interface(s)
- 63488K bytes of flash-simulated non-volatile configuration memory.
- Base ethernet MAC Address: 00E0.B026.B88C
- Motherboard assembly number: 73-5781-09
- Power supply part number: 34-0965-01
- Motherboard serial number: FOC061004SZ
- Power supply serial number: DAB0609127D
- Model revision number: C0
- Motherboard revision number: A0
- Model number: WS-C2950-24
- System serial number: FHK0610Z0WC
- Configuration register is 0xF
3 案例3:交換機密碼設置
3.1 問題
配置交換機的訪問口令
1)配置用戶進入特權模式的明文密碼為123
2)配置用戶進入特權模式的密文密碼為456
3)配置conslole口令為789
3.2 方案
配置交換機訪問口令
實現此案例需要按照如下步驟進行。
3.3 步驟
步驟一:交換機密碼配置
1)設置特權模式口令
包括兩種典型的方法:
方法1(明文):enable password 密碼字串
方法2(加密):enable secret 密碼字串
比如,以下操作將明文口令設為123、加密口令設置為456:
- sw2960(config)# enable password 123
- sw2960(config)# enable secret 456
返回特權模式,查看運行配置可觀察兩種口令設置的差異:
- sw2960(config)# end //返回特權模式
- sw2960#
- %SYS-5-CONFIG_I: Configured from console by console
- sw2960# show running-config //查看當前的運行配置
- .. ..
- !
- hostname sw2960
- !
- enable secret 5 $1$mERr$pUBB1obEqpmMUtC1rBieD1 //加密口令設置
- enable password 123 //非加密的口令設置
- !
- !
- .. ..
執行disable切換到用戶模式,再執行enable切換到特權模式,此時會要求輸入正確的口令才允許進入(如果明文/密文口令都設置了,則密文口令起作用):
- sw2960> enable
- Password: //嘗試明文口令123無效
- Password: //輸入密文口令456驗證成功
- sw2960#
步驟二:設置console口令
以下操作配置交換機console口令
- Sw2960(config)#line console 0
- Sw2960(config-line)#password 789 //設置consol口令
- Sw2960(config-line)#login
切換到用戶模式,提示輸入conslole口令才能再次進入到用戶模式:
- Sw2960(config-line)#end
- Sw2960#
- %SYS-5-CONFIG_I: Configured from console by console
- Sw2960#exit
- Sw2960 con0 is now available
- Press RETURN to get started.
- User Access Verification
- Password:
步驟三:清空設備配置
- Switch(config)#exit
- Switch#write
- Switch#erase startup-config
- Erasing the nvram filesystem will remove all configuration files! Continue? [confirm] //此時系統詢問是否確定刪除,按回車即可
- [OK]
- Erase of nvram: complete
步驟四:重啟設備檢測配置狀況
- Switch#reload
- Proceed with reload? [confirm] //此時系統詢問是否確定重啟,按回車即可