千家论坛_弱电智能化技术与工程讨论(建筑智能,家居智能,人工智能)

千家下载中心
收藏本版 (10) |订阅

千家下载中心 今日: 5451 |主题: 2041|排名: 19 

发新帖
打印 上一主题 下一主题

[分享]思科交换机配置简要...

[复制链接]
junipar 发布于: 2012-12-25 16:20 918 次浏览 9 位用户参与讨论
跳转到指定楼层
说明
本手册只包括日常使用的有关命令及特性,其它未涉及的命令及特性请参考英文的详细配置手册。
配置端口
配置一组端口
    命令     目的
Step 1      configure terminal    进入配置状态
Step 2      interface range {port-range}     进入组配置状态
Step 3          可以使用平时的端口配置命令进行配置
Step 4      end    退回
Step 5      show interfaces [interface-id]    验证配置
Step 6      copy running-config startup-config    保存

当使用interface range命令时有如下的规则:
?    有效的组范围:
o    vlan从1 到4094
o    fastethernet 槽位/{first port} - {last port}, 槽位为0
o    gigabitethernet槽位/{first port} - {last port},槽位为0
o    port-channel port-channel-number - port-channel-number, port-channel号从1到64
?    端口号之间需要加入空格,如:interface range fastethernet 0/1 – 5 是有效的,而interface range fastethernet 0/1-5 是无效的.
?    interface range 命令只能配置已经存在的interface vlan
?    所有在同一组的端口必须是相同类别的。
见以下例子:
Switch# configure terminal

Switch(config)# interface range fastethernet0/1 - 5

Switch(config-if-range)# no shutdown
Switch(config-if-range)#
*Oct  6 08:24:35: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Oct  6 08:24:35: %LINK-3-UPDOWN: Interface FastEthernet0/2, changed state to up
*Oct  6 08:24:35: %LINK-3-UPDOWN: Interface FastEthernet0/3, changed state to up
*Oct  6 08:24:35: %LINK-3-UPDOWN: Interface FastEthernet0/4, changed state to up
*Oct  6 08:24:35: %LINK-3-UPDOWN: Interface FastEthernet0/5, changed state to up
*Oct  6 08:24:36: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/05,
changed state to up
*Oct  6 08:24:36: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed
state to up
*Oct  6 08:24:36: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/4, changed
state to up

[此贴子已经被作者于2012/12/25 16:22:01编辑过]
回复

使用道具 举报

已有9人评论

新浪微博达人勋

千家认证

沙发
junipar 发表于 2012-12-25 16:22:00
 以下的例子显示使用句号来配置不同类型端口的组:
Switch# configure terminal

Switch(config)# interface range fastethernet0/1 - 3, gigabitethernet0/1 - 2

Switch(config-if-range)# no shutdown
Switch(config-if-range)#
*Oct  6 08:29:28: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Oct  6 08:29:28: %LINK-3-UPDOWN: Interface FastEthernet0/2, changed state to up
*Oct  6 08:29:28: %LINK-3-UPDOWN: Interface FastEthernet0/3, changed state to up
*Oct  6 08:29:28: %LINK-3-UPDOWN: Interface GigabitEthernet0/1, changed state to up
*Oct  6 08:29:28: %LINK-3-UPDOWN: Interface GigabitEthernet0/2, changed state to up
*Oct  6 08:29:29: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/ 1,
changed state to up
*Oct  6 08:29:29: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/ 2,
changed state to up
*Oct  6 08:29:29: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/ 3,
changed state to up
 
配置二层端口
思科三层交换机的所有端口缺省的端口都是二层口,如果此端口已经配置成三层端口的话,则需要用switchport来使其成为二层端口。
配置端口速率及双工模式
可以配置快速以太口的速率为10/100Mbps及千兆以太口的速率为10/100/1000-Mbps; 但对于GBIC端口则不能配置速率及双工模式,有时可以配置nonegotiate,当需要联接不支持自适应的其它千兆端口时
    命令    目的
Step 1      configure terminal    进入配置状态.
Step 2      interface interface-id    进入端口配置状态.
Step 3      speed {10 | 100 | 1000 | auto | nonegotiate}    设置端口速率
注   1000 只工作在千兆口. GBIC模块只工作在1000 Mbps下. nonegotiate 只能在这些GBIC上用 1000BASE-SX, -LX, and -ZX GBIC.
Step 4      duplex {auto | full | half}    设置全双工或半双工.
Step 5      end    退出
Step 6      show interfaces interface-id    显示有关配置情况
Step 7      copy running-config startup-config    保存

回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

板凳
junipar 发表于 2012-12-25 16:23:00
 
Switch# configure terminal

Switch(config)# interface fastethernet0/3

Switch(config-if)# speed 10

Switch(config-if)# duplex half
端口描述

    命令    目的
Step 1      configure terminal    进入配置模式
Step 2      interface interface-id    进入要加入描述的端口
Step 3      description string    加入描述 (最多240个字符).
Step 4      end    退回.
Step 5      show interfaces interface-id description
or
show running-config    验证.
Step 6      copy running-config startup-config    保存

Use the no description interface configuration command to delete the description.
This example shows how to add a description on Fast Ethernet interface 0/4 and to verify the description:
Switch# config terminal

Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# interface fastethernet0/4

Switch(config-if)# description Connects to Marketing

Switch(config-if)# end

Switch# show interfaces fastethernet0/4 description

Interface Status         Protocol Description
Fa0/4     up             down     Connects to Marketing
配置三层口
思科交换机有三种类型的三层端口:
?    SVIs: 即interface vlan
________________________________________
 
Note  当生成一个interface Vlan时,只有当把某一物理端口分配给它时才能被激活
________________________________________
?    三层以太网通道口(EtherChannel)
?    .路由口:路由口是指某一物理端口在端口配置状态下用no switchport命令生成的端口
所有的三层都需要IP地址以实现路由交换
配置步骤如下:
    命令    目的
Step 1      configure terminal    进入配置状态
Step 2      interface {{fastethernet | gigabitethernet} interface-id} | {vlan vlan-id} | {port-channel port-channel-number}    进入端口配置状态
Step 3      no switchport    把物理端口变成三层口
Step 4      ip address ip_address subnet_mask     配置IP地址和掩码
Step 5      no shutdown    激活端口
Step 6      end    退出
Step 7      show interfaces [interface-id]
show ip interface [interface-id]
show running-config interface [interface-id]    验证配置
Step 8      copy running-config startup-config    保存配置
回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

地板
junipar 发表于 2012-12-25 16:25:00
 配置举例如下:
Switch# configure terminal

Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# interface gigabitethernet0/2

Switch(config-if)# no switchport

Switch(config-if)# ip address 192.20.135.21 255.255.255.0

Switch(config-if)# no shutdown

Switch(config-if)# end

 
show ip interface命令:
Switch# show ip interface gigabitethernet0/2

GigabitEthernet0/2 is up, line protocol is up
  Internet address is 192.20.135.21/24
  Broadcast address is 255.255.255.255
  Address determined by setup command
  MTU is 1500 bytes
  Helper address is not set
  Directed broadcast forwarding is disabled
 
<output truncated>
监控及维护端口
监控端口和控制器的状态
主要命令见下表:
Show Commands for Interfaces Command     目的
show interfaces [interface-id]    显示所有端口或某一端口的状态和配置.
show interfaces interface-id status [err-disabled]    显示一系列端口的状态或错误-关闭的状态
show interfaces [interface-id] switchport    显示二层端口的状态,可以用来决定此口是否为二层或三层口。
show interfaces [interface-id] description    显示端口描述
show ip interface [interface-id]    显示所有或某一端口的IP可用性状态
show running-config interface [interface-id]    显示当前配置中的端口配置情况
show version    显示软硬件等情况

回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

5#
junipar 发表于 2012-12-25 16:25:00
 举例如下:
Switch# show interfaces status

 
Port    Name               Status       Vlan       Duplex  Speed Type
Gi0/1                      connected    routed     a-full  a-100 10/100/1000Base
TX
Gi0/2   wce server 20.20.2 disabled     routed       auto   auto 10/100/1000Base TX
Gi0/3   ip wccp web-cache  notconnect   routed       auto   auto 10/100/1000Base TX
Gi0/4                      notconnect   routed       auto   auto 10/100/1000Base TX
Gi0/5                      notconnect   routed       auto   auto 10/100/1000Base TX
Gi0/6                      disabled     routed       auto   auto 10/100/1000Base TX
Gi0/7                      disabled     routed       auto   auto 10/100/1000Base TX
Gi0/8                      disabled     routed       auto    100 10/100/1000Base TX
Gi0/9                      notconnect   routed       auto   auto 10/100/1000Base TX
Gi0/10                     notconnect   routed       auto   auto 10/100/1000Base TX
Gi0/11                     disabled     routed       auto   auto unknown
Gi0/12                     notconnect   routed       auto   auto unknown

回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

6#
junipar 发表于 2012-12-25 16:26:00
 Switch# show interfaces fastethernet 0/1 switchport

Name: Fa0/1
Switchport: Enabled
Administrative Mode: static access
Operational Mode: down
Administrative Trunking Encapsulation: dot1q
Negotiation of Trunking: Off
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001
 
Protected: false
Unknown unicast blocked: disabled
Unknown multicast blocked: disabled
 
Voice VLAN: dot1p (Inactive)
Appliance trust: 5


Switch# show running-config interface fastethernet0/2

Building configuration...
 
Current configuration : 131 bytes
!
interface FastEthernet0/2
 switchport mode access
 switchport protected
 no ip address
 mls qos cos 7
 mls qos cos override
end
刷新、重置端口及计数器
Clear命令    目的
clear counters [interface-id]    清除端口计数器.
clear interface interface-id    重置某一端口的硬件逻辑
clear line [number | console 0 | vty number]    重置异步串口的硬件逻辑

________________________________________
 
Note   clear counters 命令只清除用show interface所显示的计数,不影响用snmp得到的计数
________________________________________
举例如下:
Switch# clear counters fastethernet0/5
Clear "show interface" counters on this interface [confirm] y
Switch#
*Sep 30 08:42:55: %CLEAR-5-COUNTERS: Clear counter on interface FastEthernet0/5
by vty1 (171.69.115.10)
 
可使用clear interface 或 clear line 命令来清除或重置某一端口或串口,在大部分情况下并不需要这样做:
Switch# clear interface fastethernet0/5

关闭和打开端口
    命令     目的
Step 1      configure terminal    进入配置状态
Step 2      interface {vlan vlan-id} | {{fastethernet | gigabitethernet} interface-id} | {port-channel port-channel-number}    选择要关闭的端口
Step 3      shutdown    关闭
Step 4      end    退出
Step 5      show running-config    验证

使用 no shutdown 命令重新打开端口.
回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

7#
junipar 发表于 2012-12-25 16:27:00
 举例如下:
Switch# configure terminal

Switch(config)# interface fastethernet0/5
Switch(config-if)# shutdown
Switch(config-if)#
*Sep 30 08:33:47: %LINK-5-CHANGED: Interface FastEthernet0/5, changed state to a
administratively down
 
Switch# configure terminal

Switch(config)# interface fastethernet0/5
Switch(config-if)# no shutdown
Switch(config-if)#
*Sep 30 08:36:00: %LINK-3-UPDOWN: Interface FastEthernet0/5, changed state to up
 
配置VLAN
理解VLAN
 一个VLAN就是一个交换网,其逻辑上按功能、项目、应用来分而不必考虑用户的物理位置。任何交换口都可以属于某一VLAN, IP包、广播包及组播包均可以发送或广播给在此VLAN内的最终用户。每一个VLAN均可看成是一个逻辑网络,发往另一VLAN的数据包必须由路由器或网桥转发(如下图)。由于VLAN被看成是一个逻辑网络,其具有自己的网桥管理信息庫 (MIB) 并可支持自己的生成树

 VLAN作为逻辑定义的网络示意图

 
VLAN常常与IP子网相联系,同一IP子网属于同一VLAN。在VLAN之间的数据包可以由VLAN端口进行转发。
可支持的VLAN
思科交换机支持1005个 VLAN,可以分别是VTP client, server, 及 transparent modes. VLAN号可以从1到4094. VLAN号1002到1005保留给令牌环及FDDI VLAN. VTP只能学习到普通范围的VLAN, 即从VLAN到1到1005; VLAN号大于1005属于扩展VLAN,不存在VLAN数据庫中。 交换机必须配置成VTP透明模式当需要生成VLAN 号从1006到4094.
本交换机支持基于每一VLAN的生成树(PVST),最多支持128个生成树。本交换机支持ISL及IEEE 802.1Q trunk二种封装。
配置正常范围的VLAN
VLAN号1, 1002到1005是自动生成的不能被去掉。
VLAN号1到1005的配置被写到文件vlan.dat 中, 可以用show vlan 命令查看, vlan.dat 文件存放在NVRAM中.
________________________________________
 
注意   不要手工删除vlan.dat 文件,可能造成VLAN的不完整。 如要删除vlan需要用有关的命令来进行
________________________________________
生成、修改以太网VLAN
回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

8#
junipar 发表于 2012-12-25 16:27:00
     命令    目的
Step 1      configure terminal    进入配置状态
Step 2      vlan vlan-id    输入一个VLAN号, 然后进入vlan配置状态,可以输入一个新的VLAN号或旧的来进行修改。
Step 3      name vlan-name    (可选)输入一个VLAN名,如果没有配置VLAN名,缺省的名字是VLAN号前面用0填满的4位数,如VLAN0004是VLAN4的缺省名字
Step 4      mtu mtu-size    (可选) 改变MTU大小
Step 5      end    退出
Step 6      show vlan {name vlan-name | id vlan-id}    验证
Step 7      copy running-config startup config    (可选) 保存配置
用no vlan name 或 no vlan mtu 退回到缺省的vlan配置状态
举例如下:
Switch# configure terminal

Switch(config)# vlan 20

Switch(config-vlan)# name test20

Switch(config-vlan)# end



也可以在enable状态下,进行VLAN配置:
    命令     目的
Step 1      vlan database    进入VLAN配置状态
Step 2      vlan vlan-id name vlan-name    加入VLAN号及VLAN名
Step 3      vlan vlan-id mtu mtu-size    (可选) 修改MTU大小
Step 4      exit    更新VLAN数据庫并退出
Step 5      show vlan {name vlan-name | id vlan-id}    验证配置
Step 6      copy running-config startup config    保存配置(可选)

举例如下:
Switch# vlan database

Switch(vlan)# vlan 20 name test20

Switch(vlan)# exit

APPLY completed.
Exiting....
Switch#
删除VLAN
当删除一个处于VTP服务器的交换机上删除VLAN时,则此VLAN将在所有相同VTP的交换机上删除。当在透明模式下删除时,只在当前交换机上删除。
 
注意   当删除一个VLAN时,原来属于此VLAN的端口将处于非激活的状态,直到将其分配给某一VLAN。
________________________________________


    命令     目的
Step 1      configure terminal    进入配置状态
Step 2      no vlan vlan-id    删除某一VLAN.
Step 3      end    退出
Step 4      show vlan brief    验证
Step 5      copy running-config startup config    保存

也可用vlan database 进入VLAN配置状态,用no vlan vlan-id 来删除。
将端口分配给一个VLAN
回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

9#
junipar 发表于 2012-12-25 16:28:00
     命令     目的
Step 1      configure terminal    进入配置状态
Step 2      interface interface-id    进入要分配的端口
Step 3      switchport mode access    定义二层口
Step 4      switchport access vlan vlan-id    把端口分配给某一VLAN
Step 5      end    退出
Step 6      show running-config interface interface-id     验证端口的VLAN号
Step 7      show interfaces interface-id switchport    验证端口的管理模式和VLAN情况
Step 8      copy running-config startup-config    保存配置

使用 default interface interface-id 还原到缺省配置状态。
举例如下:
Switch# configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# interface fastethernet0/1

Switch(config-if)# switchport mode access

Switch(config-if)# switchport access vlan 2

Switch(config-if)# end
Switch#
配置VLAN Trunks

    命令     目的
Step 1      configure terminal    进入配置状态
Step 2      interface interface-id    进入端口配置状态
Step 3      switchport trunk encapsulation {isl | dot1q | negotiate}    配置trunk封装ISL 或 802.1Q 或自动协商
Step 4      switchport mode {dynamic {auto | desirable} | trunk}    配置二层trunk模式。
?    dynamic auto—自动协商是否成为trunk
?    dynamic desirable—把端口设置为trunk如果对方端口是trunk, desirable, 或自动模式
?    trunk—设置端口为强制的trunk方式,而不理会对方端口是否为trunk
Step 5      switchport access vlan vlan-id    (可选) 指定一个缺省VLAN, 如果此端口不再是trunk
Step 6      switchport trunk native vlan vlan-id    指定802.1Q native VLAN号
Step 7      end    退出
Step 8      show interfaces interface-id switchport    显示有关switchport 的配置
Step 9      show interfaces interface-id trunk    显示有关trunk的配置
Step 10      copy running-config startup-config    保存配置
举例:
Switch# configure terminal

Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# interface fastethernet0/4

Switch(config-if)# switchport mode trunk

Switch(config-if)# switchport trunk encapsulation dot1q

Switch(config-if)# end

回复 支持 反对

使用道具 举报

新浪微博达人勋

千家认证

10#
junipar 发表于 2012-12-25 16:28:00
 定义trunk允许的VLAN
缺省情况下trunk允许所有的VLAN通过。可以使用 switchport trunk allowed vlan remove vlan-list 来去掉某一VLAN
    Command     Purpose
Step 1      configure terminal    进入配置状态
Step 2      interface interface-id    进入端口配置
Step 3      switchport mode trunk    配置二层口为trunk
Step 4      switchport trunk allowed vlan {add | all | except | remove} vlan-list     (可选) 配置trunk允许的VLAN.
使用add, all, except,  remove关健字
Step 5      end    退出
Step 6      show interfaces interface-id switchport     验证VLAN配置情况.
Step 7      copy running-config startup-config    保存配置

回到允许所有VLAN通过时, 可用no switchport trunk allowed vlan 端口配置命令.
举例如下:
Switch(config)# interface fastethernet0/1

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

Switch(config-if)# end

配置Native VLAN(802.1q)
封装802.1q的trunk端口可以接受带有标签和不带标签的数据流,交换机向native vlan传送不带标签的数据流,缺省情况下native VLAN是1。

    命令     目的
Step 1      configure terminal    进入配置状态
Step 2      interface interface-id    进入配置成802.1qtrunk的端口
Step 3      switchport trunk native vlan vlan-id    配置native VLAN号
Step 4      end    退出
Step 5      show interfaces interface-id switchport    验证native VLAN配置
Step 6      copy running-config startup-config    保存配置

使用no switchport trunk native vlan 端口配置命令回到缺省的状态
使用STP实现负载均衡
负载均衡可以使用流量分流到其它平行的trunks上去. 交换机为了避免环路, STP通常是阻断所有端口交换机之间只留一条链路 。使用负载均衡后, 可以把不同VLAN的流量分配到不同的trunk上。
可以通过配置STP端口权值STP路径值来实现负载均衡. 如果使用STP端口权值来配置那么二条负载均衡的trunk必须联同一交换机上。使用路径值则即可以联相同的交换机与可以联不同的交换机。
使用STP端口权值的负载均衡
当同一台交换机的二个口形成环路时, STP端口权值用来决定那个口是enable的,那个口是阻断的。 可以通过配置端口权值来决定二对trunk各走那些VLAN, 有较高权值的端口(数字较小的)vlan, 将处于转发状态,同一个VLAN在另一个trunk有较低的权值(数字较大)则将处在阻断状态。 即同一VLAN只在一个trunk上发送接受。

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆 千家通行证登陆

本版积分规则

千家智客微信号
千家智客微信
玩物说商城
玩物说商城