思科路由器和交换机各种命令

交换机支持的命令:(注:交换机支持命令对应的为思科2系列以上型号的交换机。)

交换机基本状态:

switch: ;交换机的ROM态 rommon> ;路由器的R状态 switch > ;用户模式 switch# ;特权模式 switch(config)# ;全局配置模式

switch(vlan)# 交换机VLAN配置模式 switch(config-if)# ;端口配置模式

switch(config-line)# ; 指定连接状态(console连接 telnet连接)

交换机显示命令:

switch#write ;保存配置信息 switch#show running ;查看当前配置信息 switch#show startup 查看交换机NVROM配置信息 switch#show vlan ;查看vlan配置信息 switch#show vlan-switch 同样为查看vlan配置信息(一些高端交换机比如3系列的交换机必须用这个命令才能查看vlan配置信息) switch#show vtp status 查看VTP配置信息 switch#show interface ;查看所有的端口信息 switch#show interface f0/3 ;查看指定的f0/3快速以太网端口信息

switch#show interfacef0/3 switchport 查看指定的f0/3快速以太网端口trunk信息

switch #show ip inerface brief 用类似表格的形式列出路由器或者交换机接口对应的第三层配置,这个命令是使用频率最高的一个,也是最实用的一个。

switch #show spanning-tree 查看交换机生成树协议情况 switch #show spanning-tree vlan 2 查看交换机VLAN2的生成树协议情况

switch #show spanning-tree interface f0/1 查看交换机F0/1端口生成树协议情况

switch #show cdp 显示交换机当前邻居更新信息 switch #show cdp neighbor ;显示邻居直连路由信息 switch #show cdp neighbor detail 显示邻居直连路由详细信息 switch #show cdp interface 显示所有端口是否开启cdp功能 switch (config-if)#no cdp enable 关闭指定端口的cdp功能 switch (config-if)#cdp enable 打开指定端口的cdp功能 switch (config)#no cdp run 关闭所有端口的cdp功能

switch (config)#cdp run 打开所有端口的cdp功能 switch#show version 查看交换机版本信息

switch#show flash 查看flash里面的IOS信息 switch#show mac-address-table 查看交换机所有端口的MAC

地址信息

switch#show logging 查看交换机日志信息

交换机口令设置:

switch>enable ;进入特权模式 switch#config terminal ;进入全局配置模式 switch(config)#hostname 设置交换机的主机名 switch(config)#enable secret xxx ;设置特权加密口令(真正进入enable特权模式需要输入这个口令)

switch(config)#enable password xxa ;设置特权非密口令 登录console控制台需要输入密码的方法

switch(config)#line console 0 ;进入console控制台口 switch(config-line)#login ;允许登录控制台 switch (config-line)# password xx 设置登陆控制台口口令 switch (config-line)#exec-timeout 0 0 设置控制台口多长时间不操作会自动退出,前面一个0表示分钟 后面一个0表示秒 两个都是0表示一直不会自动退出。

switch(config-line)#logging sy

switch(config-line)#no ip domain-lookup 关闭域名查找功能(如果你输错了命令,switch会认为你输入的是域名,就会查找。。。浪费时间。no ip domain-lookup就是取消这种查找)

登录telnet虚拟终端需只要输入密码的方法

switch(config-line)#line vty 0 4 ;进入telnet虚拟终端 switch(config-line)#login ;允许登录虚拟终端 switch(config-line)#password xx ;设置登录虚拟终端口令xx 登录telnet虚拟终端需要输入用户名和密码的方法

switch (config)#username admin password 12345 设置登录交换机的用户名为admin 密码 12345

switch (config)#line vty 0 4 进去虚拟终端

switch (config-line)#login local 设定通过虚拟终端登录需

要输入用户名

switch#exit ;返回命令

交换机常规配置

switch(config)#no mac-address-table static (需要删掉的mac地址) fastethernet f0/7 清除掉交换机F0/7端口的MAC地址 switch(config-if)#duplex full/halt/auto ;设置交换机端口工作方式 (full全双工 halt半双工模式 auto自动检测)

switch(config-if)#speed 10/100/1000/auto ;设置交换机对应端口局域网交换速度

switch(config)#interface f0/1 进入快速以太网端口端口f0/1 switch(config-if)#description trunkinterface 设置交换机端口描述,描述为trunkinterface

switch(config)#interface vlan 1 ;进入vlan 1

switch(config)#interface range f0/1 – 24 进入快速以太网端口f0/1到f0/24

交换机备份还原文件操作:

switch#copy running-config startup-config 将RAM的当前配置存储到NVRAM switch#copy running-config tftp 备份RAM存储的配置信息到tftp switch#copy startup-config tftp 备份NVRAM配置备份到tftp switch#copy flash tftp ;备份路由器的flash文件IOS到tftp switch#copy tftp startup-config ;恢复NVRAM配置文件 switch#copy tftp running-config 恢复NVRAM配置文件

switch#copy tftp flash: 将flash文件IOS从tftp恢复到路由器 switch#erase startup-config 清除NVRAM存储的配置文件 switch#delete vlan.dat 将所有的VLAN的信息恢复到出厂配

置自建的vlan信息实际上保存在交换机Flash的vlan.dat文件内,该文件不会在删除startup-config的时候被删除,也不会在reload之后清空内容或被删除,需要手动进行清除。

Cisco清除配置使用:erase startup-config(删除NVRAM中的内容),然后重启路由器 reload

交换机生成树协议配置

switch(config)#spanning-tree vlan 2 开启VLAN2的生成树协议 switch(config)#no spanning-tree vlan 2 关闭VLAN2生成树协议 switch(config)#spanning-tree vlan 2 priority 4096 设定这个VLAN2 STP优先级为4096(取值范围为0~61440 之间的4096 的倍数,即取值范围为0、4096、8192…61440. 设定数值越小,优先级越高,交换机默认优先级为32768一个局域网(或者一个VLAN内优先级最低的交换机会成为根交换机) switch(config)#spanning-tree vlan 2 root primary 设定这个交换机为vlan 2的最优先级的交换机,也就是根交换机)

switch(config-if)#spanning-tree vlan 2 port-priority 32 设定这个交换机端口的优先级为32(端口优先级取值范围为0~240 之间的16 倍数,

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4