路由器首页 > 路由器百科 >

通过TFTP来来加载Cisco路由器配置文件

时间:2014-03-14阅读:

1.1. 通过TFTP来配置路由器
提问:如何使用TFTP来加载路由器的配置文件


回答:

Router1#copy tftp://172.25.1.1/CONFIGNAMErunning-config



注释:

IOS12.0版本以前使用的configure network命令,在以后的版本中将会消失,现已被copy <url> system:/running-config替代
拷贝至路由器的配置文件应该以End结尾,否则会出现下面的错误提示信息:%PARSER-4-BADCFG: Unexpected end of configuration file.
1.2. 保存路由器配置到服务器
提问:保存路由器当前配置文件到TFTP服务器作为备份

回答:

Router1#copy running-config tftp://172.25.1.1/CONFIGNAME


注释:

确保TFTP服务器上的目录和文件可写
可用Router1#moretftp://172.25.1.1/CONFIGNAME 来查看TFTP服务器上的文件


1.3. 使用远端配置文件启动路由器
提问:使用一个另外的配置文件来启动路由器


回答:

Router1(config)#service config
Router1(config)#boot network tftpCONFIGNAME1172.25.1.1

Router1(config)#boot host tftpCONFIGNAME2172.25.1.1


注释:
service config缺省是关闭的,当启用后,路由器会去首先去加载network文件,接着是host文件
路由器假设network文件是一个所有路由器通用的文件,而host则包括某个路由器特有的信息
必须同时指定这两个文件,即使不需要host文件,也必须建立host文件,里面只包含一个end


如两个文件都不指定,则按照下列默认顺序加载tftp://255.255.255.255/network-confg (Timed out)
tftp://255.255.255.255/cisconet.cfg (Timed out)
tftp://255.255.255.255/router1-confg (Timed out)
tftp://255.255.255.255/router1.cfg (Timed out)
1.4. 保存大于NVRAM大小的配置文件
提问:配置文件过大,超过了可用的NVRAM大小

回答:

Router1(config)#service compress-config



注释:
要是这条命令生效,必须使用copy running-config startup-config将running-config复制到NVRAM
Router1#copy running-config startup-config
Building configuration...
Compressed configuration from 9664 bytes to 4903 bytes[OK]


可以使用show startup-config来验证
Router1#show startup-config
Using 5068 out of 29688 bytes, uncompressed size = 9969 bytes
Uncompressed configuration from 5068 bytes to 9969 bytes

1.5. 清除启动配置文件
提问:清除配置文件恢复到出厂设置

回答:


Router1#erase nvram:或

Router1#erase startup-config


Erasing the nvram filesystem will remove all files! Continue? [confirm] <enter>

[OK]
Erase of nvram: complete
Router1#reload


Proceed with reload? [confirm] <enter>

注释:
完全删除配置需要两步:
1.删除startup配置
2.reload路由器
当你误删了startup-config后可用copy running-config startup-config恢复

1.6. 加载一个新的IOS镜像
提问:升级路由器的IOS


回答:


Router1#copy tftp://172.25.1.1/c2600-ik9o3s-mz.122-12a.bin flash:
Destination filename [c2600-ik9o3s-mz.122-12a.bin]? <enter>

Accessing tftp://172.25.1.1/c2600-ik9o3s-mz.122-12a.bin...
Erase flash: before copying? [confirm] <enter>
Erasing the flash filesystem will remove all files! Continue? [confirm] <enter>


Erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased

Erase of flash: complete

Loading c2600-ik9o3s-mz.122-12a.bin from 172.25.1.1 (via FastEthernet0/0.1):!!!!!!!!!!!!!!
[OK - 11135588 bytes]



Verifying checksum... OK (0xE643)

11135588 bytes copied in 82.236 secs (135410 bytes/sec)


Router1# reload
Proceed with reload? [confirm] <enter>


注释:
在升级路由器的IOS之前,应该先备份路由器当前的IOS镜像到TFTP服务器
TFTP服务器上面的IOS必须可读

只要你的FLASH空间够,你可以不必在升级IOS镜像前删除全来的IOS镜像


升级前必须确定你的路由器是不是符合新IOS所需要的FLASH和内存的要求
若升级失败,千万不要reload,否则进入common模式
应该将config-register的最后一位改为1,使路由器忽略IOS镜像,从ROM启动,才能删除当前的IOS镜像
1.7. 以另一个IOS镜像文件启动
提问:使用另外的IOS镜像启动
回答:

Router1(config)#boot system flash:c3620-jk9o3s-mz.122-7a.bin
Router1(config)#boot system flash:c3620-jos56i-l.120-11.bin


Router1(config)#boot system slot0:c3620-ik9s-mz.122-13.bin

Router1(config)#boot system rom


注释:

当路由器中有超过一个IOS镜像,则要指定用来启动的IOS镜像
boot system命令的顺序非常重要,如果使用新的IOS,建议先
Router1(config)#no boot system取消所有的boot system
从IOS 12.3(4)T 后思科引入了boot markers的概念,所有的boot systme命令都会放在boot markers之间
Router1#show running-config | include ^boot
boot-start-marker
boot system slot0:c3745-ipbasek9-mz.124-6.T.bin
boot system slot0:c3745-ipbasek9-mz.124-7.bin
boot system flash:
boot-end-marker


在指定启动的IOS镜像之前,应该将config-register的最后一位改为1,则路由器会忽略boot system命令,从ROM启动,然后再更改要启动的IOS镜像


1.8. 通过网络启动
提问:IOS太大本地Flash无法保存,使用保存在网络上的IOS启动
回答:


Router1(config)#boot system tftp c2500-io-l.122-7a.bin 172.25.1.1


Router1(config)#boot system flash


注释:

从tftp启动可以作为从路由器IOS镜像启动失败的备份

1.9. 拷贝IOS镜像文件到服务器
提问:保存一份IOS到TFTP服务器作为备份


回答:

Router1#copy flash:c2600-ik9o3s-mz.122-12a.bin tftp


Address or name of remote host []? 172.25.1.1
Destination filename [c2600-ik9o3s-mz.122-12a.bin]? <enter>
!!!!!!


11135588 bytes copied in 52.588 secs (211752 bytes/sec)



注释:

强烈推荐在将IOS镜像上传到TFTP服务器后,去掉文件的可写属性
1.10. 通过控制台口拷贝IOS镜像文件
提问:通过控制台口和AUX端口来加载IOS
回答:
Router1#copy xmodem: slot1:
Proceed? [confirm] <enter>
Destination filename [ ]? c3620-ik9s-mz.122-12a.bin


Erase slot1: before copying? [confirm] <enter>
Use crc block checksumming? [confirm] <enter>
Max Retry Count [10]: <enter>


Perform image validation checks? [confirm] <enter>
Xmodem download using crc checksumming with image validation
Continue? [confirm] <enter>
Ready to receive file...........CC <start xmodem file transfer here>

4294967295 bytes copied in 1450.848 secs (1271445669961 bytes/sec)



注释:
思科建议使用AUX口进行此步骤,因为AUX口支持硬件流控。为了提高拷贝速度,建议提前设置端口速度为115200来提高传输速度
Router1(config)#line aux 0
Router1(config-line)#speed 115200

可用verifyslot1:c3620-ik9s-mz.122-12a.bin来校验传输的文件

1.11. 删除Flash中的文件
提问:删除Flash中的文件
回答:
删除整个flash
Router1#erase slot1:
Erasing the slot1 filesystem will remove all files! Continue? [confirm] <enter>

Erasing device... eeeeeeeeeeee ...erased


Erase of slot1: complete


或者删除单个文件
Router1#delete slot1:c3620-ik9s-mz.122-13.bin

Delete filename [c3620-ik9s-mz.122-13.bin]? <enter>
Delete slot1:c3620-ik9s-mz.122-13.bin? [confirm] <enter>

注释:
并不是所有的路由器都支持erase命令,不同的文件系统有不同的删除文件方法

Command

Filesystem


Description

Delete


All


Marks the file as deleted, but does not permanently remove it from flash



Squeeze
A
Permanently removes all files that have been marked as deleted


Format

A & C


Erases the entire flash device

Verify

All
Verifies that the IOS file's checksum matches the value encoded in the image

Undelete
A & B
Recovers deleted files


Erase

A & B
Erases the entire flash device



1.12. 对Flash进行分区
提问:对Flash进行分区

回答:
Router1(config)#partition slot1: 2 8 8


注释:
有些文件系统不支持删除单个文件,使用partition能将某些文件隔离出来,防止整个flash设备同时被删除


1.13. 配置路由器为TFTP服务器
提问:配置路由器作为TFTP服务器


回答:

Router1(config)#tftp-server flash:c2600-ik9o3s-mz.122-12a.bin {access-list}


注释:
使用此命令并不能把路由器配置为全功能的TFTP服务器,此服务器只能用于文件下载,而不能进行上传
要下载的文件必须事先放置在flash中,不限与IOS镜像文件,

可以使用access-list来限制访问的网段,提高安全性
建议在完成下载任务后,关闭路由器的TFTP服务器功能
1.14. 在路由器上使用FTP
提问:在路由器上使用FTP来进行文件的下载


回答:

Router1(config)#ip ftp usernameusername


Router1(config)#ip ftp passwordpassword
Router1#copy ftp: running-config
Address or name of remote host [172.25.1.1]? 172.25.1.1

Source filename []? test


Destination filename [running-config]? <enter>
Accessing ftp://172.25.1.1/test...

Loading /test

[OK - 24/4096 bytes]

24 bytes copied in 0.276 secs (87 bytes/sec)


注释:

如果没有指定用户名和密码,路由器缺省会使用匿名登录


当然也可以使用下面的简化命令
copy ftp://username:password@172.25.1.1/c3620-ik9s-mz.122-10a.bin slot1:

1.15. 批量产生路由器配置文件

1.16. 同时改变多台路由器的配置
1.17. 获得设备的硬件信息
1.18. 备份路由器的配置
以上都是使用perl脚本来进行批量化操作,暂时现不修改了
1.19. 热重启
提问:重启路由器而对业务产生最小的影响

回答:


Router1(config)#warm-reboot



注释:
要使warm-reboot生效,必须先冷启动一次

此特性开始于12.3(2)T,根据实验冷启动要比热启动慢4分钟。可以使用reload warm命令进行人工的热重启
该命令不仅能够手动的热重启,而且可以在软件崩溃的情况下自动重启:

Router1(config)#warm-reboot count 4 uptime6


指定在4次热启动后的下一次启动为冷启动,或两次热启动的间隔必须为6分钟,否则,第二次启动为冷启动


1.20. 热升级
提问:升级路由器IOS而对业务影响最小
回答:

Router1(config)#warm-reboot
Router1#reload warm file slot0:c3745-ipbasek9-mz.124-7.bin


注释:
12.3(11)T开始支持此特性

要使warm-reboot生效,必须先冷启动一次

你能够使用slot0,slot1,TFTP服务器等来热升级IOS
升级后的IOS版本也必须支持热升级特性
1.21. 配置存档特性
提问:自动对路由器配置进行存档

回答:


Router1(config)#archive

Router1(config-archive)#path slot0:/configs/$h
Router1(config-archive)#time-period 1440 //每1440分钟保存一次,若不设置则不自动保存


Router1(config-archive)#write-memory //启用存档特性
Router1(config-archive)#end
Router1#



注释:
从12.3(4)T开始思科引入配置存档特性

每次使用write对配置进行保存的时候都会在路由器上生成一个存档配置文件


ftp,http,https,pram,rcp,slot,scp,tftp等作为保存路径
使用show archive命令来显示当前的配置存档,缺省保存14个文件
配置比较命令 show archive config differences slot0:/configs/Router1-1


配置回滚的命令configure replace slot0:/configs/Router1-1 方便的回滚到以前的配置
对于保存的配置文件名可以$h来代表设备主机名$t来代表时间
1.22. 路由器配置锁定
提问:防止多个用户同时对路由器配置文件进行修改


回答:

自动进行配置锁定
Router1(config)#configuration mode exclusive auto
按需进行配置锁定
Router1(config)#configuration mode exclusive manual


注释:

12.3(14)T引入了此特性

在auto的模式下,如果有用户进入了配置模式就自动对配置进行锁定
在manual模式下,可以使用configure terminal lock进行配置锁定
可以使用show configuration lock来查看当前的配置锁定信息

如果你确实需要进行配置,就把看到锁定的人踢掉吧

本文由luyouqi6.cn出品;作品转载请附版权链接http://www.luyouqi6.cn/baike/479.html

相关资料参考: