1. 基本配置命令

Switch >enable       进入特权模式
Switch #config terminal         进入全局配置模式

Switch (config)#hostname  XXX      设置交换机主机名为XXX

Switch(config)#enable password            进入特权模式的密码(明文形式保存)
Switch(config)#enable secret               加密密码(加密形式保存,优先)
Switch(config)#ip default-gateway           配置交换机网关
Switch(config)#show mac-address-table      查看MAC 地址
Switch(config)logging synchronous          阻止控制台信息覆盖命令行上的输入
Switch(config)no ip domain-lookup          关闭DNS 查找功能

Switch(config)exec-timeout 0 0            阻止会话退出                                        

 

2. 使用Telnet远程管理

Switch (config)#line vty 0 4    进入虚拟终端
Switch (config-line)# password     设置登录口令
Switch (config-line)# login    要求口令验证
 

3. 控制台口令

switch(config)#line console 0    进入控制台口
switch(config-line)# password  xxx   设置登录口令
switch(config-line)# login    允许登录
 

4. Cisco发现协议(CDP

Switch(config)#show cdp                        显示Cisco设备全局配置信息

Switch(config)#show cdp interface 端口            查看CDP配置下端口信息

Switch(config)#show cdp neighbors                显示直连Cisco设备信息

 Switch(config)#show cdp neighbors detail           查看邻居详细信息
 
 

5. 恢复出厂配置

Switch(config)#erase startup-config
Switch(config)delete vlan.dat
 

6. 配置接口标识, 用于区分交换机,路由器的各个接口

switch(config)#interface fastethernet 0/1       0/1 接口为例

switch(config)# description toMill2            端口描述为“到二厂”

 
 

7. Vtp配置

switch(config)#vtp domain        设置vtp 域名
switch(config)#vtp password       设置vtp 密码

switch(config)#vtp mode server /client/transparent  设置vtp服务器模式

switch(config)#vtp version         设置vtp 版本
switch(config)#vtp pruning         启用vtp 修剪
: 要想从vtp 中减少一台交换机,只需将该交换机vtp 域名更改即可。
 

8. Vlan基本配置

  Switch#vlan database                         进入vlan配置模式

  Switch(vlan)#vlan 号码 name 名称             创建vlanvlan

  Switch(vlan)#vlan号码 mtu数值               修改MTU大小

switch(vlan)#apply

  Switch(vlan)#exit                             更新vlan数据并退出

  Switch#show vlan                            查看验证

  Switch#copy running-config startup-config        保存配置

 
 

9. VLAN 中添加 删除端口

Switch#config terminal                       进入全局配置

Switch(config)#interface fastethernet0/1         进入要分配的端口

Switch(config-if)#Switchport mode access        定义access端口,也就是二层端口

Switch(config-if)#Switchport acces vlan        把端口分给一个vlan

Switch(config-if)#switchport mode trunk         设置端口为trunk口(干线)

Switch(config-if)#switchport trunk encapsulation dot1q    设置vlan 中继协议(cisco 2960系列默认使用802.1q协议封装

 

Switch(config-if)#no switchport mode ( switchport mode access)    禁用干线

Switch(config-if)#switchport trunk allowed vlan add 12        Trunk中添加vlan

Switch(config-if)#switchport trunk allowed vlan remove 12     Trunk中删除vlan

Switch(config-if)#switchport trunk pruning vlan remove 12  Trunk中关闭局部修剪

 

Switch#show vlan brief              查看所有vlan信息

Switch#show vlan id                  查看某个vlan 的信息
 
 

10. 查看trunk协议

Switch#show int trunk                查看trunk端口

        

   Trunk

  开启(no           ——将端口设置为永久中继模式
  关闭(off          ——将端口设置为永久非中继模式, 并且将链路转变为非中继链路
  企望(desirable )——让端口主动试图将链路转换成中继链路
  自动(auto        ——使该端口愿意将链路变成中继链路
 
注:可以使用default interface interface-id 还原接口到默认配置状态
 
配置接口为动态协商模式:
Switch(config)#interface 接口号
Switch(config)#switchport mode dynamic  desirable/auto
 
 
11. 以太网通道配置

switch(config)#interface range fasternet0/1 - 2    fasternet0/10/2 口捆绑

switch(config-if)#channel-group 1 mode on    配置以太通道模式

switch(config-if)#port-channel load-balance {dst-mac | src-mac}在链路间实现负载均衡

switch#show etherchannel  1  summary    查看通道信息

switch#show etherchannel  load-balance    查看通道信息
 

12. 交换机显示命令:

switch#show vtp status    查看vtp 配置信息
switch#show running-config    查看当前配置信息
switch#show vlan    查看vlan 配置信息
switch#show interface    查看端口信息
switch#show int f0/0    查看指定端口信息
switch#dir flash:    查看闪存
switch#show version    查看当前版本信息
switch#show cdp    cisco 设备发现协议
switch#show cdp traffic    杳看接收和发送的cdp 包统计信息
switch#show cdp neighbors    查看与该设备相邻的cisco 设备
switch#show interface f0/1 switchport            查看有关switchport 的配置
switch#show cdp neighbors                     查看与该设备相邻的cisco 设备
 
 

13. 生成树协议spanning-tree protocol

Switch(config-if)#spanning-tree portfast    配置速端口(连接终端设备的端口状态)如pc

Switch#show spanning-tree summary    检测vlan 生成树配置

Switch#show spanning-tree vlan detail    浏览详细生成树配置信息

Switch#show spanning-tree interface detail    浏览详细生成树端口配置信息