Cisco 交换机基本配置命令及学习心得
1:配置登录用户,口令等
Switch> //用户直行模式提示符
Switch>enable //进入特权模式
Switch# //特权模式(配置密码后必须输入密码才可进入特 权模式)
Switch#config terminal //进入全局配置模式
Switch(config)# //配置模式提示符
Switch(config)#hostname xxx //设置主机名成为xxx这里使用CISCO 2960G
CISCO 2960G(config)#enable password xxx //设置使能口令为明文显示为xxx
CISCO 2960G(config)#enable secret xxx //设置使能口令为密文显示为xxx
CISCO 2960G(config)#line vty 0 15 //设置虚拟终端线,通过telnet方式 登录允许0-15个用户同事登录
CISCO 2960G(config-line)#login //设置远程telnet远程登录验证
CISCO 2960G(config-line)#password xxx //设置telnet登录密码
2:cisco2960 VLan设置
CISCO 2960G> enable //进入特权模式
CISCO 2960G#vlan database //进入vlan设置
CISCO 2960G(vlan)#vlan 2 name xxx //创建vlan 2,并给vlan命名
CISCO 2960G(vlan)#no vlan 2 v //删除vlan 2
CISCO 2960G(vlan)#exit //回到特权模式下
端口设置命令:
CISCO 2960G(config)#interface fastethernet0/1 //进入网口1,简化命令 int f0/1 ,0/1指的是第一个插槽上的第一个网口
CISCO 2960G(config-if)# //接口视图模式
CISCO 2960G(config-if)#shutdown //关闭当前端口
CISCO 2960G(config-if)#no shutdown //打开当前端口
CISCO 2960G(config)#interface gigabyte0/1 //进入汇聚千兆口1,简化命令 int giga0/1指的是第一个插槽上的第一个汇聚网口
CISCO 2960G(config-if)#
CISCO 2960G(config-if)#duplex auto/full/half //设置端口工作模式为 自适应/全双通/半双通
CISCO 2960G(config-if)#switchport mode trunk //设置当前端口模式为汇聚口
CISCO 2960G(config-if)#switchport mode access //设置当前端口模式为接入模式
CISCO 2960G(config-if)#switchport trunk allowed vlan 1,2 //设置当前汇聚端口允许vlan1,2通过,vlan修剪,默认为all,全部允许
CISCO 2960G(config-if)#switchport trunk vlan 2 //设置当前汇聚端口允许vlan 2通过,vlan修剪
CISCO 2960G(config-if)#switchport access vlan 2 //将当前端口加入到vlan 2中
CISCO 2960G(config-if)#switchport trunk encap dot1q //设置vlan中继
将端口加入vlan
CISCO 2960G(config)#interface fastethernet0/1
CISCO 2960G(config-if)#switchport mode access
CISCO 2960G(config-if)#switchport access vlan 2
将多个端口加入到VLAN中
CISCO 2960G(config)#interface range f0/1 - 10
CISCO 2960G(config-if-range)#switchport mode access
CISCO 2960G(config-if-range)#switchport access vlan 2
CISCO 2960G#show vlan brief //用于查看配置后结果
CISCO 2960G#show vlan //用于查看配置后结果
3:设置VTP cisco专有的vlan终极协议也成为局域网干道协议,作用是十几台交换机在企业网中,配置VLAN工作量大,可以使用VTP协议,把一台交换机配置成VTP Server, 其余交换机配置成VTP Client,这样他们可以自动学习到server 上的VLAN 信息
switch(config)#vtp domain xxxx //设置发vtp域名
switch(config)#vtp password xxxx //设置发vtp密码
switch(config)#vtp mode server //设置发vtp模式为 vtp服务器
switch(config)#vtp mode client //设置发vtp模式为 vtp客户端
4:交换机配置IP地址
switch(config)#interface vlan 1 //进入vlan 1
switch(config-if)#ip address 119.167.223.221 255.255.255.128 //设置交换机的管理ip地址
switch(config)#ip default-gateway 119.167.223.254 //设置交换机的默认网关
switch(config)#end //退出当前模式
5: 交换机保存设置命令
switch#write //保存配置信息
switch#copy running-config startup-config //将当前正在使用中的配置保存到交换机开机需要加载的配置文件里去。
6:交换机显示命令
特权模式下:
switch#show vtp //显示vtp配置信息
switch#show run //显示当前配置信息
switch#show running-config //显示当前正在使用的配置信息
switch#show startup-config //交换机开机是自动加载的 配置文件
switch#show vlan //显示vlaner配置信息
switch#show interfaces //显示端口配置信息
switch#show interfaces fastethernet 0/1 switchport //显示二层端口状态,可以用来决定此口是否为二层或三层口
switch#show int f0/1 //查看指定端口配置信息 show interface fastethernet0/1
switch#show ip interface vlan100 //查看交换机vlan100的ip配置信息
switch#show version //查看交换机固件版本信息
7:基于端口的mac地址绑定
switch#config terminal //进入配置视图模式
switch(config)#interface fasrethernet 0/1 //进入具体端口视图模式下
switch(config-if)#switchport port-secruity //配置端口安全模式
switch(config-if)#switchport port-secruity mac-address MAC(主机的mac地址) //配置该端口要绑定的主机的MAC地址
switch(config-if)#no switchport port-secruity mac-address MAC(主机的mac地址) //删除绑定主机的mac地址
8:配置交换机的snmp功能
switch(config)#snmp-server community xxx ro //xxx为自定义的共同体名称,并且团体的权限为只读。
switch(config)#snmp-server trap-source FastEthernet0/3/0 //设置snmp监控的端口,此端口必须要配置IP地址才行
switch(config)#snmp-server trap-source vlan 100 /把vlan 100接口作为监控端口
switch(config)#snmp-server host x.x.x.x(ip地址) xxx(团体名) //设置管理机x.x.x.x,同时允许该管理机以团体明xxx访问。
switch(config)#snmp-server host 119.167.223.221 zy //例子
switch(config)#snmp-server enable traps //启用snmp服务
9:交换机禁ping配置
switch(config)#access-list 110 deny icmp any any //配置访问控制列表(Access Control List,ACL)110指的ICMP对应ping。
switch(config)#access-list 110 permit ip any any //运行所有的IP协议的应用
switch(config)#int vlan 1
switch(config-if)#ip access-group 110 in
switch(config)#int vlan 2
switch(config-if)#ip access-group 110 in
switch(config)#int vlan 3
switch(config-if)#ip access-group 110 in
switch(config)#int fasrethernet 0/X
switch(config-if)#ip access-group 110 in //端口X上禁ping
.
.
.
10:恢复交换机出厂设置
思科交换机分为两种系统,分别是IOS和CatOS,下面介绍IOS版本的操作,
Switch#write erase
Erasing the nvram filesystem will remove all files! Continue? [confirm]y[OK]
Erase of nvram: complete
Swtich# delete flash:vlan.dat ------------老版本需做此操作。
Delete filename [vlan.dat]?
Delete flash:vlan.dat? [confirm]y
Switch#reload
另一种方法是启动的时候按Mode进入引导模式,执行如下命令:
flash_init
rename flash:config.text flash:config.old
boot
11: 端口汇聚
console>enable
console#config
console(config)#interface gigaethernet 0/1
console(config-if)#speed 1000
console(config-if)#duplex full
console(config)#interface gigaethernet 0/2
console(config-if)#speed 1000
console(config-if)#duplex full
console(config-if)#exit
console(config)#interface range gigaethernet 0/1-0/2
console(config-if)#channel-group 1 mode on/auto
console(config-if)#switchport mode trunk
console(config-if)#switchport trunk allowed vlan all
console#show etherchannel summary //查看端口汇聚状态。
另外一台交换机的对应汇聚端口务必要和这里两个汇聚口的设置一样。
R1#vlan database
R1(vlan)#vlan 2
R1(vlan)#exit
R1#configure terminal
R1(config)#int range fastethernet 0/1-4
R1(config-int-range)# switchport access vlan 2
R1(config-int-range)# channel-group 1 mode on
R2#vlan database
R2(vlan)#vlan 2
R2(vlan)#exit
R2#configure terminal
R2(config)#int range fastethernet 0/1-4
R2(config-int-range)# switchport access vlan 2
R2(config-int-range)# channel-group 1 mode on
同一个vlan里汇聚,端口使用access状态,多个VLAN之间汇聚端口才需要trunk状态。
***心得***
这里对整个配置过程中需要注意的一些事项以及自己出错的一些地方做一下总结:
1:配置cisco 2960G禁ping的时候出现了一个错误,由于照搬了网上的命令行,实际使用发现无法实现禁ping的效果,最后悟出来原来是加入的ip access-group xx必须与在配置视图里边配置的access-list xx保持一直才能行。
例子:
switch(config)#access-list 110 deny icmp any any //配置访问控制列表(Access Control List,ACL)110指的ICMP对应ping。
switch(config)#access-list 110 permit ip any any //运行所有的IP协议的应用
switch(config)#int vlan 1
switch(config-if)#ip access-group 110 in
2:在配置交换机的snmp-server的时候,(1)需要配置的团体名字和权限snmp-server community xxx ro,(2)还有最重要的指定需要监视的端口号,这个端口号需要可以配置IP,所以对于二层交换机2960而言,只有指定管理vlan的接口了。switch(config)#snmp-server trap-source vlan 100,(3)指定管理机器的IP并授权管理局以xxx团体名进行管理监视端口switch(config)#snmp-server host x.x.x.x(ip地址) xxx(团体名) //设置管理机x.x.x.x,同时允许该管理机以团体明xxx访问。
switch(config)#snmp-server host 119.167.223.221 zy //例子 (4)最后是开启交换机的snmp-server功能switch(config)#snmp-server enable traps //启用snmp服务
完整的例子:
switch(config)#snmp-server community xxx ro //xxx为自定义的共同体名称,并且团体的权限为只读。
switch(config)#snmp-server trap-source FastEthernet0/3/0 //设置snmp监控的端口,此端口必须要配置IP地址才行
switch(config)#snmp-server trap-source vlan 100 /把vlan 100接口作为监控端口
switch(config)#snmp-server host x.x.x.x(ip地址) xxx(团体名) //设置管理机x.x.x.x,同时允许该管理机以团体明xxx访问。
switch(config)#snmp-server host 119.167.223.221 zy //例子
switch(config)#snmp-server enable traps //启用snmp服务。
相关文章
本文直接把华为网络设备中那些真正“危险”的命令拎出来,一条一条拆给你看:哪些会导致中断、哪些会让配置归零、哪些会让你“远程自毁”,以及哪些是隐蔽雷区2026-04-13
三层交换机功能那么强大,那它可以完全取代路由器吗?本文将带大家好好了解一下三层交换机和路由器的差别2026-02-26
本文我们将学习和探讨OSI参考模型中二层和三层交换机的各种特性和应用,以及它们之间工作方式的区别2026-02-26
在交换机配置与故障排查过程中,总会遇到那些“关键时刻靠得住的命令”,今天我们就来分享一份思科双实战命令手册2025-11-18
在使用华为交换机进行故障排查时,首先需要了解交换机的当前状态,通过执行基础命令,可以迅速获取到交换机的系统信息、接口状态以及配置情况等关键数据,为后续的故障分析2025-11-18
弱电日常中,交换机是不可或缺的设备,但关于其端口的种类与功能,可能许多朋友并不十分清楚,接下来,我们将深入探讨交换机的主要端口类型2025-09-18
交换机分层次是什么意思? 浅析一层交换机/二层交换机/三层交换机的区别
交换机作为重要的网络设备,承载着数据包的转发和路由功能,其中,一层交换机、二层交换机和三层交换机在功能和应用上各有差异,详细请看下文介绍2025-09-18
如何正确识别一台POE交换机的好坏? 选购可靠的POE交换机注意事项
POE技术已经历多年发展,广泛应用于安防监控和无线覆盖等领域,需求量大,但质量参差不齐,市场上POE交换机的品牌繁多,如何正确识别一台POE交换机的好坏?详细请看下文介2025-09-17
H3C四款2.5G交换机S1506FX/S1509FXC-U/S1510FX/S1510FX-UP拆机评测
新华三H3C近期新出了四款2.5G交换机,很多朋友想要看看这四款交换机的性能与区别,下面我们一起来看看详细测评2025-07-15
在选择交换机的时候,有朋友问联果8口万兆三层全光交换机怎么样?值得购买吗?下面我们就来看看详细测评2025-05-17








最新评论