交换机笔记 - CCIESKY-home.732go.com

来源:百度文库 编辑:神马文学网 时间:2024/04/29 02:53:07

交换机笔记 

一、什么是交换机
交换机是工作在数据链路层
(1)LLC(逻辑链路控制):用数值来指定数据帧中包的类型

(2)物理地址(MAC地址):
在以太网中以48位,6bit表示,如:HH:HH:HH:HH:HH:HH,前三位为厂商代码,后三位为主机代码;
每块网卡的物理地址都是唯一的;
物理地址和ip地址通过arp协同工作的;
ff:ff:ff:ff:ff:ff 广播地址发给所有的主机,目的地址是全:ff的帧叫广播帧;

(3)封装帧
帧的四种类型:
IE802.2帧:没有LLC字段,只能用在单一的一个协议上
以太2帧:在以太帧上加了一个类型字段,用来支持多路复用(在现在的ip网络中用得比较多)
SAP(服务访问点帧):真正实现了LLC,OSI推荐的标准贞,但是用得比较少
SNAP:将ASP模拟成以太帧
Ethernet II帧格式:
----------------------------------------------------------------------------------------------
| 前序 | 目的地址 | 源地址 | 类型 | 数据 | FCS |
----------------------------------------------------------------------------------------------
| 8 byte | 6 byte | 6 byte | 2 byte | 46~1500 byte | 4 byte|

IEEE802.3一般帧格式
--------------------------------------------------------------------------------------------------------------
| 前序 | 帧起始定界符 | 目的地址 | 源地址 | 长度 | 数据 | FCS |
------------------------------------------------------------------------------------------------------------
| 7 byte | 1 byte | 2/6 byte | 2/6 byte | 2 byte | 46~1500 byte | 4 byte |

类型字段
两字节的类型字段仅用于Ethernet II帧。该字段用于标识数据字段中包含的高层协议,也就是说,该字段告诉接收设备如何解释数据字段。在以太网中,多种协议可以在局域网中同时共存,例如:类型字段取值为十六进制0800的帧将被识别为IP协议帧,而类型字段取值为十六进制8137的帧将被识别为IPX和SPX传输协议帧。因此,在Ethernet II的类型字段中设置相应的十六进制值提供了在局域网中支持多协议传输的机制。
在IEEE802.3标准中类型字段被替换为长度字段,因而Ethernet II帧和IEEE802.3帧之间不能兼容。
http://hi.baidu.com/hkjj66/blog/item/5c24edef926b5a17fcfa3c30.html


(4)MAC(介质访问控制)
争用型:CSMA/CD(以太网:介质访问控制CSMA/CD的网络)
共享型:令牌环(无冲突效率高,算法复杂成本高)

二、以太网
(1)随着用户的增加会有广泛的冲突
(2)总线结构,传输受限
HUB:工作在物理层,简单的光电转发设备,不能对帧进行逻辑的处理,物理的星型结构,逻辑的总线结构。HUB只能解决单点故障,不能提高网络速度。

冲突域越大,效率越低,所以要分割冲突域。

交换机的每一个接口就是一个冲突域,独立运行CSMA/CD算法
交换机要互联冲突域,使用桥接算法

三、桥接算法
(1)学习,构建MAC地址表(端口和MAC地址表的关系)
(2)转发
(3)过滤,并发通讯,(只向需要的接口发数据)
(4)广播(两种帧),MAC表中没有的,则从所有接口中发出去
=〉最终实现互联冲突域

交换机的所有接口构成一个广播域

四、VLAN
VLAN是用来划分广播域
一个VLAN在一个广播域中,可以跨越多个交换机

VLAN 跨越交换机的实现:
(1)trunk:用一个接口载多个vlan数据
使用tag技术来个vlan打标,用VLAN-ID:
ISL(CISCO私有)会增加帧的长度
dot1q(国际标准)

DTP(动态TRUNK协议)缺省的是ISL封装

(2)vtp(CISCO私有)自动配置vlan
用来在一个域中用来自动生成管理和修改vlan
在server中生成通过广播发出去
vtp的广播仅从trunk线路上发出去
在一个网络中可以有多个vtp server

一个接口有两种模式:trunk、access
当接口属于一个vlan时,它的模式为access

*路由器的每一个接口是一个独立的广播域,在接口之间不转发广播

▲一个vlan = 一组接口 = 一个广播域 = 一个子网


(3)stp
把物理的环状结构做成逻辑的树状结构
物理的环的产生是因为要有冗余

BPDU:stp用来计算信息的一个帧
<1>bridge_id :优先级+MAC地址,用来计算根。root-id
<2>path_coast:路径成本,用来计算最短路径的。
<3>sender_id:优先级+MAC地址
<4>point_id

<1>选根:选出bridge_id最低的做根
<2>根接口:每个交换机离根最近的接口为根接口
<3>指定接口:为每个段选一个指定接口,指一个段离根最最近的接口

stp下的四种接口状态
<1>blocking:可以接收BPDU,但是不转发用户数据
15秒
<2>listening:监听
15秒
<3>learning:学习构造MAC表
20秒
<4>forwarding:转发

生成树CISCO专用技术,用来缩短计算时间
PVST:没vlan生成树,每个vlan有自己独立的生成树计算
MST:分组生成树

(4)端口汇聚:把两个物理接口变成一个逻辑接口,关掉生成树。
(5)HSRP:冗余网关,虚拟路由器的MAC就是active路由器的MAC地址

五、交换机的配置
(1)EtherChannel
3550(config)# interface gigabitethernet 0/1
3550(config-if)# switchport
3550(config-if)# channel-group 1 mode desirable
3550(config-if)# exit

3550(config)# interface gigabitethernet 0/2
3550(config-if)# switchport
3550(config-if)# channel-group 1 mode desirable
3550(config-if)# interface port-channel 1
3550(config-if)# switchport mode trunk

(2)Trunk
switch(config)# interface {fastethernet|gigabitethernet} solt/port
switch(config-if)# switchport trunk encapsulation {isl | dot1q | negotiate}
switch(config-if)# switchport mode {dynamic {auto | desirable} | trunk}
switch(config-if)# switchport trunk native vlan vlan-id
switch(config-if)# switchport trunk allowed vlan {add | except | all | remove } vlan-id [,vlan-id[,vland-id[,...]]]

配置验证:
show running-config inter-face type slot/port       //显示接口运行的配置
show interface [ type slot/port ] switchport           //显示接口的交换机端口配置
show interface [ type slot/port ] trunk                     //显示接口的干道配置

配置实例:
配置端口支持ISL链路聚集
conf  t
int fast 5/8
switchport
switchport trunk encapsulation isl
switchport mode trunk
end
配置端口为desirable支持802.1Q,并只允许vlan 1~100出现在干道中
conf t
int fast 5/8
switchport trunk encapsulation dot1q
switchport mode dynamic desirable
switchport trunk allowed vlan 1-100
no shut
end  

(3)VTP
switch# conf igure terminal
switch(conf ig)# vtp server | client | transparent
switch(config)# vtp domain domain_name
switch(conf ig)# vtp version 2
switch(config)# vtp password password_string 
//口令大小写敏感,并且长度是8-64字符,采用VTP人证是一种推荐做法
switch(config)# vtp pruning
switch(config)# exit

(4)VLAN
创建vlan:
switch# configure terminal
switch(config)# vlan vlan-id
switch(config)# name vlan-name

删除特定的vlan:
switch# configure terminal
switch(config)# no vlan vlan-id
switch(config)# end

(5)interface to vlan
switch# configure terminal
switch(config)# interface fastethernat 5/6
switch(config-if)# switchport mode access
switch(config-if)# switchport access vlan 200
switch(config-if)# no shutdown
switch(config-if)# end

(6)HSRP
定义HSRP组
standby group-number ip virtual-ip -address

配置HSRP组
switch#show running-confing
!
interface vlan10
ip address 172.16.10.82 255.255.255.0
no ip redirects
standby 47 ip 172.16.10.110
!

路由器HSRP优先级配置实例
switch#show running-confing
!
interface vlan10
ip address 172.16.10.82 255.255.255.0
no ip redirects
standby  47 priority 150
standby 47 ip 172.16.10.110
!

配置HSRP抢占
switch#show running-confing
!
interface vlan10
ip address 172.16.10.82 255.255.255.0
no ip redirects
standby  47 priority 150
standby 47 preempt
standby 47 ip 172.16.10.110
!

(7)STP
配置PVST+的基本参数
在交换机上启用STP
switch# configure terminal
switch(config)# spanning-tree vlan 100
switch(config)# end

设置网桥优先级
switch# configure terminal
switch(conifg)# spanning-tree vlan 100 priority 4096
switch(config)# end
//优先级的默认设置:根网桥4096,辅助根8192,默认值32786

配置生成树端口开销或vlan端口开销
spanning-tree cost port_cost
spanning-tree vlan vlan-id cost port-cost

启用交换机宏命令
spanning-tree vlan vlan-id root primary
spanning-tree vlan
vlan-id root secondary

配置MST的基本参数
spanning-tree mst configuration
name name
revision revision_number
instance instance_number vlan vlan_range

配置MST实例,将VLAN映射到实例的输出结果
switch# configure terminal
switch(config)# spanning-tree mode mst
switch(config)# spanning-tree mst configuration
switch(config-mst)# show current
……
switch(config-mst)# name cisco
switch(config-mst)# revision 1
switch(config-mst)# instance 1 vlan 1-10
switch(config-mst)# show pending
……
switch(config-mst)# end