【摘要】:操作交换机的命令称为EXEC命令,使用EXEC命令之前必须先登录交换机。为保证交换机的安全,EXEC指令具有二级保护,即为用户模式及特权模式。该模式下可以配置口令保护,在该模式下可以查看交换机的配置信息和调试信息,保存或删除配置文件等。在交换机中还有很多其他的命令规则,都与交换机基本相同,比如命令补齐、简写命令、删除命令、问号帮助命令等。
1.交换机的工作模式
CLI采用多种命令模式以保障系统的安全性。操作交换机的命令称为EXEC命令,使用EXEC命令之前必须先登录交换机。为保证交换机的安全,EXEC指令具有二级保护,即为用户模式及特权模式。在用户模式下只能执行部分指令,在特权模式下可以执行所有指令。
(1)普通用户(User EXEC)模式。
交换机启动后直接进入该模式,在此模式下,用户只能查看交换机的部分系统和配置信息,但不能进行配置。只能输入一些有限的命令,这些命令通常对交换机的正常工作没有什么影响。(nsrjgc是交换机的名称)
普通用户模式的提示符:nsrjgc>
(2)特权用户(Priviledge EXEC)模式。
该模式下可以配置口令保护,在该模式下可以查看交换机的配置信息和调试信息,保存或删除配置文件等。而且特权模式是进入其他模式的关口,欲进入其他模式必须先进入特权模式。在普通用户模式下输入enable命令即可进入特权用户模式, 也可以输入“en”,IOS就会自动识别该命令为“enable”。
nsrjgc>en
Password: ﹗输入特权用户密码,如果没有就输入非特权用户密码,而且它们都不显示输入的内容
nsrjgc#
(3)全局配置(Global Configuration)模式。
特权用户模式下输入configure terminal命令即可进入全局配置模式,在该模式下主要完成全局参数的配置,如设置交换机名、修改特权用户密码、进入一些专项配置状态(如端口配置、VLAN配置)等。
nsrjgc#config terminal
Enter configuration commands, one per line.End with CNTL/Z.
nsrjgc(config)#
(4)接口配置(Interface Configuration)模式。
接口模式可以对交换机的各种接口进行配置,如配置IP地址、数据传输速率、封装协议等。在全局模式下输入interface interface-type 命令,即可进入接口配置模式,其中interface interface-type 为具体某个端口的名称,如fastEthernet0/0。
nsrjgc(config)#int fastEthernet 0/0 //进入F0/0 接口
nsrjgc(config-if)#
nsrjgc(config)#int vlan1 //进入VLAN1接口
nsrjgc(config-if)#
不管在任何模式,用exit命令可返回上一级模式,按“Ctrl+Z”组合键键可返回特权用户模式。
在交换机中还有很多其他的命令规则,都与交换机基本相同,比如命令补齐、简写命令、删除命令、问号帮助命令等。如下就是帮助命令的例子。
nsrjgc(config)#?
Configure commands:
banner Define a login banner
boot Boot Commands
cdp Global CDP configuration subcommands
clock Configure time-of-day clock
do To run exec commands in config mode
enable Modify enable password parameters
end Exit from configure mode
exit Exit from configure mode
hostname Set system's network name
interface Select an interface to configure
ip Global IP configuration subcommands
line Configure a terminal line
mac-address-table Configure the MAC address table
no Negate a command or set its defaults
service Modify use of network based services
spanning-tree Spanning Tree Subsystem
username Establish User Name Authentication
vlan Vlan commands
vtp Configure global VTP state
2.基本接口配置
(1)配置主机名:
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line.End with CNTL/Z.
Switch(config)#hostname nsrjgc
nsrjgc(config)#
(2)配置密码:
nsrjgc(config)#enable secret rjgc //设置特权加密口令rjgc
nsrjgc(config)#enable password 123 //设置非特权加密口令123
nsrjgc(config)#line vty 0 15 //进入虚拟终端
nsrjgc(config-line)#password wlgc //要求口令验证wlgc
nsrjgc(config-line)#login
(3)配置管理地址:
nsrjgc(config)#int vlan 1 //进入VLAN1
nsrjgc(config-if)#ip address 192.168.1.1 255.255.255.0 //给VLAN1划分地址
nsrjgc(config-if)#no shutdown //开启端口
%LINK-5-CHANGED: Interface Vlan1, changed state to up
nsrjgc(config-if)#exit
nsrjgc(config)#ip default-gateway 192.168.1.254 //给交换机设置默认网关
给VLAN1配置管理地址,计算机可以通过Telnet或者Web方式访问该地址。为了允许其他网段的计算机也能通过Telnet访问,在交换机上配置了默认网关。
(4)设置以太网端口的工作模式和速率:
nsrjgc(config)#interface f0/1
nsrjgc(config-if)#duplex ?
auto Enable AUTO duplex configuration //自动检测双工模式
full Force full duplex operation //全双工
half Force half-duplex operation //半双工(www.chuimin.cn)
nsrjgc(config-if)#speed ?
10 Force 10 Mbps operation //10 Mb/s
100 Force 100 Mbps operation //100 Mb/s
auto Enable AUTO speed configuration //自动检测接口速度
(5)端口安全配置常用命令:
nsrjgc(config)#int f0/1
nsrjgc(config-if)#switchport ?
access Set access mode characteristics of the interface
mode Set trunking mode of the interface
native Set trunking native characteristics when interface is in trunking mode
nonegotiate Device will not engage in negotiation protocol on this interface
port-security Security related command
trunk Set trunking characteristics of the interface
voice Voice appliance attributes
nsrjgc(config-if)#switchport port-security ? //设置端口的安全性
mac-address Secure mac address //设置安全MAC地址
maximum Max secure addresses //设置端口允许最多MAC地址数量
violation Security violation mode //设置端口发生安全违规时的举措
nsrjgc(config-if)#switchport port-security violation ?
shutdown Security violation shutdown mode //当端口违规时立即关闭
(6)保存配置:
nsrjgc#copy running-config startup-config
Destination filename [startup-config]?
Building configuration...
[OK]
nsrigc#
(7)清除配置信息:
nsrjgc#erase startup-config
Erasing the nvram filesystem will remove all configuration files! Continue?[confirm]
[OK]
Erase of nvram: complete
%SYS-9-NV_BLOCK_INIT: Initialized the geometry of nvram nsrjgc#
(8)查看配置:
nsrjgc#show running-config
Building configuration...
Current configuration : 1 010 bytes
!
version 12.1
no service password-encryption
!
hostname nsrjgc
!
enable secret 5 $1$mERr$Uh5awwd1NgsF4yapy1AE20 //特权用户加密显示
enable password 123 //非特权明文显示
!
!
!
interface FastEthernet0/1
!
…
interface Vlan1
ip address 192.168.1.1 255.255.255.0 //管理地址
!
ip default-gateway 192.168.1.254 //默认网关
!
line con 0
!
line vty 0 4
password wlgc //登录密码
login
line vty 5 15
password wlgc
login
!
!
习题9
1.交换机的功能是什么?工作原理是什么?
2.交换机是如何分类的?性能指标有哪些?
3.交换机各指示灯代表的含义有哪些?
4.交换机的基本配置方法有哪些?
相关推荐