设为首页 收藏本站
查看: 865|回复: 0

[经验分享] Cisco基础【交换机】远程登录交换机并进行交换机的备份与还原

[复制链接]

尚未签到

发表于 2018-7-10 13:44:46 | 显示全部楼层 |阅读模式
拓扑图:
DSC0000.jpg

实验背景:
  利用主机本地登录交换机并进行配置:
  设置console口的口令
  设置enable的密码
  远程pC通过telnet远程登录交换机并将交换机的配置保存到FTP服务器上。
  当交换机出现故障时,重新购买一台交换机换上,然后将老交换机的配置从FTP服务器还原到新的交换机上。查看是否新交换机具有了和旧交换机一样的配置(即有console口的口令和enable的密码),这样新的交换机就不必重新配置了。
  实验过程注意事项:
  为了模拟真实的场景呢,交换机的配置是没有相应键盘来输入密令的,所以所有交换机的本地配置都是有主机进入终端来进行初始化配置的。
交换机的配置(从主机的终端进入交换机对其配置)
  对交换机进行配置:
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”的提示。
  为方便实现远程管理,需要对交换机进行相应的远程管理配置
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机的配置
  远程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的文件。这个文件就是交换机中的配置文件。
DSC0001.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之后发现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和running-config的呢,这儿给出简单的理解:
  startup-config 是开机启动的配置文件,在NVRAM中,断电后能保存;
  running-config是即使配置过的运行文件,在DRAM中,断电会全部丢失。
  也就是说呢,交换机启动后,startup-config就不会再改变了,如果我们在交换机中做了很多的工作,这个工作将会保存在running-config文件中,而不是保存在startup-config中。由于running-config配置文件断电会全部丢失,所以我们做好工作后,会将running-config复制到startup-config中以保存所做的工作。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-535899-1-1.html 上篇帖子: Cisco IOU 模拟器测试感受 下篇帖子: Cisco 4506 ROMMON IOS upgrade(console)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表