路由器是工作在OSI参考模型第三层——网络层的数据包转发设备。路由器通过转发数据包来实现网络互连。虽然路由器可以支持多种协议(如TCP/IP IPX/SPXAppleTalk等协议),但是在我国绝大多数路由器运行TCP/IP协议。路由器通常连接两个或多个由IP子网或点到点协议标识的逻辑端口,至少拥有1个物理端口。路由器根据收到数据包中的网络层地址以及路由器内部维护的路由表决定输出端口以及下一跳地址,并且重写链路层数据包头实现转发数据包。路由器通过动态维护路由表来反映当前的网络拓扑,并通过与网络上其他路由器交换路由和链路信息来维护路由表。路由器设备厂商最有名的是Cisco公司,以下是Cisco路由器配置的常用命令汇总,希望对正在学习和应用思科路由器的你有帮助。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

启动接口,分配IP地址:

router>
router> enable
router#
router# configure terminal
router(config)#
router(config)# interface Type Port
router(config-if)# no shutdown
router(config-if)# ip address IP-Address Subnet-Mask
router(config-if)#
z

配置RIP路由协议:30秒更新一次

router(config)# router rip
router(config-if)# network Network-Number <--
通告标准A,B,C类网-->
router(config-if)#
z

配置IGRP路由协议:90秒更新一次

router(config)# router igrp AS-Number <-- AS-Number 范围165535-->
router(config-if)# network Network-Number <--
通告标准A,B,C类网-->
router(config-if)#
z

配置Novell IPX路由协议:Novell RIP 60秒更新一次

router(config)# ipx routing [node address]
router(config)# ipx maximum-paths Paths <--
设置负载平衡,范围1512-->
router(config)# interface Type Port
router(config-if)# ipx network Network-Number [encapsulation encapsulation-type] [secondary] <--
通告标准A,B,C类网-->
router(config-if)#
z

配置DDR

router(config)# dialer-list Group-Number protocol Protocol-Type permit[list ACL-Number]
router(config)# interface bri 0
router(config-if)# dialer-group Group-Number
router(config-if)# dialer map Protocol-Type Next-Hop-Address name Hostname Telphone-Number
router(config-if)#
z

配置ISDN

router(config)# isdn swith-type Swith-Type

<-- 配置ISDN交换机类型,中国使用basic-net3-->

router(config-if)# z


配置Frame Relay

router(config-if)# encapsulation frame-relay [cisco   IEtf ]
router(config-if)# frame-relay lmi-type [ansi
  cisco   q933a ]
router(config-if)# bandwidth kilobits
router(config-if)# frame-relay invers-arp [ Protocol ] [dlci ]
<--
配置静态Invers ARP表:
router(config)# frame-relay Protocol Protocol-Address DLCI [ Broadcast ] [ ietf
  cisco ] [ payload-compress   packet-by-packet ]
-->
<--
设置Keepalive间隔:
router(config-if)# keepalive Number
-->
<--
为本地接口指定DLCI
router(config-if)# frame-lelay local-dlci Number
-->
<--
子接口配置:
router(config-if)# interface Type Port.Subininterface-Number [ multipoint
  point-to-point ]
router(config-subif)# ip unnumbered Interface
router(config-subif)# frame-lelay local-dlci Number
-->
router(config-if)#
z

配置标准ACL

router(config)# access-list Access-List-Number [ permit   deny ] source [ source-mask ]
<-- Access-List-Number
范围:
1
99标准ACL100199扩展ACL800899标准IPX ACL
900
999扩展IPX ACL1000~1099 IPX SAP ACL600699Apple Talk ACL-->
router(config)# interface Type Port
router(config-if)# ip access-group Access-List-Number [ in
  out ]
router(config-if)#
z

配置扩展ACL

router(config)# access-list Access-List-Number [ permit   deny ] [ Protocol   Protocol-Number ] source source-wildcard [ Source-Port ] destination destination-wildcard [ Destination-Port ] [ established ]
router(config)# interface Type Port
router(config-if)# ip access-group Access-List-Number [ in
  out ]
router(config-if)#
z

配置命名ACL

router(config)# ip access-list [ standard   extended ] ACL-Name
router(config [ std-
  ext- ] nacl)# [ permit   deny ] [ IP-Access-List-Test-Conditions ]
router(config [ std-
  ext- ] nacl)# no [ permit   deny ] [ IP-Access-List-Test-Conditions ]
router(config [ std-
  ext- ] nacl)# z
router(config)# interface Type Port
router(config-if)# ip access-group [ACL-Name
  1~199 ] [ in   out ]
router(config-if)#
z

配置DCE时钟:

router# show controllers Type Port <-- 确定DCE接口-->
router(confin-if)# clock rate 64000 <--
进入DCE接口设置时钟速率-->
router(config-if)#
z

配置PPP协议:

router(config)# username Name passWord Set-Password-Here <-- 验证方建立数据库-->
router(config)# interface Type Port
router(config-if)# encapsulation ppp <--
启动PPP协议-->
router(config-if)# ppp outhentication [ chap
  chap pap   pap chap   pap ] <--选择PPP认证-->
router(config-if)# ppp pap sent-username Name password Password <--
发送验证信息-->
router(config-if)#
z

 

 

PAP单向认证配置实例:

验证方:

router-server(config)# username ClIEnt passWord 12345 <-- 验证方建立数据库-->
router-server(config)# interface serial 0
router-server(config-if)# encapsulation ppp
router-server(config-if)# ppp authentication pap <--
选择使用PAP实现PPP认证-->
router-server(config-if)#
z

被验证方:

router-client(config-if)# encapsulation ppp
router-client(config-if)# ppp pap sent-username Client password 12345 <--
发送验证信息-->
router-client(config-if)#
z

PAP双向认证配置实例:

路由器 A

routerA(config)# username B password 12345
routerA(config)# interface serial 0
routerA(config-if)# encapsulation ppp
routerA(config-if)# ppp authentication pap
routerA(config-if)# ppp pap sent-username A password 54321
routerA(config-if)#
z

路由器 B

routerB(config)# username A password 54321
routerB(config)# interface serial 1
routerB(config-if)# encapsulation ppp
routerB(config-if)# ppp authentication pap
routerB(config-if)# ppp pap sent-username B password 12345
routerB(config-if)#
z

CHAP单向认证配置实例:

验证方:

router-server(config)# username router-client password 12345
router-server(config)# interface serial 0
router-server(config-if)# encapsulation ppp
router-server(config-if)# ppp authentication chap
router-server(config-if)#
z

被验证方:

router-client(config-if)# encapsulation ppp
router-client(config-if)# ppp authentication chap
router-client(config-if)# ppp chap hostname router-client
router-client(config-if)# ppp chap password 12345
router-client(config-if)#
z

 CHAP双向认证配置实例:

路由器 A

routerA(config)# username routerB passWord 12345
routerA(config)# interface serial 0
routerA(config-if)# encapsulation ppp
routerA(config-if)# ppp authentication chap
routerA(config-if)# ppp chap hostname routerA
routerA(config-if)# ppp chap password 54321
routerA(config-if)#
z

路由器 B

routerB(config)# username routerA password 54321
routerB(config)# interface serial 1
routerB(config-if)# encapsulation ppp
routerB(config-if)# ppp authentication chap
routerB(config-if)# ppp chap hostname routerB
routerB(config-if)# ppp chap password 12345
routerB(config-if)#
z

Telnet使用:

routerA# terminal monitor <-- 可以传回在远端主机执行Debug命令的结果-->
routerA# telnet IP-Address [ Router-Name ] <--Telnet
到指定的地址或名字的主机-->
routerB# [ exit
  logout ] <--退出Telnet-->
routerB# <6>
再按 <--挂起Telnet-->
routerA# show sessions <--
显示当前所有Telnet的信息,包括Connect-Number -->
routerA# Connect-Number <--
返回指定的Telnet连接-->
routerA# disconnect IP-Address [ Router-Name ] <--
断开指定地址或名字的主机的连接-->
routerA# show user <--
显示Telnet到本机的连接信息-->
routerA# clear line [ 0
  1   2   3   4 ] <--断开指定Telnet到本机的连接-->

禁止任何Telnet到本机:

router(config)# line vty 0 4
router(config-line)# access-class ACL-Number
router(config)#
z

设置主机名:

router(config)# hostname Set-Hostname
router(config)#
z
router(config)#
z

设置用户模式密码:

router(config)# line console 0
router(config-line)# login
router(config-line)# password Set-Password
router(config-line)#
z

 

                 
设置Telnet密码:

router(config)# line vty 0 4
router(config-line)# login
router(config-line)# passWord Set-Password
router(config-line)#
z

设置特权模式密码:

router(config)# enable password Set-Password <-- 不加密的密码,明码-->
router(config)# enable secret Set-Password <--
经过加密的密码-->
router(config)#
z

给所有密码加密:

router(config)# service password-ancryption Set-Password-Here
router(config)# no service password-ancryption <--
取消加密-->
router(config)#
z

设置登录Banner

router(config)# banner motd 分隔符 Set-Banner-InFORMation-Here 分隔符 <--前后分隔符一定要一致-->

设置接口的描述信息:

router(config-if)# description Set-Port-InFORMation-Here
router(config)#
z

CDP的控制:

router(config-if)# cdp enable <-- 在指定端口启用CDP,缺省-->
router(config-if)# no cdp enable <--
在指定端口关闭CDP-->
router(config)# cdp run <--
使所有端口启用CDP-->
router(config)# no cdp run <--
使所有端口关闭CDP-->

Ping的使用:

router# ping IP-Address
router# ping <--
扩展Ping命令-->
Protocol [ip]
[ Protocol-Type ] <--选择协议类型-->
Target IP address
IP-Address <--输入测试地址-->
Repeat count [5]
<--选择发送的ICMP包数量-->
Datagram size [100]
<--选择每个包的大小-->
Timeout in seconds [2]
<--设置每个包的超时时间-->
Extended commands [n]
y <--使用扩展Ping命令-->
Sweep range of sizes [n]

Tracke的使用:

router# trace IP-Address [ Host-Name ]

Cisco 4000路由器指定媒体类型:

router(config-if)# media-type 10baset
<--
使AUI(默认)失效,改为使用RJ-45-->
router(config-if)#
z

 更改路由器启动顺序:

router(config)# boot system Flash IOS-FileName
router(config)# boot system tftp IOS-FileName TFTP-IP-Address
router(config)# boot system rom
router(config)#
z

修改寄存器数值:

router(config)# config-register value <--Cisco 出厂默认value0x2102value范围:0x2100(进入ROM监视器),0x2101(使系统从ROM启动), 0x21020x210F(使系统从NVRAM启动)。0x10x2101,从最小位开始改变-->

ROM监视器中更改寄存器数值:

> o/r value

路由器密码的恢复:

> o/r 0x2142 <--25xx 型路由器--> > confreg 0x2142 <--16xx型路由器-->
router> I
router> n
router> enable
router# copy startup-config running-config
router# configure terminal
router(config)# enable secret New-PassWord
router(config)# config-register 0x2102
router(config)#
z
router# copy running-config startup-config
router# reload

冷关机,然后再开机并在60秒内按< Ctrl> 进入ROM监视器模式

配置名称-主机入口:

router(config)# ip host Set-Name [ TCP-Port-Number ] IP-Address [ IP-Address 2 ] ...
router(config)#
z

定义DNS主机:

router(config)# ip name-server Server-Address [ Server-Address 2 ] ...
router(config)#
z

禁用DNS

router(config)# no ip domain-lookup
router(config)#
z

配置水平分割:

router(config-if)# ip split-horizon
router(config-if)# no ip split-horizon
router(config-if)#
z

 配置静态路由:

router(config)# ip route IP-Address Subnet-Mask [ Next-Hop-Address   Local-Out-Port ] [Distace ]
<--Distance
范围:1255,相当于优先权,越小越好。RIP=120DSPF=110IGRP=100EIGRP=90-->
router(config)#
z

配置缺省路由:

router(config)# ip defoult-network IP-Address <-- 动态缺省路由-->
router(config)# ip route 0.0.0.0 0.0.0.0 [ Next-Hop-Address
  Local-Out-Port ] [Distace ] <--静态缺省路由-->
router(config)#
z

其它命令:

router# show version
router# show running-config
router# show startup-config
router# show Flash
router# show interface [ Type Port ]
router# show buffers
router# show protocol
router# show mem
router# show stacks
router# show processes
router# show cdp entry [ Device-Name ] <--
显示指定邻居三层信息-->
router# show cdp neighbors
router# show cdp neighbors detail <---
显示所有邻居三层信息->
router# show ip router
router# show ipx router
router# show host
router# show ip protocol
router# show ip interface Type Port
router# show ipx interface Type Port
router# show ipx servers
router# show ipx traffic
router# show access-lists [ ACL-Number ]
router# show isdn status
router# show dialer <--
查看ISDN拨号信息-->
router# show isdn active
router# show frame-relay pvc
router# show frame-relay map
router# show frame-relay lmi
router# erase startup-config
router# reload
router# setup
router# copy running-config startup-config
router# copy startup-config running-config
router# copy tftp running-config
router# copy running-config tftp
router# debug ipx routing activity
router# debug ipx sap
router# debug isdn q921
router# debug isdn q931
router# debug dialer
router# debug ip rip
router# clear interface bri [ 0
  1   2 ]