Cisco基础【交换机】远程登陆交换机并进行交换机的备份与还原

拓扑图:

wKioL1RHwnfS0QpoAACDUV4bw6U522.jpg 

 

实验背景:

     利用主机本地登陆交换机并进行配置: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机的配置

远程PCIP地址改成与交换机同网段: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的文件。这个文件就是交换机中的配置文件。

wKiom1RHwjnznZ9xAALR2v7u2Ic392.jpg 

假设交换机坏掉了,要求从新更换了一个新的交换机,须要将原来旧的交换机的配置也应用的新的交换机中。

将交换机删掉,从新添加一个新的交换机并链接好线。

对新的交换机先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以后发现Vlan1IP地址,console口和telnet都是有口令密码的。并且此时呢,远程PCping通交换机却不能利用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-configrunning-config的呢,这儿给出简单的理解:

startup-config 是开机启动的配置文件,在NVRAM中,断电后能保存;

running-config是即便配置过的运行文件,在DRAM中,断电会所有丢失。

也就是说呢,交换机启动后,startup-config就不会再改变了,若是咱们在交换机中作了不少的工做,这个工做将会保存在running-config文件中,而不是保存在startup-config中。因为running-config配置文件断电会所有丢失,因此咱们作好工做后,会将running-config复制到startup-config中以保存所作的工做。

相关文章
相关标签/搜索