A-A+

思科(Cisco)IOS基本操作命令(一)

2016年01月06日 站长资讯 暂无评论

一、简介

Cisco的网m际操作系统(IOS:Internetwork Operating Syste),IOS配置通常是通过基于文本的命令行接口(Command Line Interface,CLI)进行的。

二、路由其基本操作

1、基本操作模式

1)用户模式

Router> #通常可以查看统计信息

Router>logout #退出用户模式

2)特权模式

Router>enable

Router# #进入特权模式,特权模式是从用户模式进入的;用于产看和修改路由器配置。

router#disable #退出特权模式

3)全局配置模式

Router#configure terminal #进入全局配置模式,全局配置模式从特权模式进入;在全局配置模式中,做的任何修改都会在路由器中生效。

Router#config t 或者 Router#congfigure #这两个简化命令都可以进入全局配置模式

Router(config)#exit #退出全局配置模式,也可以使用快捷键ctrl+z。

2、帮助命令与命令补全

在IOS中,可以使用tab键进行命令补全,用?获取命令帮助,如:

  1. Router#conf               #在这里按tab键  
  2. Router#configure t        #补全为configure,输入t,再按tab键  
  3. Router#configure terminal #补全为configure terminal  
  4.   
  5. Router#c?                 #命令帮助  
  6.    clear  clock   configure  connect  copy  
  7. Router#clock ?  
  8.    set Set the time and date  
  9. Router#clock set ?   
  10.    hh:mm:ss   Current Time  
  11. Router#clock set 11:44:59 ?  
  12.    <1-31>  Day of zhe month  
  13.    MONTH   Month of the year  
  14. Router#clock set 11:44:59 25 ?  
  15.    MONTH   Month of the year  
  16. Router#clock set 11:44:59 25 Apr ?  
  17.    (1993-2035)  Year  
  18. Router#clock set 11:44:59 25 Apr 2015 ?  
  19.     <cr>            #表示按回车键enter  
  20. Router#clock set 11:44:59 25 Apr 2015  
  21. Router#show clock    #查看时间设置  
  22.      *11:44:59.56 UTC Sat 25 Apr 2015  

3、常用快捷键

ctrl+u #从光标所在位置删除到行尾

ctrl+a #光标移动到行首

ctrl+e #光标移动到行尾

4、历史命令

  1. Router#show terminal #查看终端配置与历史命令保存条数  
  2. Router#show history  #查看历史命令  
  3. ↑ ↓ 上下箭头   调用前一个或后一个命令  
  4. Router#terminal history size ?  
  5.     <0-256>   Size of history huffer  
  6. Router#terminal history size 50   #修改历史命令保存条数  

5、查看路由器基本信息

Router#show vesion

三、路由器和交换机的密码管理

1、设置主机名

  1. Router>en  
  2. Router#config t  
  3. Enter configuration commands ,one per line.End with CNTL/Z  
  4. Router(config)#hostname R0  
  5. R0(config)#  

2、设置登录提示信息

1)定义日期信息表记

  1. R0(config)#banner motd I  
  2. Enter TEXT message.End with the character  'I'  
  3. Warning:NO LOADING!  
  4. I               #分割界定符,可以设为任意字符。提示信息可以是任何内容,一般设置警告信息  
  5. R0(config)#no banner motd   #取消日期信息表记  

2)定义登录信息标记

  1. #登录信息表记在motd标记区之后,在用户名和登录提示之前显示  
  2. R0(config)#banner login U  
  3. Enter TEXT message.End with the character  'U'  
  4. NO!  
  5. U  
  6. R0(config)#no banner login  #取消登录信息标记  

3、设置口令

路由器密码

接口密码:设置密码后,登录需先验证密码。

1)console 口密码

本地接口,所以不用密码也可以管理

2)虚拟接口密码

a) telnet 密码

b) ssh 密码

3)aux 接口

特权模式密码

登录之后,执行enable命令,进入特权模式时需要

#conf t

#enable secret 密码

4)设置特权模式密码

R0(config)#enable password 246 #设置特权非密口令

R0(config)#enable secret 342 #设置特权加密口令

#加密密码优先级更高,如果设置了加密码,则非加密密码不可使用

5)设置console端口登录口令

  1. R0(config)#line ?  
  2.   <2-499>   First Line number  
  3.   aux       Auxiliary line  
  4.   console   Primary terminal line  
  5.   tty       Terminal controller  
  6.   .  
  7.   .  
  8.   .  
  9. R0(config)#line consol ?  #设置console口密码,只有一个console口  
  10.   <0-0>    First Line number  
  11. R0(config)#line consol 0  
  12. R0(config-line)#login     #表示进入了接口模式  
  13. %LOgin disable on line 0,until 'password' is set  
  14. #login 是启用密码检查,也是让密码生效。如果没有密码会报错。  
  15.  R0(config-line)#password 123   #设置密码为123  
  16.  R0(config-line)#login         #启用密码检查  

在接口模式中,可以设置回话超时时间

  1. R0(config-line)#exec-timeout 0 0  
  2.   #设定登陆之后多久超时。格式是0分0秒,即永不超时。默认是10分钟不操作会被踢出。  
  3. R0(config-line)#logging synchtonous  
  4.   #阻止控制台信息,避免打扰命令输入  

3)设置telnet登录口令

  1. R0(config)#line vty ?  
  2.   <0-15>   First Line number  
  3. R0(config)#line vty 0 15  
  4. R0(config-line)#password 452  
  5. R0(config-line)#login  
  6. #telnet登录不安全,尽量不使用。  
  7. R0(config-line)#no login    #允许telnet无密码登录(不安全,不允许使用)  

4)密码加密

密码除了Router(config)#enable secret 456是加密保存的,其他密码都是明文保存的,可使用如下密令加密。

R0#show running-config #先查看一下密码,可以看到密码是明文保存的

R0(config)#service password-encryption #开启加密服务,所有的密码都会密文保存

4、SSh登录

1)设置用户名和域名

Router(config)#hostname R0

R0(config)#ip domain-name lamp #修改主机名和域名,生成秘钥时使用,并且必须设置路由时间

2)生成加密秘钥

R0(config)#crypto key generate rsa general-keys modulus 1024 #使用rsa加密,生成1024位秘钥

3)设定登录密码

R0(config)#aaa new-model #启用AAA模式

R0(config)#username cisco password cisco #设定用户名和登录密码

4)设定超时时间、失败次数、版本

  1. R0(config)#ip ssh authentication-retries 5 #设置最大失败次数  
  2. R0(config)#ip ssh time-out 120             #设定ssh超时时间  
  3. R0(config)#ip ssh version 2                #设置ssh版本为SSH2  

5)设定连接线路

R0(config)#line vty 0 988

R0(config-line)#transport input SSH

#仅允许使用ssh登陆,如果还要允许telnet登陆,使用命令:transport input SSH telnet

#远程登录后,特权模式不设置密码是不能登陆特权模式的

四、路由器接口操作

R0#show running-config #查看接口配置,还可以看到路由器有哪些接口,版本,密码设置等。

R0(config)#interface fastEthernet 0/1 #选择接口0/1,进入接口配置模式。其中0代表插槽,1代表端口;有些接口会用0/0/1描述,0代表路由器本身,0代表插槽,1代表端口。

R0(config-if)#description connect to R1 #对接口添加简单的描述

R0#show running-config #可以查看到对接口的描述

do命令:每个命令的执行都必须在特定的命令模式下,如sh run命令就只能在特权模式下还行,否则会报错;但是可以使用do命令让命令在其它模式下执行,如:

  1. R0(config)#do sh run  
  2.   
  3. R0(config)#int f0/1  
  4.    R0(config-if)#no shutdown  #激活端口  
  5.    R0(config-if)#shutdown     #关闭端口  
  6.    R0(config-if)#ip address 192.168.216.124 255.255.255.0  #给接口配置ip 地址  
  7.    R0(config-if)#do sh int f0/1 #用此命令可以查看某一接口的配置信息,此时可以看到f0/1的配置信息  
  8.    R0(config-if)#do sh run   #用此条命令也可以查看,不过会显示所有接口的配置信息  
  9.    时钟频率一般有服务器运营商进行控制,只对串口连接的路由器生效,而现在基本都被光纤接口取代了。如果使用Seria串口,则在DCE(数据通信设备)端需要配置时钟频率,而DTE(数据终端设备)不用配置。  
  10.    R0#show controlles s1/0   #查看s1/0接口情况,是否是DTE或者DCE  
  11.    R0(config)#int s1/0  www.luyouqiwang.com  
  12.    R0(config-if)#clock rate 64000  
  13.    R0(config-if)#do sh contro s1/0  
  14.    #串口设备还可以通过bandwidth命令来配置宽带,注意这个命令的单位是千位。  
  15.    R0(config)#int s1/0  
  16.    R0(config-if)#bandwidth ?  
  17.        <1-10 0000 000>  Bandwidth in kilobits  
  18.    R0(config-if)#bandwidth 1000  

五、保存与删除

1、保存配置

R0#copy running-config startup-config

#running-config是运行配置,保存在DRAM中,重启后会失效。执行此命令会吧running-config复制为startup-config。startup-config是启动配置,保存在NVRAM中,永久生效。

R0#sh startup-config #查看启动配置

2、删除配置

R0#erase startup-config

R0#show startup-config

startup-config is not present

3、重启路由器

R0#reload

六、查看与验证配置

1、 ping ip #探测ip地址是否畅通

2、traceroute 域名或者IP #测试路由路径

3、telnet ip、域名或者端口 #远程管理,或者探测端口

4、查看接口的参数和配置

R0#show interface f0/0

5、清除接口的计数器

R0#clear counters f0/0

6、查看IP信息

R0#sh ip interface

7、查看所有接口的IP地址和状态

R0#show ip interface brief

8、查看所有接口上的协议

R0#show protocols

标签:

给我留言