慈悲ciby

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

思科交换机的基本配置:

工作模式:
  1. 用户模式:
只能查看简单的部分信息,不能做配置。
可以执行一些简单的测试命令如:ping 、 traceroute

ps: 直接输入 ? 回车,可以得到该模式下的所有可用的命令
2. 特权模式:

可以查看所有的配置信息,只能做一些简单,如时间,日期等无关紧要配置的修改。
进入方法:在用户模式下输入:enable (一般简写就行:en)
  1. 全局配置模式:
可以进行配置,对全局生效。
进入方法:在用户模式下输入:configure terminal (一般简写就行:conf t )
  1. 接口配置模式:
对相应的接口进行配置
进入方法:int + 对应的接口:如 int f0/1 (全拼:interface fastEthernet 0/1)
命令:exit 退出当前模式,进入上一级的模式。

当连续的1-3 的接口都需要进行相同的配置时。可以进入有一个范围内的接口进行统一配置。

  1. 控制台模式
控制台模式也叫线模式。在该模式下主要是设置控制台模式下的用户登陆密码。
进入方法:在全局配置模式下输入:line console 0 
  1. 虚拟终端模式
在该模式下主要时配置一个虚拟终端的用户名和登陆秘密。
进入方法: 在全局配置模式下输入: line  vty 0 4 
一些基本的配置:
  1. 两个重要的配置文件
  • running-config: 记录着交换机的配置,在交换机的内存中,重启或重载交换机就会丢失配置。

  • startup-config: 和running-config,也是记录着交换机配置的文件,在交换机的flash/nvrom中,重启或者重载不会丢失,一般新的没有进行配置的交换机,这个文件是没有配置的。

  • 我们在配置时,配置信息是写在running-config 中的。
    交换机在开机时会读取 startup-config 中的配置信息,如果这个文件中没有相关的配置信息,这个交换机就读取不到相关的配置。

  • 当我们进行配置后,需要将runnin-config中的配置信息复制到startup-config中,这样我们在重启交换机或是重载时,我们先前的配置,可以在重启或重载时读取到startup-config 中的配置信息,这样我们的配置就不会丢失。


配置的方法:
方法一:

Switch#copy running-config startup-config // 在特权模式下,进行配置
Destination filename [startup-config]?  // 回车确定
Building configuration...
[OK]
Switch#

方法二:

Switch#write //在特权模式下,直接使用write 
Building configuration...
[OK]
Switch#

清空配置文件startup-config

 Switch# erase startup-config 
Erasing the nvram filesystem will remove all configuration files! Continue? [confirm]
[OK]
Erase of nvram: complete
%SYS-7-NV_BLOCK_INIT: Initialized the geometry of nvram
Switch#
  1. 配置特权模式登陆密码
// 特权密码有两种设置方法,password 和 secret ,建议使用 secret 设置
// secret 设置优先级高(也就是说当你同时用password和secret写入了密码时secret生效),而且密码会使用密文显示

Switch(config)#enable ?     // 两种密码设置方式
 password  Assign the privileged level password
  secret    Assign the privileged level secret
Switch(config)#enable secret 123.com  // 在全局配置模式下设置

配置如下:
配置

登陆验证

  1. 配置控制台模式的登陆密码:

方式一:

Switch>enable       // 进入特权模式
Switch#config t     // 进入全局配置模式
Enter configuration commands, one per line.  End with CNTL/Z.   
Switch(config)#line console 0       // 进入console口配置
Switch(config-line)#password 123.com  // 设置密码
Switch(config-line)#login       // 启用密码 ✳
Switch(config-line)#exit     // 退出到特权模式
Switch#copy running-config startup-config   // 把刚才的配置保存,避免重启后丢失
Switch#reload       // 重启 验证

登陆验证:
登陆验证
方式二:(不只是需要登陆密码,还需要登陆用户名)

Switch(config)#line con 0 //进入控制台模式
Switch(config-line)#login local // 使用本地数据库来验证账密
Switch(config-line)#exit 
Switch(config)#username liuzhouming password 123.com // 在全局配置模式下添加本地的认证用户和密码
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#wri
Switch#write   // 保存刚才的配置,避免丢失
Building configuration...
[OK]
Switch#
Switch#
Switch#
Switch#reload //重载交换机,验证

验证如下:
成功登陆
可以看到我们输入了账密后,成功登陆。

  1. 一些基本的命令总结

给特权模式添加密码

Switch(config)#enable password 123.com // 给特权模式设置密码(在配置文件中是明文)
Switch(config)#enable se
Switch(config)#enable secret 456.com //也是给特权模式设置密码(在配置文件是加密的,使用的是md5加密方式)
Switch(config)# 

关闭控制台模式和虚拟终端模式下的超时踢出功能。

Switch(config)#line console 0
Switch(config-line)#no ex
Switch(config-line)#no exec-timeout //关闭超时踢出功能
Switch(config-line)#exit
Switch(config)#line vty 0 4 
Switch(config-line)#no ex
Switch(config-line)#no exec-timeout 
Switch(config-line)#

将配置文件中的密码都加密
双向加密(type 7) : 命令service password-encryption自动对配置中的密码加密。
没加密之前:

Switch(config)#service password-encryption //加密
Switch(config)#do sh run  // 查看running-config 文件

加密之后

更改主机名

Switch(config)#hostname sw1
sw1(config)#

一些查看命令:
一般实在特权模式下查看,如果想在全局配置模式或者以上的模式使用查看命令show, 在show 前加 do。

sw1# sh ip route   // 查看配置路由表
 
sw1# sh ip int     //查看端口 ip 信息
sw1# sh ip int b   // 查看简要的 ip 端口信息(有接口开启与否的状态信息)
 
router1# sh ip int f0/1 // 思科路由器上查看端口f0/1 的端口IP信息 ,在交换机上不能这样用

sw1# sh int  //  查看端口信息
sw1# show int f0/1 // 查看端口f0/1 的端口信息
sw1# show int f0/1 status;查看指定端口状态
 
sw1# sh vlan   // 查看vlan 表 ,简要查看vlan : sh vlan b 
 
sw1# sh ip access-list   // 查看acl表 
 
sw1# show mac_address table   // 查看mac地址表 
 
sw1# dir flash:   //查看闪存,注意有个“:” 号

sw1# sh vtp status  // 查看vtp的配置信息

sw1# sh running-config // 查看内存中的配置文件
sw1# sh startup-config // 查看初始化配置文件

router1# sh ip nat translations // 在路由器上查看NAT 转换的信息
posted on 2018-12-08 20:51  慈悲ciby  阅读(2114)  评论(1编辑  收藏  举报