CISCO 2950交换机配置参考

这是本人在近期的网络技术培训中对于交换机的学习记录,列举了CISCO 2950交换机的经常使用配置命令,并进行了简要说明。api

交换机配置

接口设置

Switch(config-if)#duplex [full|half|auto]   //设置接口双工模式安全

Switch(config-if)#speed [10|100|auto]   //接口速率服务器

接口安全

安全接口网络

Switch(config-if)#sw port-security  session

Switch(config-if)#sw port-security maximum 1  //负载均衡

Switch(config-if)#sw port-security mac-address [sticky] H.H.H //静态指定安全地址。dom

说明:设置了安全接口后,就会只学习链接到该接口的MAC地址。若是指定了最大地址数(maximum),则只学习限定地址数的MAC地址。oop

Trunk接口和监控接口不能配置为安全接口。学习

接口保护spa

Switch(config-if)#sw protected  //被保护的端口必须指定一个惟一的VLAN ID,它不会向其它被保护端口发送任何数据包,但能够向非保护端口转发数据。若是被保护端口向其它交换机发送数据,须要经过trunk接口。

接口地址绑定

Switch(config)#mac access-list extended mac10 //mac10为定义的访问列表名

switch(config-ext-macl)#permit MAC 目的MAC

switch(config-if)mac access-group mac10 in  //在接口中应用访问列表

IP地址绑定与此相似,只须要将前面的mac换成IP便可。

默认网关

Switch(config)#ip default-gateway 192.168.1.1 //设置默认网关

VLAN基本配置

定义VLAN

switch# vlan database

switch (vlan)# vlan 10 //配置vlan

说明:要配置扩展VLAN号(1006-4096),则必须将交换机设置为透明(transparent)模式。标准vlan号为1-1005

设置管理VLAN

 

指定接口所在VLAN

switch (config-if)sw mode acc //配置接口为访问模式

switch (config-if)#sw acc vlan 8  //将接口加入到vlan 8

VLANIP地址和默认网关

switch (config-if)#int vlan8  //进入vlan接口配置模式

switch (config-if)#ip addr 192.168.1.7 255.255.255.0  //设置vlanip地址

Switch(config)#ip default-gateway 192.168.1.1 //默认网关

VTP模式

switch (vlan)#vtp domain domainname password pass1 //配置vtp域名,密码为pass1

switch (vlan)# vtp [server|client]  //配置交换机vtp服务器/客户模式

VTP修剪

Switch(config)#VTP prunning  //启用VTP修剪

Switch(config-if)#sw trunk vlan [vlan-list]  //在接口上对指定vlan进行修剪

trunk设置

Switch(config)# interface interface mod/port

Switch(config-if)# switchport mode trunk  //接口配置为trunk模式

Switch(config-if)# switchport trunk encapsulation {isl | dot1q}   //封闭的trunk协议

swtich(config-if)#sw trunk allowed vlan [VlanID]  //设置容许经过的VLAN

Switch(config-if)# switchport trunk allowed vlan remove vlan-list

Switch(config-if)# switchport trunk allowed vlan add vlan-list

switch(config-if)#sw trunk prunning vlan [vlanid|add|remove|except|none]   //对指定VLAN进行修剪。

Switch(config-if)#sw trunk native vlan 30 //vlan30设置为native vlan

Switch(config-if)#sw nonegotiate //该接口上不执行协商协议

Switch#show interfaces  F0/1  switchport  //检查接口上的trunk/access状态

查看VLAN状态

Switch#sh vlan 

动态VLAN TRUNK

Switch(config-if)#sw mode dynamic desirable //设置接口模式为动态

端口镜像

s(config)#monitor session 1 destion interface gi0/1   //采用gi0/1为镜像端口

Switch(config)#monitor session 1 source intface fa0/1 – 24  //124号快速以太网端口做为被监控对象

生成树配置

基本配置

Switch(config)#span mode [mst|pvst|rapid pvst]  //生成树类型,默认为pvstMst模式不支持对单个vlan进行配置,而pvst则能够。Msttrunk封装802.1Q,而pvsttrunk封装为ISL

验证:#sh span sum

Switch(config)#span loopguard default  //在全部接口上默认启用环回保护。阻止根接口或预备接口成为指定接口,阻止根接口和预备接口发送BPDU。接口上有相应配置,可覆盖默认默认。
验证:#sh span sum

Switch(config-if)#span port-priority 128 //修改接口的优先级。验证:#sh span int f0/7 (假定为7号端口)

Switch(config-if)#span vlan 20 port-priority 128 //接口是trunk模式时,可对不一样的VLAN设置不一样的优先级值,覆盖接口优先级值。验证:#sh span int f0/7 #sh span vlan 20

Switch(config-if)#span link-type [point-to-point|shared] //链路类型。全双工接口被认为是点对点类型,而半双工接口被认为是共享链路类型。

根网桥

switch(config)#spanning-tree vlan 10 root primary|secondary  //设置此交换机为vlan10的生成树的主要(次要)根  验证:#sh span vl 10

switch(config)#spanning-tree vlan10 priority 0//优先级,4096的倍数,默认为32768
验证:#span vl 10

switch(config-if)#spanning-tree guard root //根保护 验证:#sh run

生成树快速收敛配置

Switch(config)#span backbonefast //启用快速干线。验证:#sh span sum

Switch(config)#span uplinkfast //启用快速上连线路,不能用于根网桥。验证:#sh span sum

Switch(config)#span portfast default //在全部access接口上默认启用portfast,这样接口在启动时直接进入转发状态。在接口上的配置会覆盖全局的默认配置。验证:#sh span sum

 相似的命令还有:

Switch(config)#Span portfast bpdufilter default //默认在启用了portfast接口上进行bpdu过滤,即阻止在该端口发送和接收BPDU

Switch(config)#span portfast bpduguard default//默认在启用了portfast接口上进行bpdu保护。在配置有错时,将收到bpdu的接口置为error-disable状态,这样能够帮助排除错误配置,由于不排除故障就没法使用接口。

Switch(config)#span uplinkfast max-update-rate 150 //通知上游交换机链路状态改变的频率。范围0-32000,默认150。验证:#sh spanning-tree summary

Swtich(config)#span vlan 20 hello-time 2  //设置hello时间间隔,范围0-10,默认2,只须要在根网桥上设置。 验证:#sh span vlan 20

Switch(config)#span vlan 20 forward-time 15 //端口状态转换前停留时间,范围4-30,,默认15,只需在根网桥上设置。(端口状态转换是指监听到学习,或学习到转发)

Swtich(config)span vlan 20 max-age 20 //设置经过指定接口从邻居收到的BPDU存储的最大生命周期,超过期端口转入监听状态,范围6-40,默认20

负载均衡

负载均衡的基本策略:经过修改port-priorityport cost值,将不一样的VLAN流量从不一样的trunk上经过。假设有VLAN10203040,分别经过两个端口f0/3,f0/4trunk链路。可作以下配置。

一、  VLAN1020f0/3经过

Switch(config)#int f0/3

Switch(config-if)#sw mode trunk

Switch(config-if)#span vlan 10 port-priority 16 //优先级按16增长,默认为128

Switch(config-if)#span vlan 20 port-prioprity 16

二、  vlan 30,40 默认从f0/4经过

Switch(config)#int f0/4

Switch(config-if)#span vlan 30 port-priority 16

Switch(config-if)#span vlan 40 port-prority 16

注:这样的配置,须要生成树模式为pvst,在正常状况下,VLAN1020的流量将从3号端口转发,而VLAN3040的流量将从4号端口转发。当3号端口的链路中断时,VL1020的流量将自动经过4号端口转发。固然,若不修改port-priority,而是象上面同样修改cost值(使cost值比默认的要小),能达到相同的效果。

链路聚合

Switch(config)#port-channel load-balance  srt/dst  //在多个接口间进行负载均衡

switch(config-if)#Channel-group 1 mode on|active|passive //在接口上启用以太通道模式/LACP/PAGP

switch(config-if)#channel-protocol LACP|pAgp  //设置以太通道使用的协议

switch(config-if)#Switchport mode trunk //设置接口为trunk模式,以便全部(或指定VLAN的)流量都能经过

显示以太通道配置状况

Switch#sh eth port  //可显示以太通道的接口列表和接口参数

Switch#sh eth port-channel //显示以通道列表

Swtich#sh eth protocol  //显示以太通道组列表和各以太通道使用的协议。

snmp设置

对交换机进行网络管理,必须给交换机设置一个IP地址。

Switch(config)#int vlan 1  //进入VLAN1接口,以便设置管理地址

Switch(config-if)#ip add 192.168.1.1 255.255.255.0 //

Switch(config)#snmp-server community public [ro|rw] //设置共同体名称public和读(写)参数ro(rw) .

Switch(config)#snmp-server host 81.129.1.1 traps public //设置traps的接收主机

交换机上的组播配置

Switch(config)#ip igmp snooping [vlan vlanID] //启用IGMP snooping 。也能够在接口模式下进行相似设置。

手工添加MAC地址表

Switch(config)#mac-address-table static [HH.HH.HH] vlan [VlanID] interface F0/9 //添加MAC地址HH.HH.HH对应的端口为F0/9.

Switch#show mac-address-table  //验证MAC地址表