第一章路由器配置和文件管理

出处:NeoShis Blog

1.1. 通过TFTP来配置路由器

提问 使用TFTP来加载路由器的配置文件

回答

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

Destination filename [running-config]?

Accessing tftp://172.25.1.1/NEWCONFIG...

Loading NEWCONFIG from 172.25.1.1 (via FastEthernet0/0.1): !

[OK - 24 bytes]

24 bytes copied in 0.192 secs (125 bytes/sec)

Router1#

注释 IOS12.0版本以前使用的configure network命令,另外拷贝至路由器的配置文件应该以End结尾,否则会出现下面的错误提示信息:%PARSER-4-BADCFG: Unexpected end of configuration file.

1.2. 保存路由器配置到服务器

提问 保存路由器当前配置文件到TFTP服务器作为备份

回答

Freebsd% touch /tftpboot/router1-confg

Freebsd% chmod 666 /tftpboot/router1-confg

Freebsd% telnet Router1

Trying 172.25.1.5...

Connected to Router1.

Escape character is '^]'.

User Access Verification

Password:

Router1>enable

Password:

Router1#copy running-config tftp://172.25.1.1/router1-confg

Address or name of remote host [172.25.1.1]?

Destination filename [router1-confg]?

!!!

9640 bytes copied in 3.956 secs (2437 bytes/sec)

Router1#

注释 确保TFTP服务器上的目录和文件可写

1.3. 使用远端配置文件启动路由器

提问 使用另外的配置文件来启动路由器

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#service config

Router1(config)#boot network tftp Network-auto 172.25.1.1

Router1(config)#boot host tftp Router8-auto 172.25.1.1

Router1(config)#end

Router1#

注释 service config缺省是关闭的,如果打开缺省会去查找的文件名为network-config, cisconet.cfg, router1-confg, router1.cfg等

1.4. 保存大于NVRAM大小的配置文件

提问 配置文件过大,超过了可用的NVRAM大小

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#service compress-config

Router1(config)#end

Router1#

注释 可以使用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: (erase startup-config)

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

[OK]

Erase of nvram: complete

Router1#reload

System configuration has been modified. Save? [yes/no]: no

Proceed with reload? [confirm]



注释 无

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]?

Accessing tftp://172.25.1.1/c2600-ik9o3s-mz.122-12a.bin...

Erase flash: before copying? [confirm]

Erasing the flash filesystem will remove all files! Continue? [confirm]

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]

注释 无

1.7. 以另一个IOS镜像文件启动

提问 使用其它的IOS镜像启动

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

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

Router1(config)#end

注释 boot system命令的顺序非常重要,如果使用新的IOS,建议先进行no 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

Router1#



1.8. 通过网络启动

提问 IOS太大本地Flash无法保存,使用保存在网络上的IOS启动

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

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

Router1(config)#boot system flash

Router1(config)#end

Router1#

注释 无

1.9. 拷贝IOS镜像文件到服务器

提问 保存一份IOS到TFTP服务器作为备份

回答

Freebsd% touch /tftpboot/c2600-ik9o3s-mz.122-12a.bin

Freebsd% chmod 666 /tftpboot/c2600-ik9o3s-mz.122-12a.bin

Freebsd% telnet Router1

Trying 172.25.1.5...

Connected to Router1.

Escape character is '^]'.

User Access Verification

Password:

Router1>enable

Password:

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]?

!!!!!!

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

Router1#

注释

1.10. 通过控制台口拷贝IOS镜像文件

提问 通过控制台口和AUX端口来加载IOS

回答

Router1#copy xmodem: slot1:

**** WARNING ****

x/ymodem is a slow transfer protocol limited to the current speed

settings of the auxiliary/console ports. The use of the auxilary

port for this download is strongly recommended.

During the course of the download no exec input/output will be

available.

---- ******* ----

Proceed? [confirm]

Destination filename []? c3620-ik9s-mz.122-12a.bin

Erase slot1: before copying? [confirm]

Use crc block checksumming? [confirm]

Max Retry Count [10]:

Perform p_w_picpath validation checks? [confirm]

Xmodem download using crc checksumming with p_w_picpath validation

Continue? [confirm]

Ready to receive file...........CC

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

Router1#

注释 思科建议使用AUX口进行此步骤,因为AUX口支持硬件流控。为了提高拷贝速度,建议提前使用下述命令来设置端口速度

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line aux 0

Router1(config-line)#speed 115200

Router1(config-line)#end

Router1#

1.11. 删除Flash中的文件

提问 删除Flash中的文件

回答

Router1#erase slot1:

Erasing the slot1 filesystem will remove all files! Continue? [confirm]

Erasing device... eeeeeeeeeeee ...erased

Erase of slot1: complete

Router1#

或者删除单个文件

Router1#delete slot1:c3620-ik9s-mz.122-13.bin

Delete filename [c3620-ik9s-mz.122-13.bin]?

Delete slot1:c3620-ik9s-mz.122-13.bin? [confirm]

Router1#

注释 并不是所有的路由器都支持erase命令,不行的话可以尝试format命令,有些路由器在使用delete命令以后还可以使用undelete来恢复,同时也需要使用squeeze来彻底删除文件

1.12. 对Flash进行分区

提问 对Flash进行分区

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#partition slot1: 2 8 8

Router1(config)#end

Router1#

注释 如果erase不支持也可以试试partition命令

1.13. 配置路由器为TFTP服务器

提问 配置路由器为TFTP服务器

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

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

Router1(config)#end

Router1#

注释 使用此命令并不能把路由器配置为全功能的TFTP服务器,此服务器只能用于文件下载,而不能进行上传

1.14. 在路由器上使用FTP

提问 在路由器上使用FTP来进行文件的下载

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#ip ftp username neoshi

Router1(config)#ip ftp password ioscookbook

Router1(config)#end

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]?

Accessing [url]ftp://172.25.1.1/test...[/url]

Loading /test

[OK - 24/4096 bytes]



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

Router1#

当然也可以使用下面的简化命令

copy [url]ftp://neoshi[/url]:ioscookbook@172.25.1.1/c3620-ik9s-mz.122-10a.bin slot1:

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

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

1.16. 同时改变多台路由器的配置

1.17. 获得设备的硬件信息

1.18. 备份路由器的配置

以上都是使用perl脚本来进行批量化操作,建议使用我推荐的图形话绿色免费工具软件

1.19. 热重启

提问 重启路由器而对业务影响减少到最低

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#warm-reboot

Router1(config)#end

Router1#

注释 要使用热启动必须先冷启动一次…无语了吧哈哈。此特性开始于12.3(2)T,根据实验冷启动要比热启动慢4分钟。可以使用reload warm命令进行人工的热重启

1.20. 热升级

提问 升级路由器IOS而对业务影响最小

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#warm-reboot

Router1(config)#end

Router1#reload warm file slot0:c3745-ipbasek9-mz.124-7.bin

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

1.21. 配置存档特性

提问 自动对路由器配置进行存档

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#archive

Router1(config-archive)#path slot0:/configs/$h

Router1(config-archive)#write-memory

Router1(config-archive)#time-period 1440

Router1(config-archive)#end

Router1#

注释 从12.3(4)T开始思科引入配置存档特性,每次使用wr对配置进行保存的时候都会在路由器上生成一个存档配置文件,当然也可以像示例那样每1440分钟保存一次,使用show archive命令来显示当前的配置存档,缺省保存14个文件,并且提供了配置比较命令 show archive config differences slot0:/configs/Router1-1 更提供了配置回滚的命令configure replace slot0:/configs/Router1-1 方便的回滚到以前的配置。对于保存的配置文件名可以$h来代表设备主机名$t来代表时间

1.22. 路由器配置锁定

提问 防止同时多个用户对路由器配置文件进行修改

回答

自动进行配置锁定

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#configuration mode exclusive auto

Router1(config)#end

Router1#

按需进行配置锁定

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#configuration mode exclusive manual

Router1(config)#end

Router1#

注释 12.3(14)T引入了此特性防止多个用户同时对路由器配置进行修改,在配置为auto的模式下,如果有用户进入了配置模式就自动对配置进行锁定,在manual模式下可以使用configure terminal lock进行配置锁定,可以使用show configuration lock来查看当前的配置锁定信息,如果你确实需要进行配置,就把看到锁定的人踢掉吧。
第二章路由器管理

2.1. 创建命令别名

提问 为常用的命令创建简洁的别名

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#alias exec rt show ip route

Router1(config)#alias exec on show ip ospf neighbor

Router1(config)#end

Router1#

注释 show aliases命令可以输出当前配置的别名



2.2. 管理路由器ARP缓存

提问 修改ARP表条目超时时长

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#interface Ethernet0

Router1(config-if)#arp timeout 600

Router1(config-if)#end

Router1#

注释 缺省情况为4个小时,同时思科没有提供命令能单独的清除某个ARP缓存,只能通过clear arp 命令来清除整个ARP表



2.3. 路由器Buffer调整

提问 手动调整路由器Buffer分配来使其工作的更高效

回答 路由器维护两个Buffer池,public buffers和interface buffers

调整public buffers

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#buffers big initial 100

Router1(config)#buffers big max-free 200

Router1(config)#buffers big min-free 50

Router1(config)#buffers big permanent 50

Router1(config)#end

Router1#

调整interface buffers

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#buffers Ethernet0 initial 200

Router1(config)#buffers Ethernet0 max-free 300

Router1(config)#buffers Ethernet0 min-free 50

Router1(config)#buffers Ethernet0 permanent 50

Router1(config)#end

Router1#

注释 一般不建议修改,如果修改,建议首先使用show buffers命令来查看当前buffer使用情况,调整完以后建议使用show memory来查看内存使用情况



2.4. 自动调整路由器Buffer

提问 希望路由器根据自己的情况自动进行buffer分配调整

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#buffers tune automatic

Router(config)#end

Router#

注释 此命令引自IOS 12.3(14)T,使用show buffers tune命令来查看自动调整情况



2.5. 使用CDP协议

提问 希望获得相连网络设备的信息

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#cdp run

Router1(config)#interface Serial0/0

Router1(config-if)#cdp enable

Router1(config-if)#exit

Router1(config)#interface FastEthernet0/0

Router1(config-if)#no cdp enable

Router1(config-if)#exit

Router1(config)#interface FastEthernet1/0

Router1(config-if)#cdp enable

Router1(config-if)#end

Router1#

注释 CDP(Cisco Discovery Protocol)是思科专有的协议,用于发现相连的思科设备,帮助了解网络拓朴,缺省是启用的,使用show cdp neighbor detail 命令可以查看相连设备的详细信息



2.6. 禁止CDP协议

提问 为了安全期间不想让邻近设备发现自己设备的信息

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#cdp run

Router1(config)#interface FastEthernet0/0

Router1(config-if)#no cdp enable

Router1(config-if)#end

Router1#



注释 为了安全期间可以在边界设备上禁止CDP

2.7. 小服务的开启

提问 开启或者禁用一些类似finger的小服务

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#service tcp-small-servers (no service tcp-small-servers)

Router1(config)#service udp-small-servers (no sercie udp-small-servers)

Router1(config)#end

Router1#

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#ip finger (no ip finger)

Router1#

注释 tcp和udp的小服务指开启路由器的echo,discard,daytime和chargen服务,为了安全期间都建议将其关闭



2.8. 启用路由器HTTP访问

提问 通过浏览器来配置和管理路由器

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#access-list 75 permit 172.25.1.1

Router1(config)#access-list 75 deny any

Router1(config)#ip http server

Router1(config)#ip http access-class 75

Router1(config)#end

Router1#



注释 由于IOS 12.1(5)之前存在HTTP访问的高危漏洞,所以如果你的IOS版本小于此版本建议不要开启此服务



2.9. 启用路由器安全HTTPS访问

提问 通过加密的访问HTTP访问路由器

回答

Core#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Core(config)#ip http secure-server

Core(config)#end

Core#



注释 IOS 12.2(14)S之后引入此特性,建议先用no ip http server命令关闭非加密的HTTP访问,然后开启安全的访问,同时可以使用ip http secure-port 8080

命令来更改访问端口

2.10. 使用静态主机名映射

提问 在路由器上配置静态的主机映射表,从而使用主机名而不是IP地址来访问设备

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#ip host freebsd 172.25.1.1

Router1(config)#ip host router2 10.1.1.1 172.22.1.4

Router1(config)#end

Router1#

注释 可以对一个主机名映射很多IP地址来提供冗余访问,show hosts命令来验证



2.11. 启用DNS服务

提问 路由器使用DNS服务器来解析主机名

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#ip domain-lookup

Router1(config)#ip domain-name oreilly.com

Router1(config)#ip name-server 172.25.1.1

Router1(config)#ip name-server 10.1.20.5

Router1(config)#end

Router1#



注释 从IOS 12.2开始,思科使用了ip domain lookup.来代替ip domain-lookup 类似的ip domain-name 被 ip domain name代替



2.12. 禁用域名解析

提问 禁用域名解析,防止路由器自动对打错的命令的进行DNS查询

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#no ip domain-lookup

Router1(config)#end

Router1#

如果需要启用DNS查询主机名,但是又为了避免打错命令查询的情况可以使用如下的变通方法

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line vty 0 4

Router1(config-line)#transport preferred none

Router1(config-line)#end

Router1#

注释 对后一个命令的稍微解释一下,正常情况下都知道可以直接使用主机名回车路由器会认为时telnet 到此设备,可以省略掉telnet的命令,原因是因为transport preferred缺省是telnet,如果配置为none就必须使用telnet命令来进行设备登录,命令打错也不会出现地址解析的问题了。

2.13. 配置路由器特定时间重启

提问 需要路由器在特定时间自动重启

回答

Router1#reload in 20

Reload scheduled for 11:33:53 EST Sat Feb 1 2003 (in 20 minutes)

Proceed with reload? [confirm] <enter>

Router1#

Router1#reload at 14:00 Feb 2

Reload scheduled for 14:00:00 EST Sun Feb 2 2003 (in 26 hours and 44 minutes)

Proceed with reload? [confirm] <enter>

Router1#

注释 很有用的命令,当你在对路由器配置进行修改前可以先行输入此命令,然后进行修改但是不保存配置,这样可以防止把自己锁在路由器之外。可以使用reload cancel命令来取消定时重启

2.14. 定时执行配置命令

提问 周期性的定时执行某个命令

回答

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#kron policy-list NEOSHI

Router(config-kron-policy)#cli write memory

Router(config-kron-policy)#exit

Router(config)#kron occurrence DAILYat5 at 17:00 recurring

Router(config-kron-occurrence)#policy-list NEOSHI

Router(config-kron-occurrence)#end

Router#



注释 从IOS12.3(1)开始引入了这个类似Unix Cron的特性,不过也有一些缺点,只能运行EXEC模式下的命令,不能运行配置模式下的命令,同时输入的命令不能是交互性的,比如不能输入copy running-config startup-config来保存配置,因为是需要确认的,必须使用write memory来代替

2.15. 显示路由器CPU利用率的历史数据

提问 显示历史的路由器CPU利用率

回答

Router# show processes cpu history

Router 03:48:18 PM Monday Apr 17 2006 EDT



555559999999999999999

5 444449999999999999999

100 ******************

90 ******************

80 ******************

70 ******************

60 ******************

50 ***********************

40 ***********************

30 ***********************

20 ***********************

10 * ***********************

0....5....1....1....2....2....3....3....4....4....5....5....

0 5 0 5 0 5 0 5 0 5

CPU% per second (last 60 seconds)



99 1 9999

99 1 4 9999

100 ** ***#*#

90 ** **##*#

80 #* *###*#

70 #* *###*#

60 #* *###*#

50 #* *#####

40 #* *#####

30 #* ######

20 ## ######

10 ## * ######

0....5....1....1....2....2....3....3....4....4....5....5....

0 5 0 5 0 5 0 5 0 5

CPU% per minute (last 60 minutes)

* = maximum CPU% # = average CPU%

……………………………….(由于显示问题省去此图).

CPU% per hour (last 72 hours)

* = maximum CPU% # = average CPU%



注释 从IOS12.2(2)T以后思科为show process cpu命令增加了history的选项,这样可以看到最长3天的CPU利用率,而以前最多可以看到5分钟的。输出图很不容易看懂,简单的说最左边是最新的数据,然后历史数据会向右移,在每分钟和每小时的会有峰值和平均值,峰值为现在每列的上端,不过是竖着排列的。

2.16. 生成意外导出文件(Exception Dump Files)

提问 在路由器发生意外当机的情况下生成导出文件发给TAC进行处理

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#ip ftp source-interface Loopback0

Router1(config)#ip ftp username ijbrown

Router1(config)#ip ftp password ijpassword

Router1(config)#exception protocol ftp

Router1(config)#exception region-size 65536

Router1(config)#exception dump 172.25.1.3

Router1(config)#end

Router1#



注释 缺省情况下路由器会使用tftp命令进行传送,不过TFTP有16M的限制所以建议换为FTP协议。另外为了防止当机导致文件不能生成,所以使用了exception region-size 65536 来提前保留部分内存给该命令使用。可以先使用write core命令来提前实验下生成此文件

2.17. 生成接口信息报告

2.18. 生成路由表报告

2.19. 生成ARP表报告

2.20. 生成主机表报告

以上都是使用perl脚本来进行命令输出的汇总操作,脚本略去
第三章用户访问和权限管理


3.1. 设置用户名和密码

提问 为每个单独的人员设置不同的用户名和密码

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#username neoshi password ioscookbook (username weak nopassword)

Router1(config)#aaa new-model

Router1(config)#aaa authentication login local_auth local

Router1(config)#line vty 0 4

Router1(config-line)#login authentication local_auth

Router1(config-line)#exit

Router1(config)#end

Router1#

注释 设置单独的用户名和密码的好处就不用多说了,这里只提一个就是在日志中会显示谁做了修改,比如%SYS-5-RELOAD: Reload requested by kdooley on vty0 (172.25.1.1).另外在username这个命令里面还有一个autocommand的选项,实现登录以后自动执行某个特定的命令的作用,下面的例子就是一个用户名为run无密码,登录以后显示完端口状态就自动退出的例子,很好用吧

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#aaa new-model

Router1(config)#aaa authentication login default local

Router1(config)#aaa authorization exec default local

Router1(config)#username run nopassword noescape

Router1(config)#username run autocommand show ip interface brief

Router1(config)#end

Router1#



3.2. 加密密码

提问 加密密码从而在配置文件中不明文显示

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#enable password oreilly

Router1(config)#line vty 0 4

Router1(config-line)#password cookbook

Router1(config-line)#line con 0

Router1(config-line)#password cookbook

Router1(config-line)#line aux 0

Router1(config-line)#password cookbook

Router1(config-line)#exit

Router1(config)#service password-encryption

Router1(config)#end

Router1#

注释 这种加密方式很弱,很容易被破解

3.3. Using Better Password-Encryption Techniques

提问 使用强度高的加密方式而不是思科缺省的加密技术

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#enable secret ORAbooks

Router1(config)#end

Router1#

在IOS 12.2(8)T后也可以对username的密码做高强度的加密

Router#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#username ijbrown secret oreilly

Router(config)#end

Router#



注释 由于这种加密方式使用的是MD5所以破解难度相对增大了。对于enable secret的密码有个小技巧就是密码设定正常没有?,不过可以通过^V+?的方式来输入。

3.4. 移去配置文件中的密码信息

提问 不想在配置文件中显示密码

回答 使用脚本略去

注释 简单的用show tech命令也可以

3.5. 解密思科的弱密码

提问 破解思科缺省的密码算法

回答 使用脚本略去

注释 可以使用BOSON网站上的免费工具

3.6. 显示当前登录用户

提问 显示当前登录设备的用户

回答

Router1#show users (who)

注释 无

3.7. 发信息给其它用户

提问 试图发送信息给登录在同一设备的其它用户

回答

Router1#send *

Router1#send console 0

Router1#send vty 2

Router1#send 66



注释 很好用的特性,比如当你重启的时候需要告诉别人,文本信息^+Z结束

3.8. 修改可用VTY数目

提问 增加或者减少可登录用户的数目

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line vty 0 9

Router1(config-line)#exit

Router1(config)#end

Router1#



注释 缺省可登录vty数目为5,不能删除,对于增加的可以使用no line vty x 删除,不能不能删除单独的vty,是删除所有大于x的vty

3.9. 修改VTY的超时时长

提问 修改超时避免用户登录超时被系统断开

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line vty 0 4

Router1(config-line)#exec-timeout 0 0 (exec-timeout 240 0)

Router1(config-line)#exit

Router1(config)#end

Router1#



注释 缺省用户10分钟空闲就会被踢掉系统,0 0可以用不超时,第一个0是分钟,第二个0是秒。同时为了防止有些用户掉死但是还占用vty端口的情况,建议使用下面命令来防止:

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#service tcp-keepalives-in

Router1(config)#end

Router1#

3.10. 限制用户登录可以使用的协议

提问 只允许用户用特定的协议来进行系统登录

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line vty 0 4

Router1(config-line)#transport input telnet

Router1(config-line)#exit

Router1(config)#end

Router1#



注释 缺省情况下除了可以telnet登录,还支持以下协议登录lat pad v120 lapb-ta rlogin ssh

3.11. 配置用户登录可用总时长Enabling Absolute Timeouts on VTY Lines

提问 对用户登录总时长进行限制,不论是否在空闲还是活动

回答 Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line vty 0 4

Router1(config-line)#absolute-timeout 5

Router1(config-line)#logout-warning 30

Router1(config-line)#exit

Router1(config)#end

Router1#



注释 无

3.12. 部署Banners

提问 设置登录时显示的警示性信息

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#banner exec # This is an exec banner #

Router1(config)#banner login # This is a login banner #

Router1(config)#banner motd $ This is a motd banner $

Router1(config)#end

Router1#



注释 不用使用welcome之类的字样,下面是一个FBI的路由器登录banner做参考

Router1(config)#banner login #

Enter TEXT message. End with the character '#'.



+--------------------------------------------------------------------+

| WARNING |

| ------- |

| This system is solely for the use of authorized users for official |

| purposes. You have no expectation of privacy in its use and to |

| ensure that the system is functioning properly, individuals using |

| this computer system are subject to having all of their activities |

| monitored and recorded by system personnel. Use of this system |

| evidences an express consent to such monitoring and agreement that |

| if such monitoring reveals evidence of possible abuse or criminal |

| activity, system personnel may provide the results of such |

| monitoring to appropriate officials. |

+--------------------------------------------------------------------+

#

Router1(config)#end

Router1#

3.13. 在特定端口禁用Banners显示

提问 aux口用于modem连接,为了避免出现问题希望关闭banner显示

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line aux 0

Router1(config-line)#no motd-banner

Router1(config-line)#no exec-banner

Router1(config-line)#exit

Router1(config)#end

Router1#



注释

3.14. 禁用Line登录

提问 禁止在AUX或者Line端口进行设备登录

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line aux 0

Router1(config-line)#transport input none

Router1(config-line)#no exec

Router1(config-line)#exec-timeout 0 1

Router1(config-line)#no password

Router1(config-line)#exit

Router1(config)#end

Router1#

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#access-list 98 deny any log

Router1(config)#line vty 0 4

Router1(config-line)#transport input none

Router1(config-line)#exec-timeout 0 1

Router1(config-line)#no exec

Router1(config-line)#access-class 98 in

Router1(config-line)#exit

Router1(config)#end

Router1#



注释 无

3.15. 为管理员保留特定的登录端口

提问 防止所有的登录端口都被占用,为管理员留一个后门

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#access-list 9 permit 172.25.1.1

Router1(config)#line vty 4

Router1(config-line)#access-class 9 in

Router1(config-line)#exit

Router1(config)#end

Router1#

或者

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#access-list 9 permit 172.25.1.1

Router1(config)#line vty 5 7

Router1(config-line)#rotary 25

Router1(config-line)#access-class 9 in

Router1(config-line)#exit

Router1(config)#end

Router1#



注释 在使用第二种rotary命令时就相应的改变登录时的端口号码,不是缺省的23,而是3000+rotary的号码25=3025

3.16. 限制特定地址的Telnet登录

提问 只允许特定的机器进行Telnet登录

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#access-list 99 permit 172.25.1.0 0.0.0.255

Router1(config)#access-list 99 deny any log

Router1(config)#line vty 0 4

Router1(config-line)#access-class 99 in

Router1(config-line)#exit

Router1(config)#end

Router1#

注释 无

3.17. 对Telnet访问进行日志记录

提问 记录每次telnet的日志

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#access-list 90 permit any log

Router1(config)#line vty 0 4

Router1(config-line)#access-class 90 in

Router1(config-line)#exit

Router1(config)#end

Router1#

注释 需要注意的是不管登录成功还是失败,在日志中都是显示的permitted:

%SEC-6-IPACCESSLOGS: list 90 permitted 172.25.1.1 1 packet

3.18. 设置发起Telnet的源地址

提问 有时对端设备有安全设置只允许特定的地址发起telnet请求

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#ip telnet source-interface loopback0

Router1(config)#end

Router1#

或者

Router1#telnet 172.25.1.5 /source-interface loopback0

注释 缺省情况路由器会使用到目的地所使用的端口来做Telnet的源地址

3.19. 自动登录

注释 使用脚本略去,其实用SecueCRT很容易设定

3.20. 使用SSH登录

提问 启用SSH这种加密的登录方式

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#hostname Router1

Router1(config)#ip domain-name neoshi.net

Router1(config)#crypto key generate rsa

The name for the keys will be: Router1.oreilly.com

Choose the size of the key modulus in the range of 360 to 2048 for your

General Purpose Keys. Choosing a key modulus greater than 512 may take

a few minutes.



How many bits in the modulus [512]: 1024

Generating RSA keys ...

[OK]



Router1(config)#

Jun 27 15:04:15: %SSH-5-ENABLED: SSH 1.5 has been enabled

Router1(config)#ip ssh time-out 120

Router1(config)#ip ssh authentication-retries 4

Router1(config)#end

Router1#

注释 从IOS 12.3(4)T开始支持SSH v2,之前只支持v1,首先要确认你的IOS版本,然后确认支持安全特性3DES,才能开启SSH的特性

<!--[if !supportLists]-->3.21. <!--[endif]-->改变IOS命令的特权等级

提问 修改特定IOS命令的特权等级

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#privilege exec level 1 show startup-config

Router1(config)#end

Router1#

注释 缺省情况路由器支持16种特权等级,命令一般归属于0,1和15三种特权等级,在特权等级0下面只支持disable, enable, exit, help, 和logout命令,1下面不能对配置进行修改,15就是enable的特权等级

3.22. 基于用户的特权等级Defining Per User Privileges

提问 给不同的用户赋予不同的特权等级

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#aaa new-model

Router1(config)#aaa authentication login default local

Router1(config)#aaa authorization exec default local

Router1(config)#username neoshi privilege 10 password ioscookbook

Router1(config)#privilege exec level 10 show ip route

Router1(config)#privilege exec level 1 show ip

Router1(config)#privilege exec level 1 show

Router1(config)#end

Router1#

注释 通常的0,1和15三种等级弹性不足,可以定义更多的等级给不同的用户

<!--[if !supportLists]-->3.22. <!--[endif]-->基于端口的特权等级

提问 根据登录的不同端口自动赋予特定的特权等级

回答

Router1#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#line aux 0

Router1(config-line)#privilege level 5

Router1(config-line)#exit

Router1(config)#privilege exec level 5 show ip route

Router1(config)#privilege exec level 1 show ip

Router1(config)#privilege exec level 1 show

Router1(config)#end

Router1#

注释 无