学习啦 > 学习电脑 > 电脑硬件知识 > 硬件知识 >

Cisco 交换机基本配置命令有哪些重要的

时间: 加城1195 分享

  交换机工作于OSI参考模型的第二层,即数据链路层。交换机内部的CPU会在每个端口成功连接时,通过将MAC地址和端口对应,形成一张MAC表,学习交换机时候基本配置命令是必须掌握的,这篇文章主要介绍了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:基本连接方式 】

  作为网络隔离使用:对于一些功能好的交换机,可以通过模式选择开关选择网络隔离模式,实现网络隔离的作用,可以只允许普通端口和UPlink端口通讯,普通端口之间是相互隔离不可以通讯的

  除了作为核心交换机(中心交换机)使用,还可以作为扩展交换机(接入交换机)来扩展网络

  放在路由器上方,扩展网络供应商的网络线路(用于一条线路多个IP的网络),连接之后不同的路由器用不同的IP连接至公网

  相关阅读:交换机硬件故障常见问题

  电源故障:

  由于外部供电不稳定,或者电源线路老化或者雷击等原因导致电源损坏或者风扇停止,从而不能正常工作。

  由于电源缘故而导致机内其他部件损坏的事情也经常发生。

  如果面板上的POWER指示灯是绿色的,就表示是正常的;如果该指示灯灭了,则说明交换机没有正常供电。

  这类问题很容易发现,也很容易解决,同时也是最容易预防的。

  针对这类故障,首先应该做好外部电源的供应工作,一般通过引入独立的电力线来提供独立的电源,并添加稳压器来避免瞬间高压或低压现象。

  如果条件允许,可以添加UPS(不间断电源)来保证交换机的正常供电,有的UPS提供稳压功能,而有的没有,选择时要注意。

  在机房内设置专业的避雷措施,来避免雷电对交换机的伤害。现在有很多做避雷工程的专业公司,实施网络布线时可以考虑。


Cisco 交换机基本配置命令相关文章:

1.Cisco常用的路由器交换机配置命令

2.思科交换机配置命令有哪些

3.cisco2960交换机安装配置基础详解

4.交换机命令行配置与VLAN介绍

5.cisco交换机设置

4017295