利用主機本地登陸交換機並進行配置:html
設置console口的口令服務器
設置enable的密碼ide
遠程pC經過telnet遠程登陸交換機並將交換機的配置保存到FTP服務器上。ui
當交換機出現故障時,從新購買一臺交換機換上,而後將老交換機的配置從FTP服務器還原到新的交換機上。查看是否新交換機具備了和舊交換機同樣的配置(即有console口的口令和enable的密碼),這樣新的交換機就沒必要從新配置了。spa
實驗過程注意事項:debug
爲了模擬真實的場景呢,交換機的配置是沒有相應鍵盤來輸入密令的,因此全部交換機的本地配置都是有主機進入終端來進行初始化配置的。htm
對交換機進行配置:blog
Switch>enable Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#hostname SW1 SW1(config)#line console 0 //進入console口終端線路配置模式 SW1(config-line)#passwod 123 //設置console口的密碼爲123 SW1(config-line)#login //使設置的console口的密碼生效。(在登陸的時候驗證密碼) SW1(config-line)#exit SW1(config)#enable password 123456 //設置enable明文密碼。(使進入交換機時候驗證密碼) SW1(config)#exit SW1#
須要注意的是: enable若是不設置的話,在telnet登陸時會出現」no password」的提示。圖片
爲方便實現遠程管理,須要對交換機進行相應的遠程管理配置ip
SW1#conf t Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#inter vlan 1 //進入交換機默認的管理vlan 1 SW1(config-if)#ip address 192.168.1.1 255.255.255.0 //配置管理IP地址和子網掩碼 SW1(config-if)#no shutdown//啓用端口 SW1(config-if)# %LINK-5-CHANGED: Interface Vlan1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up SW1(config-if)#exit SW1(config)#line vty 0 15 //定義最多能夠容許16個用戶用Telnet登陸交換機 SW1(config-line)#password cisco //設置telnet登陸時的密碼爲cisco SW1(config-line)#login //使密碼設置生效 SW1(config-line)#exit SW1(config)#
遠程PC的IP地址改成與交換機同網段:192.168.1.2255.255.255.0
將服務器的IP地址改爲192.168.1.254 255.255.255.0
遠程PC機經過遠程telnet登陸交換機(經過PC機的命令提示符進入)
PC>ping 192.168.1.1 //先對交換機ping一下確保與交換機之間的連線是相同的 Pinging 192.168.1.1 with 32 bytes of data: Request timed out. Reply from 192.168.1.1: bytes=32 time=0ms TTL=255//提示ping通 Reply from 192.168.1.1: bytes=32 time=1ms TTL=255 Reply from 192.168.1.1: bytes=32 time=0ms TTL=255 Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 3, Lost = 1 (25% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 1ms, Average = 0ms PC>telnet 192.168.1.1 //用telnet進行遠程登陸 Trying 192.168.1.1 ...Open User Access Verification Password: //輸入telnet登陸密碼:cisco SW1>enable //進入交換機 Password: //輸入進入密碼:123456 SW1#copy running-config startup-config //將運行配置文件覆蓋啓動配置文件。(將交換機所作的配置保存下來。) Destination filename [startup-config]? //指定目標文件[默認爲startup-config] Building configuration... [OK] SW1#copy running-config TFTP //將運行配置文件(交換機的配置)保存到FTP服務器上 Address or name of remote host []? 192.168.1.254 //指定遠程FTP服務器的地址 Destination filename [SW1-confg]? SW1-20141022-config //指定保存到FTP服務器上的文件名 Writing running-config....!! [OK - 1059 bytes] 1059 bytes copied in 3.005 secs (0 bytes/sec) SW1#
此時查看服務器中的FTP服務器,的確發現有了一個名叫SW1-20141022-config的文件。這個文件就是交換機中的配置文件。
將交換機刪掉,從新添加一個新的交換機並鏈接好線。
對新的交換機先show一下
Switch> Switch>enable Switch#show running-config Building configuration... Current configuration : 971 bytes ! version 12.1 no service timestamps log datetime msec no service timestamps debug datetime msec no service password-encryption ! hostname Switch ! ! 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 Vlan1 no ip address shutdown ! ! line con 0 ! line vty 0 4 login line vty 5 15 login ! ! end
新的交換機確實是空白的,vlan1沒有配置IP,也沒有登陸口令。
既然交換機換成新的了,那麼新的交換機須要從新初始化。
Switch# Switch#config t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#int vlan 1 //進入VLAN1 Switch(config-if)#ip add Switch(config-if)#ip address 192.168.1.1 255.255.255.0 //配置VLAN1IP地址 Switch(config-if)#no shutdown //啓動生效 Switch(config-if)# %LINK-5-CHANGED: Interface Vlan1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up Switch(config-if)#exit Switch(config)#exit Switch# %SYS-5-CONFIG_I: Configured from console by console Switch#copy TFTP startup-config //將FTP上的文件複製到啓動配置文件中 Address or name of remote host []? 192.168.1.254 //來自FTP的地址是192.168.1.254 Source filename []? SW1-20141022-config //來自FTP的SW1-20141022-config文件 Destination filename [startup-config]? //指定存放的目標文件爲默認的startup-config Accessing tftp://192.168.1.254/SW1-20141022-config.... Loading SW1-20141022-config from 192.168.1.254: ! [OK - 1059 bytes] //複製成功。 1059 bytes copied in 3.016 secs (351 bytes/sec) Switch#
此時,FTP上的SW1-10241022-config文件已經成功導入到新的交換機上去了。也就是說舊交換機上的全部配置都已經成功複製(還原)到了新交換機的startup-config(啓動配置)中去了。這樣新交換機就沒必要再手動寫入命令了。
咱們來show一下交換機的運行配置和啓動配置來確認一下新交換機是否具備舊交換機的全部配置
Switch#show running-config //show 運行配置 Building configuration... Current configuration : 984 bytes ! version 12.1 no service timestamps log datetime msec no service timestamps debug datetime msec no service password-encryption ! hostname Switch ! ! 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 Vlan1 ip address 192.168.1.1 255.255.255.0 ! ! line con 0 ! line vty 0 4 login line vty 5 15 login ! ! End Switch#show startup-config //show 啓動配置 Using 1059 bytes ! version 12.1 no service timestamps log datetime msec no service timestamps debug datetime msec no service password-encryption ! hostname SW1 ! enable password 123456 ! ! 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 Vlan1 ip address 192.168.1.1 255.255.255.0 ! ! line con 0 password 123 login ! line vty 0 4 password cisco login line vty 5 15 password cisco login ! ! end
此時咱們發現了一個問題,show running-config以後發現,console口和telnet都沒有口令。而show startup-config以後發現Vlan1有IP地址,console口和telnet都是有口令密碼的。並且此時呢,遠程PC能ping通交換機卻不能利用telnet登陸交換機。
這個緣由的是由於在還原交換機的時候,咱們是將FTP上的SW1-20141022-config文件還原到了交換機的startup-config配置文件中了,而沒有還原到running-config配置中去。因此咱們須要將startup-config再複製到running-config中。
Switch# Switch#copy startup-config running-config //將startup-config複製到running-config中 Destination filename [running-config]? //指定目標文件爲默認的running-config 1059 bytes copied in 0.416 secs (2545 bytes/sec) SW1# %SYS-5-CONFIG_I: Configured from console by console
此時咱們在show running-config
SW1# SW1#show running-config Building configuration... Current configuration : 1059 bytes ! version 12.1 no service timestamps log datetime msec no service timestamps debug datetime msec no service password-encryption ! hostname SW1 ! enable password 123456 ! ! 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 Vlan1 ip address 192.168.1.1 255.255.255.0 ! ! line con 0 password 123 login ! line vty 0 4 password cisco login line vty 5 15 password cisco login ! ! end
此時show running-config 有了console口的口令和enable的登陸密碼。而遠程PC也能夠正常telnet登陸交換機了。
startup-config 是開機啓動的配置文件,在NVRAM中,斷電後能保存;
running-config是即便配置過的運行文件,在DRAM中,斷電會所有丟失。
也就是說呢,交換機啓動後,startup-config就不會再改變了,若是咱們在交換機中作了不少的工做,這個工做將會保存在running-config文件中,而不是保存在startup-config中。因爲running-config配置文件斷電會所有丟失,因此咱們作好工做後,會將running-config複製到startup-config中以保存所作的工做。