交换机常用命令
各种模式之间的切换
Command Mode
Access Method
Prompt
Exit or Access Next Mode
User EXEC
This is the first level of access.(For the switch) Change terminal settings, perform basic tasks, and list system information.
Switch>
Enter the logout command.To enter privileged EXEC mode, enter the enable command.
Privileged EXEC
From user EXEC mode, enter the enable command.
Switch#
To exit to user EXEC mode, enter the disable command.To enter global configuration mode, enter the configure command.
Global configuration
From privileged EXEC mode, enter the configure command.
Switch(config)#
To exit to privileged EXEC mode, enter the exit or end command, or press Ctrl-Z.To enter interface configuration mode, enter the interface configuration command.
Interface configuration
From global configuration mode, specify an interface by entering the interface command followed by an interface identification.
Switch(config-if)#
To exit to privileged EXEC mode, enter the end command, or press Ctrl-Z.To exit to global configuration mode, enter the exit command.
Config-vlan
In global configuration mode, enter the vlan vlan-id command.
Switch(config-vlan)#
To exit to global configuration mode, enter the exit command.To return to privileged EXEC mode, enter the end command, or press Ctrl-Z.
VLAN configuration
From privileged EXEC mode, enter the vlan database command.
Switch(vlan)#
To exit to privileged EXEC mode, enter the exit command.
Line configuration
From global configuration mode, specify a line by entering the line command.
Switch(config-line)#
To exit to global configuration mode, enter the exit command.To return to privileged EXEC mode, enter the end command, or press Ctrl-Z.
用户模式与特权模式
用户模式:可以使用一些基本的查询命令
特权模式:可以对交换机进行相关的配置
切换特权模式
进入特权模式命令
Switch>enable
退出特权模式命令
Switch#disable
查看帮助信息
?
设置时间
Switch#clock set 时间(自选参数。参数必须符合交换机要求)
显示信息命令
Switch#show 可选参数
查看交换机配置
Switch#show running-config
查看端口信息
Switch#show interface
查看MAC地址表:
Switch#show mac address-table
查看交换机CPU的状态信息:
Switch#show processes
注意:可以用TAB键补齐命令,自选参数为用户自定义参数,可选参数为交换机设定参数
保存交换机配置
Switch#copy running-config startup-config
Switch#wr
全局配置模式
切换全局配置模式
进入全局配置模式
Switch#configure terminal
退出配置模式
Switch(config)#exit
设置主机名
主机名修改
Switch(config)#hostname 主机名(自选参数)
取消主机名设置
Switch(config)#no hostname
设置特权模式密码
设置特权模式进入密码
Switch(config)#enable secret 密码(自选参数)
取消特权模式密码:
Switch(config)#no enable secret
显示信息命令
示例: do show *
注意:配置模式中无法使用show命令,如果要使用的话,请使用do show
指定根交换机命令
Switch(config)#spanning-tree vlan 自选参数(VLAN号)
示例:
Switch (config)#spanning-tree vlan 1 root primary
注意:设置根交换机是基于VLAN的
关闭生成树协议命令
Switch (config)#no spanning-tree vlan自选参数(VLAN)
示例:
Switch (config)#no spanning-tree vlan 1
接口配置模式
切换接口配置模式
进入接口配置模式
Switch(config)#interface 端口名称(可选参数)
退出接口配置模式
Switch(config-if)#exit
启用和停用端口
启用端口
Switch(config-if)#no shutdown
停用端口
Switch(config-if)#shutdown
进入多端口配置
进入同类型多端口配置
Switch(config)#interface range fastethernet0/1-5
进入不同类型多端口配置
Switch(config)#interface range fastethernet0/1-5,gigabitethernet 0/
二层端口的配置
端口速率
Switch(config-if)#speed 可选参数
双工模式
Switch (config-if)#duplex可选参数
启用和禁用链路协商
启用链路协商
Switch (config-if)#negotiation auto
禁用链路协商
Switch (config-if)#no negotiation auto
VLAN 的配置
新建VLAN
Switch (config)#vlan 自选参数(VLAN号)
Switch(config-vlan)#name 自选参数(VLAN名)
示例:
Switch (config)#vlan 1
Switch (config-vlan)#name lab1
删除VLAN
Switch#vlan database
Switch(v1an)#no vlan 自选参数(vlan号)
示例:
Switch#vlan database
Switch(v1an)#no vlan 2
将一个接口加入VLAN
Switch(config)#interface 可选参数 (接口号)
Switch (config-if)#switchport mode access
Switch(config-if)#switchport access vlan 自选参数(VLAN号)
Switch(config-if)#no shutdown
Switch(config-if)#exit
示例:
Switch(config)#interface f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 1
Switch(config-if) #no shutdown
Switch(config-if)#exit
将一个接口退出VLAN
Switch(config)#interface 可选参数(接口号)
Switch(config-if)#no switchport access vlan 自选参数(VLAN号)
示例
Switch(config)#interface f0/1
Switch(config-if)#no switchport access vlan 2
配置vlan的ip地址
Switch(config)#interface vlan {Vlan号}
Switch(config-if)#ip address {ip地址} {子网掩码}
示例
Switch(config)#interface vlan 10
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
Switch(config-if)#ip address 192.168.1.1 255.255.255.0
修改一个接口为端口汇聚模式
Switch (config)#interface 可选参数(接口号)
Switch(config-if)#switchport mode trunk
VLAN的验证命令
Switch#show vlan # 显示VLAN列表
Switch#show interface switchport # 查看具体接口的VLAN成员资格信息
Switch#show run # 查看vlan的ip
VTP的配置
VTP Domain Name (VTP域名)
Switch(config)#configure terminal
Switch(config)#vtp domain 自选参数
示例:
Switch (config)#vtp domain Lab_Network
VTP mode (VTP模式)
Switch(config)#vtp mode 可选参数(Server/C1ient/ Transparent)
示例:
Switch (config)#rtp mode Server
VTP Pruning (VIP修剪)
Switch(config)#vtp pruning
注意:有的交换机不支持VTP修剪命令
查看VTP的配置命令
显示交换机运行的VTP模式,配置修订号和交换机所属的VTP域
Switch#show vtp status
显示VTP消息相关的统计数据
Switch#show vtp counters
远程登录交换机设置
配置管理VLAN
Switch(conf)#interface vlan 1 Switch (config-if)#ip address x.x.x.x 255.255.255.0 Switch (config-if)#no shutdown
注意: IP 地址必须与远程连接交换机的PC机地址在同一网段
在交换机上指定默认网关
Switch (config)#ip default-gateway x.x.x.x
注意:指定的默认网关仅当前交换机有效。
将交换机连接PC机的端口加入VLAN 1
Switch(config)#interface 端口号(可选参数) Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 1 Switch(config-if)#no shutdown
配置交换机的远程登录
Switch(config)#line vty 0 4 Switch (config-line)#password 自选参数 Switch (config-line)#login Switch (config-line)#enable secret 自选参数
Last updated
Was this helpful?