现在的位置: 首页 > 综合 > 正文

[原创]让我们一起CCNA吧系列文章四:CISCO IOS介绍

2013年12月05日 ⁄ 综合 ⁄ 共 30829字 ⁄ 字号 评论关闭
本系列文章主要针对CCNA 640-801的学习者,学习课程为SYBEX的《Cisco Certified Network Associate Study Guide Fourth Edition》

Introduction to the Cisco IOS

本章思科考试的内容如下:

·配置ip地址,子网掩码,默认网关地址。
·使用附加管理功能配置路由器
·构建一个LAN
·在路由器上进行初始配置
·在交换机上进行初始配置

现在是介绍思科网络操作系统的时候了,Cisco Internetwork Operating
System简称IOS,它在思科的路由器和交换机上运行,它还能让你在上面执行配置操作。在本章你将能够学习到怎样通过初始安装模式和Cisco IOS command-line interface (CLI)来配置思科的路由器。这里是一些本章我们要达到的目标:
·关于IOS的介绍和配置
·连接一个路由器
·启动路由器
·登陆路由器
·弄明白路由器的提示符
·弄明白CLI的提示符
·执行编辑和帮助功能
·搜集基本的路由器信息
·设置管理功能
·设置名称
·设置标识
·设置密码
·设置接口描述
·进行接口配置
·显示,保存,删除配置文件
·确认路由器配置。

The Cisco Router User Interface

Cisco Internetwork Operating System (IOS)思科网络操作系统是思科路由器和交换机的内核。内核是一个操作系统最基本的,不可缺少的部分。它分配资源和管理底层硬件。思科创建了一种叫做CiscoFusion的东西,目标是使得所有的思科设备都运行同样的操作系统,可惜,目前还没有完全实现。通常所有的思科路由器都运行同样的IOS,相对比的是只有半数的交换机运行IOS,不过这个数字增长得很快。
下面,我们将学习怎么样使用安装模式来一步步地配置路由器。再下一个部分我们则使用命令行接口模式来完成同样的任务。

Cisco Router IOS

IOS被用来提供网络服务和启用网络应用程序。它包括了一些重要的功能如下:
·支持网络协议和功能
·在高速数据流量的设备间提供连接
·增加访问控制的安全性并使未被授权的网络停止运行
·提供可伸缩性使网络增长或冗余变的更容易
·为访问网络资源提供可靠性
你可以通过路由器的控制台接口来访问IOS,或者从辅助端口通过一个modem来访问,甚至通过telnet。访问IOS命令行被叫做EXEC会话。

Connecting to a Cisco Router

有三种不同的方法连接路由器,首先你需要连接到控制台接口(console port)
,console port通常位于路由器的背面,是一个RJ-45(8针的模块)接口。默认情况下,console port上没有设置密码。
其次,你也能够通过辅助接口(auxiliary port)来连接路由器。辅助接口能够允许你配置modem命令来支持modem连接到路由器。这是一个非常棒的特性,当路由器出现问题时它能够让你拨号登陆到一个远程的路由器上而不必跑老远的地方。
最后,你能够在网络内通过Telnet来连接路由器任何一个使用中的接口。Telnet是一个终端仿真程序。

Bringing Up a Router

当你第一次启动一个路由器的时候,首先执行power-on self-test (POST)自检,如果自检通过那么从flash存储器中寻找并加载IOS----如果IOS文件存在的话(flash存储器是一种电子可擦写可编程的只读存储器,也叫做EEPROM)。然后IOS寻找并加载有效的配置文件----startup-config,默认情况下配置文件都存放在非易失性内存(NVRAM)里。
当你第一次启动或者重启路由器的时候会出现以下信息:
System Bootstrap, Version 12.2(13)T, RELEASE SOFTWARE (fc1)
Copyright (c) 2000 by cisco Systems, Inc.
C2600 platform with 32768 Kbytes of main memory
这是路由器启动过程第一个部分的输出。当POST开始的时候bootstrap程序的这些信息告诉路由器该怎么加载IOS,默认情况下是在flash存储器里寻找。
找到IOS后把它解压缩到内存里,当解压缩完毕后,IOS开始运行,象下面的显示(注意这里的IOS版本是12.2[13]):
Cisco Internetwork Operating System Software
IOS (tm) C2600 Software (C2600-I-M), Version 12.2(13),
RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2001 by cisco Systems, Inc.
Compiled Tue 17-Dec-03 04:55 by kellythw
Image text-base: 0x80008088, data-base: 0x8080853C

一旦IOS加载完毕并开始运行,接下来将在NVRAM里加载一个有效的配置文件。
如果在NVRAM里没有配置文件,那么路由器将进入安装模式(setup mode),安装模式是一个逐步的过程,来帮助你配置路由器。你也可以在任何时候在特权模式下输入setup命令来进入安装模式。虽然安装模式只有一部分全局命令,但当你不知道怎么去配置一个确定的协议如桥接啊,DECnet啊时会很有用的。

Setup Mode
有两种不同情况的安装模式:基本管理和扩展安装。
基本管理仅仅给你足够的配置以允许路由器的连通性。
扩展安装则给你配置一些全局参数如配置接口参数的能力。
如果想进入安装模式,只需要在下面的情况下回答yes或者y就可以了:
--- System Configuration Dialog ---
Would you like to enter the initial configuration dialog?
[yes/no]:y
At any point you may enter a question mark '?' for help.
Use ctrl-c to abort configuration dialog at any prompt.
Default settings are in square brackets '[]'.

这里告诉了我们如果使用Ctrl+C来退出配置会话,[]里括住的是默认设置。
我们一般选择扩展安装的模式:
Would you like to enter basic management setup?[yes/no]:n

First, would you like to see the current interface
summary? [yes]:[Enter]
Any interface listed with OK? value "NO" does not have a
valid configuration
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned NO unset up up
FastEthernet0/1 unassigned NO unset up up
Configuring global parameters:
Enter host name [Router]:bogy
The enable secret is a password used to protect access
to privileged EXEC and configuration modes. This
password, after entered, becomes encrypted in the
configuration. Enter enable secret:bogy
The enable password is used when you do not specify an
enable secret password, with some older software
versions, and some boot images.
Enter enable password:bogy
% Please choose a password that is different from the
enable secret
Enter enable password:bogy1

这里有一些东西你要注意一下,刚才我们输入了两个密码,它们的作用是不同的,等下我们再详细说。但你要知道的是两个密码中我们只用到了enable secret password。虽然如此你在安装模式中你依然要把两个密码都配了,而且它们不能够一样。
默认情况下enable secret password是用MD5加密的,而enable password是明文显示的。
下面是配置telnet会话密码,因为如果你没有配置这个密码,你将不能够通过telnet来登陆路由器。
The virtual terminal password is used to protect
access to the router over a network interface.
Enter virtual terminal password:bogy
Configure SNMP Network Management? [yes]:[Enter] or [no]
Community string [public]:[no]
Configure DECnet? [no]:[Enter]
Configure AppleTalk? [no]:[Enter]
Configure IP? [yes]:[Enter]
Configure IGRP routing? [yes]:no
Configure RIP routing? [no]:[Enter]
Configure bridging? [no]:[Enter]
Configure IPX? [no]:[Enter]

如果你不知道要使用什么命令来配置协议的时候,上面的命令能够帮助你完成配置。但是如果你在命令行接口下配置,你将获得更多的灵活性。
如果你的路由器上有一个异步信号的modem卡,你也可以配置一下:
Async lines accept incoming modems calls. If you will
have users dialing in via modems, configure these lines.
Configure Async lines? [yes]:n
如果你有一个ISDN BRI的接口,你将被提示配置ISDN的交换类型:
BRI interface needs isdn switch-type to be configured
Valid switch types are:
[0] none..........Only if you don't want to configure BRI
[1] basic-1tr6....1TR6 switch type for Germany
[2] basic-5ess....AT&T 5ESS switch type for the US/Canada
[3] basic-dms100..Northern DMS-100 switch type for US/Canada
[4] basic-net3....NET3 switch type for UK and Europe
[5] basic-ni......National ISDN switch type
[6] basic-ts013...TS013 switch type for Australia
[7] ntt...........NTT switch type for Japan
[8] vn3...........VN3 and VN4 switch types for France
Choose ISDN BRI Switch Type [2]:2

因为这里我们的路由器上只有两个接口:FastEthernet 0/0和FastEthernet 0/1
Configuring interface parameters:
Do you want to configure FastEthernet0/0 interface? [yes]:[Enter]
Use the 100 Base-TX (RJ-45) connector? [yes]:[Enter]
Operate in full-duplex mode? [no]: y and [Enter]
Configure IP on this interface? [yes]:[Enter]
IP address for this interface: 1.1.1.1
Subnet mask for this interface [255.0.0.0]: 255.255.0.0
Class A network is 1.0.0.0, 16 subnet bits; mask is /16
Do you want to configure FastEthernet0/1 interface? [yes]:[Enter]
Use the 100 Base-TX (RJ-45) connector? [yes]:[Enter]
Operate in full-duplex mode? [no]:y and [Enter]
Configure IP on this interface? [yes]:[Enter]
IP address for this interface: 2.2.2.2
Subnet mask for this interface [255.0.0.0]: 255.255.0.0
Class A network is 2.0.0.0, 16 subnet bits; mask is /16

我知道,这些配置都是非常基本的,但它能够帮助你使一个路由器启动并很快运行。配置完成了,现在将显示你刚才创建的运行配置信息:
The following configuration command script was created:
hostname bogy
enable secret 5 $1$B0wu$5F0m/EDdtRkQ4vy4a8qwC/
enable password bogy1
line vty 0 4
password bogy
snmp-server community public
!
no decnet routing
no appletalk routing
ip routing
no bridge 1
no ipx routing
!
interface FastEthernet0/0
media-type 100BaseX
full-duplex
ip address 1.1.1.1 255.255.0.0
no mop enabled
!
interface FastEthernet0/1
media-type 100BaseX
full-duplex
ip address 2.2.2.2 255.255.0.0
no mop enabled
dialer-list 1 protocol ip permit
dialer-list 1 protocol ipx permit
!
end
[0] Go to the IOS command prompt without saving this config.
[1] Return back to the setup without saving this config.
[2] Save this configuration to nvram and exit.
Enter your selection [2]:0

这里有一个有趣的地方,那就是你能够选择进入命令行接口模式并放弃刚才的配置(0),你也能够回头重新再设置一遍(1),也能够保存配置到NVRAM中并退出重启(2)。这里我选择的是0,我们将不保存刚才的配置并进入命令行接口模式(CLI)。接下来我们将介绍CLI。再重复一次,你可以在任何时候按下Ctrl+C来退出安装模式。

Command-Line Interface

因为命令行接口模式(command-line interface CLI)能够提供给我们更多的灵活性,所以当配置一个路由器的时候我们一般都是使用CLI。有时候我把CLI也称为“Cash Line Interface”,如果你能够在CLI下创建一个好的路由器或者交换机的配置,那么你就能拿到现金,嘿嘿。

当问你是否进入setup模式时,选择no,即进入命令行接口模式。
Would you like to enter the initial configuration dialog? [yes]:n
Would you like to terminate autoinstall? [yes]:[Enter]

Logging into the Router

在接口信息出现后你可以按下回车键,现在出现的是Router>提示符。这个也叫做用户模式操作提示符(user mode),一般在这个提示符下看一些基础的统计信息。
在用户模式下使用enable命令来进入特权模式(privileged mode),在特权模式下你可以查看和修改路由器的配置信息。
进入特权模式后提示符变成了Router#,从特权模式退出到用户模式可以使用disable命令,也可以使用exit命令。如果使用logout命令的话则退出控制台会话。

Overview of Router Modes

在特权模式下进入全局配置模式(global configuration mode)则使用configure terminal命令,也可以使用config t缩写,也可以只输入config回车后选择进入全局配置模式,在全局配置模式下你输入的命令对整个路由器都产生作用。所以才叫做全局模式嘛。

CLI Prompts

当配置路由器的时候你要分清各种不同的提示符,这是非常重要的。当你看到提示符的时候你要知道你现在是处在什么模式下。我不会详细介绍各种不同类型的提示符,如果这样做的话不仅浪费了时间而且这也超出了CCNA的考试范围,我们只需要在学习中不断的留意各种提示符出现的位置和相应的功能作用就已经足够了。这个时候你不用担心弄不懂命令提示符,因为等一下我们还要详细地说一说呢,现在把你的注意力集中到不同的提示符上去。

Interfaces
在全局模式下进入接口配置模式,使用interface命令。
Router(config)#interface ?
Async Async interface
BVI Bridge-Group Virtual Interface
CTunnel CTunnel interface
Dialer Dialer interface
FastEthernet FastEthernet IEEE 802.3
Group-Async Async Group interface
Lex Lex interface
Loopback Loopback interface
MFR Multilink Frame Relay bundle interface
Multilink Multilink-group interface
Null Null interface
Serial Serial
Tunnel Tunnel interface
Vif PGM Multicast Host interface
Virtual-Template Virtual Template interface
Virtual-TokenRing Virtual TokenRing
range interface range command
Router(config)#interface fastethernet 0/0
Router(config-if)#

你注意到了么?当你进入接口配置模式后提示符变成了Router(config-if)#。难道不能给出一个更好的提示符描述来告诉我们什么接口需要配置了么?是的,至少现在是的(难道这就是为什么思科的管理员通常都比windows的管理员拿更多money的一个原因?或许这能够使我们看起来更加聪明一点吧,^-^)有一点是可以肯定的:在配置一个路由器的时候你需要更加集中注意力。

Subinterfaces

字接口允许你在路由器的接口上创建一个逻辑的接口。子接口的提示符是Router(config-subif)#。

Router(config)#int fastethernet0/0.?
<0-4294967295> FastEthernet interface number
Router(config)#int fastethernet0/0.1
Router(config-subif)#

Line Commands

为了配置用户模式的密码,我们在全局模式下使用line命令。这时提示符变成了Router(config-line)#

Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#line ?
<0-70>   First Line number
aux     Auxiliary line
console   Primary terminal line
tty     Terminal controller
vty     Virtual terminal
x/y     Slot/Port for Modems

Router(config)#line console 0
Router(config-line)#

Routing Protocol Configurations

配置路由协议如RIP或者IGRP时,我们在提示符(config-router)#下使用命令。

Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router rip
Router(config-router)#

Editing and Help Features

你可以使用思科高级编辑特性来帮助你配置路由器。如果你在任何提示符下输入一个question mark (?)号,你将看到在这种模式下可以使用的所有命令。

Router#?
Exec commands:
access-enable Create a temporary Access-List entry
access-profile Apply user-profile to interface
access-template Create a temporary Access-List entry
bfe For manual emergency modes setting
clear Reset functions
clock Manage the system clock
configure Enter configuration mode
connect Open a terminal connection
copy Copy configuration or image data
debug Debugging functions (see also 'undebug')
disable Turn off privileged commands
disconnect Disconnect an existing network connection
enable Turn on privileged commands
erase Erase flash or configuration memory
exit Exit from the EXEC
help Description of the interactive help system
lock Lock the terminal
login Log in as a particular user
logout Exit from the EXEC
mrinfo Request neighbor and version information
from a multicast router
--More—

在这里你可以使用空格键来显示下一页或者用回车键来显示下一行。当你不想继续看下去的时候你可以按下其他任意键如Q来退出显示并返回提示符。

当你不记得一个命令是c开头但是不记得完整的名称时你可以在c后面紧跟一个?来显示所有c开头的命令。
Router#c?
clear clock configure connect copy

如果一个命令是由几个单词组成的,你可以在第一个单词后面跟着一个空格和一个?号来显示接着的命令单词。

Router#clock ?
set Set the time and date
Router#clock set ?
hh:mm:ss Current Time
Router#clock set 10:30:10 ?
<1-31>   Day of the month
MONTH   Month of the year
Router#clock set 10:30:10 28 ?
MONTH   Month of the year
Router#clock set 10:30:10 28 august ?
<1993-2035> Year
Router#clock set 10:30:10 28 august 2003 ?
<cr>
Router#

当你输入了一个不完整的命令如:Router#clock set 10:30:10时,路由器会响应
% Incomplete command,这样你就可以知道命令没有完全输入了。而当你输入了错误的命令时,路由器显示Router(config)#access-list 110 permit host 1.1.1.1
^
% Invalid input detected at '^' marker. 注意到了那个小小的^符号了吗?这个符号非常有用,它可以指示你的输入是从哪里开始错误的。

路由器支持命令缩写,比如show可以缩写为sh,sho,如果是这样的提示:
Router#sh te
% Ambiguous command: "sh te"

那么说明了有多个命令以sh te开头,sh te并不是唯一的命令所以路由器不能执行。在sh te后面使用?号来找出你需要的完整命令

Router#sh te?
tech-support template terminal

下面显示了一些思科路由器上可以使用的增强编辑命令。
1.Ctrl+A:把光标快速移动到整行的最开始
2.Ctrl+E:把光标快速移动到整行的最末尾
3.Esc+B:后退1 个单词
4.Ctrl+B:后退1 个字符
5.Esc+F:前进1 个单词
6.Ctrl+F:前进1 个字符
7.Ctrl+D:删除单独1 个字符
8.Backspace:删除单独1 个字符
9.Ctrl+R:重新显示1 行
10.Ctrl+U:擦除1 整行
11.Ctrl+W:删除1 个单词
12.Tab:自动补齐命令
13.Up arrow 或者Ctrl+P:显示之前最后输入过的命令
14.Down arrow 或者Ctrl+N:显示之前刚刚输入过的命令

这里tab键是一个非常非常有用的功能,它可以自动帮你完成命令的输入,爽吧。

你也能够使用下面的一些命令来回顾你曾经输入过的命令。

1.show history:显示最后输入的10 条命令,默认是10 条,可以修改该值。

2.terminal history size:修改显示最后输入过的的命令的数量,默认是10 条,最大是256 条。

3.show terminal:显示命令历史缓存大小,如下:
Router#sh terminal
(略)
History is enabled,history size is 10
(略)

Router#terminal history size ?
<0-256> Size of history buffer

Router#terminal history size 25

Router#sh terminal
(略)
History is enabled,history size is 25
(略)

Gathering Basic Routing Information

show version命令能够显示系统硬件的基本配置和软件版本,以及配置文件的名字和来源,还有启动镜象,最后是configuration register的值。

Router#sh version
Cisco Internetwork Operating System Software
IOS (tm) C2600 Software (C2600-BIN-M), Version 12.2(13)T1,RELEASE SOFTWARE(fc1)
TAC Support:
http://www.cisco.com/tac
Copyright (c) 1986-2003 by cisco Systems, Inc.
Compiled Sat 04-Jan-03 05:58 by ccai
Image text-base: 0x80008098, data-base: 0x80C4AD94

上面的输出是关于在路由器上运行的IOS的信息,接下来的部分是ROM的信息

ROM: System Bootstrap, Version 11.3(2)XA4, RELEASE SOFTWARE (fc1)

接下来是显示路由器已经运行了多长时间,和它重启的时候从哪里加载IOS,和IOS的名称,默认从FLASH里加载。(如果你看到一个system restarted by bus 错误,这将是一件非常糟糕的事情)

Router uptime is 1 week, 2 hours, 39 minutes
System returned to ROM by reload
System image file is "flash:c2600-bin-mz.122-13.T1.bin"

接下来是处理器,DRAM的容量和FLASH容量,和在POST的时候检测到的接口

cisco 2621 (MPC860) processor (revision 0x101) with 27648K/5120K bytes of memory
Processor board ID JAB0402040J (2308906173)
M860 processor: part number 0, mask 49
Bridging software.
X.25 software, Version 3.0.0.
2 FastEthernet/IEEE 802.3 interface(s)
2 Serial network interface(s)
32K bytes of non-volatile configuration memory.
8192K bytes of processor board System flash (Read/Write)
Configuration register is 0x2102

最后是configuration register的数值,这将在第九章详细说明。

Router and Switch Administrative Functions

虽然接下来的内容不是使路由器和交换机在网络上工作的关键,但依然是很重要的。我将带领你学习一些配置命令,这能够帮助你管理你网络。

你在路由器和交换机上能够配置的管理功能是:
·Hostnames
·Banners
·Password
·Interface descriptions
记住,这些都不能够使你的路由器或者交换机工作得更好或更快,但相信我它们能够使你的工作生活变得更美好,只要花一点点时间来配置你的设备就可以了,,因为它们能够帮助你在检查故障和维护网络时非常非常容易,何乐而不为呢。

Hostnames
你能够使用hostname命令来给路由器设置一个标识。这个标识只是在本地有意义而已,跟你的路由器进行名称解析什么的没有关系。
这里是一个例子:
Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname Todd
Todd(config)#hostname Atlanta
Atlanta(config)#
给路由器起个和该路由器有一定联系的名称能使你在网络中寻找它变得更容易。

Banners
标识能够在别人telnet或者拨号到路由器上给出一些提示如安全警告等,或者也可以写上一些让别人要注意的东西。有几种不同类型的banner:
exec process creation banner,incoming terminal line banner,login banner, and message of the day banner。下面给出例子来一一说明:

Router(config)#banner ?
LINE     c banner-text c, where 'c' is a delimiting character
exec     Set EXEC process creation banner
incoming   Set incoming terminal line banner
login     Set login banner
motd     Set Message of the Day banner

Message of the day (MOTD)是一个被广泛使用的标识。当别人拨号或者telnet甚至通过控制台接口来连上你的路由器时它能够给出一些消息。

Router(config)#banner motd ?
LINE c banner-text c, where 'c' is a delimiting character
Router(config)#banner motd #
Enter TEXT message. End with the character '#'.
If you are not authorized to be in Acme.com network, then you must disconnect immediately.
#
Router(config)#^Z
Router#
00:25:12: %SYS-5-CONFIG_I: Configured from console by console
Router#exit

Router con0 is now available
Press RETURN to get started.

If you are not authorized to be in Acme.com network, then
you must disconnect immediately.
Router>

这里你要知道的一个知识点是分界符,上面我们用#号来作为输入信息的分界符,但是要知道的是你可以使用任何字符来代替#号。举个例子:
Router(config)#banner motd x Unauthorized access prohibited!
x
当你输入完信息后按回车,输入分界符,再次回车。好,现在你已经设置完毕MOTD。分界符不会出现在显示的信息中。

Exec banner:这个标识主要出现在EXEC处理中如VTY线路,加一句,telnet就是通过VTY线路来登陆路由器的。但是只有在控制台接口上开始一个用户执行会话才能出现这个标识。

Incoming banner:这个标识则出现在反向telnet线路上。

Login banner:这个标识在MOTD标识的后面出现,但是要早于login的提示符。它能够在所有连接的终端上显示。要取消可以使用no banner login命令。

Setting Passwords

在路由器上有五种不同类型的密码:
·console
·auxiliary
·telnet (VTY)
·enable password
·enable secret password

如果你设置了enable password或者enable secret password的话,当你在用户模式使用enable命令进入特权模式时会提示你输入密码。
另外三种分别是当你从console port控制台接口,auxiliary port辅助接口或者telnet登陆时起作用。

Enable Passwords

Router(config)#enable ?
last-resort   Define enable action if no TACACS servers respond
password     Assign the privileged level password
secret       Assign the privileged level secret
use-tacacs     Use TACACS to check enable passwords

Last-resort:如果你设置了身份验证服务器但服务器没有工作时允许你还能够登陆路由器。但是如果身份验证服务器正常工作的时候则不起作用。

Password: 设置密码,如果设置了enable secret密码的话这个密码就不起作用了。

Secret:更新的,MD5加密过的密码。如果设置了的话,它会取代enable password。

Use-tacacs:这个参数告诉路由器通过TACACS服务器来进行身份认证。如果你有许多路由器的话使用这个功能会非常便利,想象一下,你会觉得到几百个路由器上一个个设置密码是很有趣的事情吗?如果你精神正常我觉得你不会去做这种事情的。所以我们只需要在TACACS服务器上修改一次就可以马上改变所有路由器的密码。

enable secret和enable password的密码不能相同,如下:
Router(config)#enable secret bogy
Router(config)#enable password bogy
The enable password you have chosen is the same as your enable secret. This is not recommended. Re-enter the enable password.

下面我们继续用例子来说明aux(auxiliary的缩写),console,vty的密码配置。

Auxiliary Password

Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#line aux ?
<0-0> First Line number
Router(config)#line aux 0
Router(config-line)#login
Router(config-line)#password bogy

要注意login命令,如果你没有使用这个命令那么将不会提示身份认证。
新版的思科路由器做了更贴心的改进:
2600A#config t
Enter configuration commands, one per line. End with CNTL/Z.
2600A(config)#line aux 0
2600A(config-line)#login
% Login disabled on line 65, until 'password' is set
2600A(config-line)#

如果你没有先输入密码,那么路由器不给你输入login命令,这是因为如果你设置了login但是忘记输入密码的话会不能访问到该线路的。不过要记住,这个新的特性在新版IOS(12.2及以上版本)才出现,老版本不支持。

Console Password

Router(config-line)#exit
Router(config)#line console ?
<0-0> First Line number
Router(config)#line console 0
Router(config-line)# password bogy1
Router(config-line)# login

因为只有一个console接口,所以我们使用line console 0命令来配置。

虽然你可以在所有的线路上配置相同的密码,但是出于安全考虑,建议你还是使用不同密码的好。

关于console port还有一些重要的命令你必须知道:
1. exec-timeout 0 0命令把EXEC会话的超时设置为0,意味着永远都不会超时。
默认的超时时间是10秒,如果你想恶作剧的话,可以在某人的路由器上设置exec-timeout 0 1 。当1秒后没有任何命令输入那么路由器会退出会话,你将要重新登陆!如果你很有空的话,可以没事就按一按下箭头键来防止超时,嘿嘿。

2.logging synchronous 这是一个非常cool的命令,因为路由器经常会有一些讨厌的信息间隔出现,当你输入一个很长的命令到一半被打断了的话,我想你会觉得很痛苦的,使用logging synchronous命令可以解决这个问题,你输入了一半的命令会在间隔消息的下面出现,而不是上面一段下面一段的。

下面是例子:
Router(config)#line con 0
Router(config-line)#exec-timeout ?
<0-35791> Timeout in minutes
Router(config-line)#exec-timeout 0 ?
<0-2147483> Timeout in seconds
<cr>
Router(config-line)#exec-timeout 0 0
Router(config-line)#logging synchronous

Telnet Password

line vty来设置telnet会话的密码。默认情况下普通的IOS版本支持5条VTY线路从0---4。如果是企业版本的话可以支持更多。如果你不能确定有多少条线路的话可以使用?号来帮助你。

Router(config-line)#line vty 0 ?
<1-4> Last Line Number
<cr>
Router(config-line)#line vty 0 4
Router(config-line)# password todd2
Router(config-line)# login

如果你没有设置VTY线路的密码,那么会出现什么情况呢?

Router#telnet SFRouter
Trying SFRouter (10.0.0.1)...Open
Password required, but none set
[Connection to SFRouter closed by foreign host]
Router#

如果你想telnet的路由器上面没有设置VTY (telnet)密码的话,你就不能登陆上去,但是如果你telnet不想输入密码的话也可以,使用no login命令就可以了。

提醒一下,当你能ping一个路由器而不能telnet时,最大的可能就是路由器没有设置VTY密码。

Encrypting Your Passwords

因为默认情况下只有enable secret 密码是加密了的。当你使用show running-config命令来显示运行中的配置时你会发现其他的密码都是明文显示的。

Router#sh running-config
[output cut]
!
enable secret 5 $1$rFbM$8.aXocHg6yHrM/zzeNkAT.
enable password bogy1
!
[output cut]
line con 0
password bogy1
login
line aux 0
password bogy
login
line vty 0 4
password bogy2
login
!
end
Router#

为了安全起见,你可以使用service password-encryption来加密这些密码。

Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#service password-encryption

然后我们再看看:

Router#sh run
Building configuration...
[output cut]
!
enable secret 5 $1$rFbM$8.aXocHg6yHrM/zzeNkAT.
enable password 7 0835434A0D
!
[output cut]
!
line con 0
password 7 111D160113
login
line aux 0
password 7 071B2E484A
login
line vty 0 4
password 7 0835434A0D
login
line vty 5 197
password 7 09463724B
login
!
end

看到了吧,虽然不是MD5加密,但也能够起到一定的作用了。要取消加密可以使用
no service password-encryption命令。

Descriptions

在接口上设置描述可以帮助管理。象hostname一样,接口descriptions也是本地性的。

Atlanta(config)#int e0
Atlanta(config-if)#description Sales Lan
Atlanta(config-if)#int s0
Atlanta(config-if)#desc Wan to Miami circuit:6fdda4321

设置接口描述后你可以使用show run或者show interface命令来看看。

Atlanta#sh run
[cut]
interface Ethernet0
description Sales Lan
ip address 172.16.10.30 255.255.255.0
no ip directed-broadcast
!
interface Serial0
description Wan to Miami circuit:6fdda4321
no ip address
no ip directed-broadcast
no ip mroute-cache

Atlanta#sh int e0
Ethernet0 is up, line protocol is up
Hardware is Lance, address is 0010.7be8.25db (bia
0010.7be8.25db)
Description: Sales Lan

Router Interfaces

在路由器配置中接口配置是一个很重要的内容。如果没有接口,路由器根本就不能完成任何工作。另外,接口配置必须要完整精确,以使得其他设备能够正常通信。关于接口配置我们要学习使用一些命令来配置网络地址,介质类型,带宽以及其他管理命令。

不同的路由器使用不同的方法来选择接口进行使用。下面的例子是一台Cisco 2522 路由器,它有10个串行接口(serial port)标号从0到9。

Router(config)#int serial ?
<0-9> Serial interface number

我们使用interface type number命令来配置不同类型的接口,配置串行接口我们用interface serial命令,配置以太网接口我们使用interface ethernet命令。

2500路由器是一种混合型配置的路由器,混合型意味着你可以根据需要在路由器上面添加新的功能模块。当然,新的模块是要用钱去买di。

在一些其他的路由器如2600,3600, 4000,和7000系列,因为这里路由器里面使用了物理插槽,插槽上插着不同端口号码的模块,所以我们的配置接口命令要小小的变化一下,我们用interface type slot/port来配置:

Router(config)#int fastethernet ?
<0-1> FastEthernet interface number
Router(config)#int fastethernet 0
% Incomplete command.
Router(config)#int fastethernet 0?
/
Router(config)#int fastethernet 0/?
<0-1> FastEthernet interface number

看到了没有,这里你不能使用int fastethernet 0来配置,而是必须使用interface type slot/port这样的格式来配置如interface fastethernet 0/0,或者缩写成int fa 0/0也可以。

如果想配置连接器的类型可以使用media-type命令,不过这通常都是自动检测的,很少需要配置。

Router(config)#int fa 0/0
Router(config-if)#media-type ?
100BaseX   Use RJ45 for -TX; SC FO for -FX
MII     Use MII connector

Bringing Up an Interface

你可以通过使用shutdown命令来关闭一个接口(这里说的关闭不是物理上的,你可以理解成禁用),如果想启动的话可以使用no shutdown命令。

如果一个接口被关闭的话,它会显示administratively down管理性关闭,使用show interfaces(或者缩写为sh int也可以)命令来看一下:

Router#sh int ethernet0
Ethernet0 is administratively down, line protocol is down
[output cut]

另外一种检查接口的办法是用show running-config命令。默认情况下所有的接口都是关闭的。

启动关闭的接口使用no shutdown(或者no shut)命令。

Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int ethernet0
Router(config-if)#no shutdown
Router(config-if)#^Z
00:57:08: %LINK-3-UPDOWN: Interface Ethernet0, changed state to up
00:57:09: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0, changed state to up

Router#sh int ethernet0
Ethernet0 is up, line protocol is up
[output cut]

Configuring an IP Address on an Interface

在接口上配置ip地址,我们用ip address address mask命令。

Router(config)#int e0
Router(config-if)#ip address 172.16.10.2 255.255.255.0
Router(config-if)#no shut

一定要记住,配完ip地址后用no shut命令来启动接口。用sh int e0命令来看看e0是否administratively shut down。当然sh run命令也可以。

如果你想在一个接口上配置第二个ip地址,你可以用secondary参数,如果不用这个参数的话,你输入的新ip地址会取代原来设置的ip地址。

Router(config-if)#ip address 172.16.20.2 255.255.255.0 secondary
Router(config-if)#^Z

我们检查一下:
Router#sh run
Building configuration...
Current configuration:
[output cut]
!
interface Ethernet0
ip address 172.16.20.2 255.255.255.0 secondary
ip address 172.16.10.2 255.255.255.0
!

好了,虽然我建议你不要在一个接口上使用多重ip地址,因为它非常之没有效率。但无论如何我还是得告诉你这些知识以防万一某天你碰到了一个恋爱中的MIS管理者(恋爱中的通常都会变得有点傻)设计的糟糕网络让你管理!也可能会有人问你关于多重ip的事情,如果你知道更多这些知识那不是更好吗?

Serial Interface Commands

在你开始配置一个串行接口(serial interface)前有一些东西要知道一下。
首先,串行接口通常都接在一个CSU/DSU类型的设备上,这个设备提供线路时钟信号给路由器。但如果你在一个back-to-back的配置环境中(通常都是在实验室里)一端---data communication equipment (DCE)数据通信设备,必须提供时钟信号,因为这里没有CSU/DSU设备。默认情况下,所有的思科路由器都是data terminal equipment (DTE)数据终端设备,所以你必须告诉接口要象DCE设备那样提供时钟信号。

配置一个DCE串行接口使用clock rate命令。

Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int s0
Router(config-if)#clock rate ?
Speed (bits per second)
1200
2400
4800
9600
19200
38400
56000
64000
72000
125000
148000
250000
500000
800000
1000000
1300000
2000000
4000000
<300-4000000> Choose clockrate from list above

Router(config-if)#clock rate 64000
%Error: This command applies only to DCE interfaces
Router(config-if)#int s1
Router(config-if)#clock rate 64000

当你尝试把一个clock rate放到一个接口上并不会造成任何破坏,clock rate命令是位每秒的(bits per second.bps)。如果你不知道一个接口是否有DCE缆线接着你可以使用show controllers int命令来查看。

Router>sh controllers s 0
HD unit 0, idb = 0x297DE8, driver structure at 0x29F3A0
buffer size 1524 HD unit 0, V.35 DCE cable

看到DCE了么?这说明了s0接口要提供时钟信号。

下一个你需要了解的命令是bandwidth。思科所有的路由器默认情况下串行接口线路的bandwidth带宽都是T1(1.544Mbps),但是这个带宽并不是通常意义上我们说的传输数据的带宽,这个串行线路的带宽一般用来给路由协议如IGRP,EIGRP和OSPF等来计算什么是到达远程网络的最好路径的。所以如果你使用RIP这样的距离向量路由协议那么带宽设置就更本没有意义。因为RIP只是使用跳数来决定最好路径。呵呵,这里说路由协议你可能会一头雾水,但是没有关系,下一章我们就要学习到了。

下面我们看看配置带宽的例子:

Router(config-if)#bandwidth ?
<1-10000000> Bandwidth in kilobits
Router(config-if)#bandwidth 64

要和clock rate区别的是,bandwidth使用千位(kilobits)而clock rate使用bit。一个是64000 ,一个是64。

Viewing, Saving, and Erasing Configurations

当你在安装模式下运行的时候,你会被问到是否保存配置,通常运行配置(running-config)在DRAM中,而启动配置(startup-config)保存在NVRAM中。

你可以手动的使用copy running-config startup-config命令来把配置文件从DRAM中保存到NVRAM中去。当然你也可以使用copy run start缩写。

Atlanta#copy run start
Destination filename [startup-config]?[Enter]
Warning: Attempting to overwrite an NVRAM configuration
previously written by a different version of the system image.
Overwrite the previous NVRAM configuration?[confirm][Enter]
Building configuration...

你可以在特权模式下使用show running-config(sh run)或者show startup-config(sh start)来查看配置文件。

show running-config显示的是当前运行的配置:

Atlanta#sh run
Building configuration...
Current configuration:
!
version 12.0
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname Atlanta
ip subnet-zero
frame-relay switching
!
[output cut]

show startup-config显示的是保存在NVRAM中的配置:
注意一下:sh start命令还能告诉我们NVRAM已经用了多少空间来保存配置文件。
Atlanta#sh start
Using 4850 out of 32762 bytes
!
version 12.0
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname Atlanta
!
!
ip subnet-zero
frame-relay switching
!
[output cut]

如果你想删除启动配置文件那么可以使用erase startup-config命令。

Atlanta#erase startup-config
Erasing the nvram filesystem will remove all files!
Continue? [confirm][Enter]
[OK]
Erase of nvram: complete
Atlanta#sh start
%% Non-volatile configuration memory is not present

Atlanta#reload

当你删除了启动配置文件后,使用reload命令重启路由器或者关掉电源再开,这时你将被提示是否进入安装模式(setup mode),因为这时候在NVRAM中没有任何配置信息。 你可以在任何使用使用Ctrl+C来退出安装模式。reload命令只能够在特权模式下使用。

Verifying Your Configuration

显然,show running-config时查看你当前配置的最好方法,而show startup-config则是查看路由器重启后使用的配置的最好方法,对吗?

好,当你查看了running-config并觉得没有什么问题了,然后你可以通过一些办法来确认一下。如使用ping和telnet。Ping(Packet Internet Groper)是一个使用ICMP echo请求和答复的程序。当你ping一个主机,主机能够回应的时候,你可以确定该主机在运行。但你却不知道它是否运行得好啊,就象你能够ping一台NT主机但并不能登陆它一样的道理。虽然如此,Ping在检测网络故障时还是很有用处的。

你知道在路由器上能够ping多少种协议吗?当然你能,只要你在用户模式或者特权模式下输入ping ?

Router#ping ?
WORD     Ping destination address or hostname
appletalk Appletalk echo
decnet   DECnet echo
ip       IP echo
ipx     Novell/IPX echo
srb     srb echo
<cr>

如果你需要知道一个邻居设备的网络层地址(例如ip地址)时,你可以到该邻居路由器或者邻居交换机上查看,也可以通过使用show cdp entry *或者show cdp detail命令来查看你将要ping的邻居的网络层地址。(至于Cisco Discovery Protocol [CDP]我们将在第九章学习)

Traceroute使用ICMP和IP的time to live (TTL)超时来检查一个数据包通过网络的路径。这里要提一下的就是traceroute可以简写成trace,但是不能写成tracer,这个是windows下的程序。

Telnet是一个非常好的工具,它使用网络层的IP和传输层的TCP来和远程设备建立会话。如果你能够telnet上一个设备,那么你的IP连通性肯定没有问题。你可以使用ip地址或者设备名称来telnet远程设备。

Router#telnet ?
WORD IP address or hostname of a remote system
<cr>

在路由器的提示符下,你可以只输入hostname或者ip来进行telnet,而不用在前面加上telnet命令。

Verifying with the show interface Command

在路由器上输入show interface命令将显示所有可以配置的接口。

Router#sh int ?
Async       Async interface
BVI         Bridge-Group Virtual Interface
CTunnel       CTunnel interface
Dialer       Dialer interface
FastEthernet   FastEthernet IEEE 802.3
Loopback     Loopback interface
MFR         Multilink Frame Relay bundle interface
Multilink     Multilink-group interface
Null         Null interface
Serial       Serial
Tunnel       Tunnel interface
Vif         PGM Multicast Host interface
Virtual-Template Virtual Template interface
Virtual-TokenRing Virtual TokenRing
accounting     Show interface accounting
crb Show     interface routing/bridging info
dampening     Show interface dampening info
description   Show interface description
irb         Show interface routing/bridging info
mac-accounting Show interface MAC accounting info
mpls-exp     Show interface MPLS experimental accounting info
precedence     Show interface precedence accounting info
rate-limit     Show interface rate-limit info
summary       Show interface summary
switching     Show interface switching
| Output modifiers
<cr>

值得注意的是,这里只有FastEthernet,Serial和async是真实的物理接口,其它的都是逻辑接口。

show interface fastethernet 0/0这条命令可以显示接口的硬件地址,逻辑地址,封装类型和冲突统计等。

Router#sh int fastethernet 0/0
FastEthernet0/0 is up, line protocol is up
Hardware is AmdFE, address is 00b0.6483.2320 (bia 00b0.6483.2320)
Description: connection to LAN 40
Internet address is 192.168.1.33/27
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input never, output 00:00:04, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes
Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog
0 input packets with dribble condition detected
84639 packets output, 8551135 bytes, 0 underruns
0 output errors, 0 collisions, 16 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out

上面的输出中特别要注意的地方就是第一行
Router#sh int fa0/0
FastEthernet0/0 is up, line protocol is up
两个up表明了FastEthernet 0/0接口已经启动并正常运行。

其中第一个参数跟物理层有关,当接口能够接收到载波检测时就会显示up。
第二个参数跟数据链路层有关,如果有从连接的另一端有keepalive信号时就显示up。(Keepalives 被用来在设备之间确认连通性)

而当显示这样时:
Router#sh int s0/0
Serial0/0 is up, line protocol is down

line已经up了但是protocol是down的。这很可能是时钟(keepalive)或者组帧问题。检查线路两端的设备以确定是否keepalives不一致,时钟频率(clock rate)是否设置,如果需要还可以检查两端的封装类型是否一致,出现这种情况可以考虑是数据链路层的问题。

Router#sh int s0/0
Serial0/0 is down, line protocol is down

象这样两个都down了的话,一般是缆线或者接口出问题了。这是物理层的故障。
还有一种可能是如果有一端被管理性的关闭(administratively shut down)那么另一端也可能会出现上面这种情况。

Router#sh int s0/0
Serial0/0 is administratively down, line protocol is down

我们看到Serial0/0被管理性的关闭了,要启动它可以在接口配置模式下使用no shutdown命令。

下面这条命令show interface serial 0/0显示了串行线路和最大传输单元(maximum transmission unit (MTU))的值默认是1500字节。还有思科路由器的默认带宽(BW):1.544Kbps。另一个需要注意的是keepalive,默认是10秒。路由器每10秒发送一次keepalive信息到邻居路由器上,如果两个路由器没有设置相同的keepalive时间,它们将不能工作。

Router#sh int s0/0
Serial0/0 is up, line protocol is up
Hardware is HD64570
MTU 1500 bytes, BW 1544 Kbit, DLY 20000 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation HDLC, loopback not set, keepalive set
(10 sec)
Last input never, output never, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 0/75, 0 drops
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes, 0 no buffer
Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored,
0 abort
0 packets output, 0 bytes, 0 underruns
0 output errors, 0 collisions, 16 interface resets
0 output buffer failures, 0 output buffers swapped out
0 carrier transitions
DCD=down DSR=down DTR=down RTS=down CTS=down

你也可以在接口用clear counters命令来清除记数。

Router#clear counters ?
Async Async interface
BVI Bridge-Group Virtual Interface
CTunnel CTunnel interface
Dialer Dialer interface
FastEthernet FastEthernet IEEE 802.3
Group-Async Async Group interface
Line Terminal line
Loopback Loopback interface
MFR Multilink Frame Relay bundle interface
Multilink Multilink-group interface
Null Null interface
Serial Serial
Tunnel Tunnel interface
Vif PGM Multicast Host interface
Virtual-Template Virtual Template interface
Virtual-TokenRing Virtual TokenRing
<cr>

Router#clear counters s0/0
Clear "show interface" counters on this interface
[confirm][Enter]
Router#
00:17:35: %CLEAR-5-COUNTERS: Clear counter on interface
Serial0 by console
Router#

Verifying with the show ip interface Command

show ip interface命令能够提供关于路由器接口的OSI第三层(网络层)的信息给你。

Router#sh ip interface
FastEthernet0/0 is up, line protocol is up
Internet address is 1.1.1.1/24
Broadcast address is 255.255.255.255
Address determined by setup command
MTU is 1500 bytes
Helper address is not set
Directed broadcast forwarding is disabled
Outgoing access list is not set
Inbound access list is not set
Proxy ARP is enabled
Security level is default
Split horizon is enabled
[output cut]

上面输出的信息包括了接口的ip地址和掩码。访问控制列表(access list)的信息,不管有没有配置访问控制列表。还有一些基本的IP信息。

Using the show ip interface brief Command

show ip interface brief是一个非常有用的命令,它提供了一个快速浏览路由器接口ip地址和接口状态的方法。

Router#sh ip int brief
Interface     IP-Address     OK? Method Status       Protocol
FastEthernet0/0 192.168.1.33   YES manual up           up
FastEthernet0/1 10.3.1.88 YES   manual up             up
Serial0/0     10.1.1.1 YES   manual up             up
Serial0/1     unassigned YES NVRAM administratively down down

Verifying with the show protocols Command

show protocols也是一个非常有用的命令,使用这个命令可以快速看到每个接口的层1和层2的状态,还有ip地址。

Router#sh protocols
Global values:
Internet Protocol routing is enabled
Ethernet0/0 is administratively down, line protocol is down
Serial0/0 is up, line protocol is up
Internet address is 100.30.31.5/24
Serial0/1 is administratively down, line protocol is down
Serial0/2 is up, line protocol is up
Internet address is 100.50.31.2/24
Loopback0 is up, line protocol is up
Internet address is 100.20.31.1/24

Using the show controllers Command

show controllers命令显示了关于物理接口的信息。它也能够让你知道插在串行接口上的缆线的类型。通常DTE的缆线只能插在data service unit (DSU)上。

Router#sh controllers serial 0/0
HD unit 0, idb = 0x1229E4, driver structure at 0x127E70
buffer size 1524 HD unit 0, V.35 DTE cable
cpb = 0xE2, eda = 0x4140, cda = 0x4000

Router#sh controllers serial 0/1
HD unit 1, idb = 0x12C174, driver structure at 0x131600
buffer size 1524 HD unit 1, V.35 DCE cable
cpb = 0xE3, eda = 0x2940, cda = 0x2800

注意到了吗?serial 0/0插的是DTE的缆线,而serial 0/1插的是DCE的缆线,这意味着Serial 0/1接口必须用clock rate命令来提供时钟信号。而Serial 0/0将从DSU那里获取时钟信号。

Summary

这是有趣的一章,我告诉了你许多关于Cisco IOS的知识,并希望你能够更多的了解思科路由器的世界。本章从介绍IOS开始,然后告诉你怎么样使用IOS来配置路由器。你学习了怎么样启动一个路由器和安装模式,呵呵自从你能够基本地配置一个路由器我想你根本不会使用安装模式的,对吗~

然后我介绍了怎么通过console口来连接路由器,介绍了思科的帮助特性和怎么样在CLI下用?来找出命令和命令参数。另外我还介绍了一些基本的show命令来帮助你确认你的配置。

管理功能能够帮助你更好的管理网络。设置路由器密码是一件非常重要的事情,我们学习了五种不同的密码类型和设置方法。另外我们还使用了hostname,interface description和banners来帮助更好的管理路由器。

好,以上就是我们学习到的IOS的基本内容,在你以后的学习中这些知识都要经常用到,所以请你确定你已经掌握了,如果答案是否的话,别介意,请回头多看一遍。

                                    6:13 2005-3-28

抱歉!评论已关闭.