CCNA笔记:2层交换
添加时间: 2008-1-3 4:33:54 作者: Cisco教程指导 阅读次数:16 来源: http://www.d9soft.com
layer 2 switching
switching services
路由协议有在阻止层3的循环的过程.但是假如在你的switches间有冗余的物理连接,路由协议并不能阻止层2循环的发生,这就必须依靠生成树协议(spanning tree protocol,stp)
不像bridges使用软件来创建和 管理 mac地址过滤表,switches使用asics来创建和管理mac地址表,可以把switches想象成多端口的bridges
层2的switches和bridges快于层3的router因为它们不花费额外的时间字查看层3包头信息,相反,它们查看帧的硬件地址然后决定是转发还是丢弃.每个端口为1个冲突域,所有的端口仍然处于1个大的广播域里
层2交换提供:
1.基于硬件的桥接(asic)
2.线速(wire speed)
3.低延时(latency)
4.低耗费
bridging vs. lan switching
桥接和层2交换的一些区别和相似的地方:
1.bridges基于软件,switches基于硬件
2.switches和看作多端口的bridges
3.bridges在每个bridge上只有1个生成树实例,而switches可以有很多实例
4.switches的端口远多于bridges
5.两者均转发层2广播
6.两者均通过 检查 收到的帧的源mac地址来学习
7.两者均根据层2地址来做转发决定
three switch function at layer 2
2层交换的一些功能:
1.地址学习(address learning):通过查看帧的源mac地址来加进1个叫做转发/过滤表的mac地址数据库里
2.转发/过滤决定(forward/filter decisions):当1个接口收到1个帧的时候,switch在mac地址数据库里查看目标mac地址和出口接口,然后转发到符合条件的那个目标端口去
3.循环避免(loop avoidance):假如有冗余的连接,可能会造成循环的产生,stp就用来破坏这些循环
spanning tree protocol(stp)
spanning tree terms
digital equipment coporation(dec)在被收购和重命名为compaq的时候,创建了原始的stp,之后ieee创建了自己的stp叫做802.1d版本的stp.和之前的dec的stp不兼容.stp的主要任务是防止层2的循环,stp使用生成树算法(spanning-tree algorithm,sta)来创建个拓扑数据库,然后查找出冗余连接并破坏它。
我们来看些关于stp的术语:
1.stp:bridges之间交换bpdu信息来检测循环,并通过关闭接口的方式来破坏循环
2.根桥(root bridge):拥有最好的bridge id即为根桥, 网络 中的一些诸如哪些端口被堵塞(block)哪些端口作为转发模式的决定都由根桥来决定
3.bpdu:bridge protocol data unit,所有的switches通过交换这些信息来选择根switch
4.bridge id:用于stp跟踪网络中的所有switches,这个id由bridge优先级(priority)和mac地址符合而成,优先级默认为32768,id最低的即为根桥
5.非根桥(nonroot bridge):不是根桥的全为非根桥,非根桥交换bpdus来更新stp拓扑数据库
6.根端口(root port):与根桥直接相连的端口,或者是到根桥最短的接口.如果到根桥的连接不止1条,将比较每条连接的带宽,耗费(cost)低的作为根端口;如果耗费相同就比较bridge id,id低的将被选用
7.指定端口(designated port):耗费低的端口,作为转发端口
8.端口耗费(port cost):带宽来决定
9.非指定端口(nondesignated port):耗费较高,为堵塞模式(blocking mode),即不转发帧
10.转发端口(forwarding port):转发端口用来转发帧
11.堵塞端口(blocked port):不转发帧,用来防止循环的产生,虽然不转发,但是它可以监听(listen)帧
spanning tree operations
之前说过:stp的任务就是查找出网络中的所有连接,并关闭些会造成循环的冗余连接.stp首先选举1个根桥,用来对网络中的拓扑结构做决定.当所有的switches认同了选举出来的根桥后,所有的bridge开始查找根端口.假如在switches之间有许多连接,只能有1个端口作为指定端口
selecting the root bridge
bridge id用来在stp域里选举根桥和决定根端口,这个id是8字节长,包含优先级和设备的mac地址,ieee版本的stp的默认优先级是32768.决定谁是根桥,假如优先级一样,那就比较mac地址,mac地址小的作为根桥
selecting the designated port
假如不止1个连接到根桥,那就开始比较端口耗费,耗费低的作为根端口,下面是一些典型的耗费标准:
1.10gbps:2
2.1gbps:4
3.100mbps:19
4.10mbps:100
spanning-tree port states
运行stp的bridges和switches的5种状态:
1.堵塞(blocking):不转发帧,只监听bpdus,主要目的是防止循环的产生.默认情况下,当switch启动时所有端口均为blocking状态
2.监听(listening):端口监听bpdus,来决定在传送数据帧之前没有循环会发生
3.学习(learning):监听bpdus和学习所有路径,学习mac地址表,不转发帧
4.转发(forwarding):转发和接收数据帧
5.禁用(disabled):不参与帧的转发和stp,一般在这个状态的都是不可操作的。
一般来说,端口只处于转发和堵塞状态,如果 网络 拓扑发生了变化,端口会进入监听和学习状态,这些状态是临时的
convergence
汇聚,也叫收敛(convergence):当所有端口移动到非转发或堵塞状态时,开始收敛,在收敛完成前,没有数据将被传送.收敛保证了所有的设备拥有相同的数据库达到一致.一般来说从堵塞状态进入到转发状态需要50秒
spanning tree example
我们来看1个stp的例子,拓扑图给出了已知的mac地址,并且所有优先级均为32768:
注意a的mac地址最小,优先级均为32768,所以a作为根桥,并且要注意的是根桥的所有端口均作为转发模式(指定端口).接下来决定根端口,直接与根桥相连的作为根端口,而且作为转发模式,所以可以判定出根端口个指定端口,bridge id决定指定和非指定端口.但是注意d和e之间,由于d的bridge id小,所以d的为指定端口,e的作为非指定端口,如下:
lan switch types
lan的交换类型决定了当switch的端口接收到1个帧的时候如何去处理
延时(latency):指数据包进入一个网络设备到离开该设备的出口接口所花的时间,这个根据不同的交换模式也不一样
3种交换模式:
1.cut-through(fastforward): cisco 称这种模式叫cut-through,fastforward或者real time模式,使用这种模式的时候,lan switch只读取到帧的目标地址为止,减少延时,但是不适合与高偏向错误率的网络
2.fragmentfree(modified cut-through):和cut-through类似,但是lan switch读取到数据(data)部分的前64字节,这个是catalyst 1900的默认模式
3.store-and-forward:在这个模式下,lan switch复制整个帧到它的缓冲区里,然后计算crc,也帧的长短可能不一样,所以延时根据帧的长短而变化.如果crc不正确,帧将被丢弃;如果正确,lan switch查找硬件目标地址然后转发它们
3种模式对帧的读取程度具体如下:
configuring the catalyst 1900 and 2950 switches
1900是款低端switch产品,分为1912和1924系列:1912是有12个10baset端口而1924是有24个10baset端口
1900 and 2950 switch startup
当1900启动后,先运行post,此时每个端口的发光二级管(leds)是绿色的,当post完成后,leds开始闪烁然后熄灭;假如post发现某个端口出问题了的话,系统led和那个出问题的端口的led开始变黄.假如你的console线缆接好了的话,post开始显示菜单,如下:
1 user(s) now active on management console.
user interface menu
[m] menus
[i] ip configuration
enter selection:k
cli session with the switch is open
to end the cli session, enter [exit].
>
而2950的启动,有点像router,先进入setup模式.但是默认你可以不对其进行配置,启动如下:
--- system configuration dialog ---
would you like to enter the initial configuration dialog? [yes/no]: no
press return to get started!
00:04:53: %link-5-changed: interface vlan1, changed state to administratively down
00:04:54: %lineproto-5-updown: line protocol on interface vlan1, changed state to down
switch>
setting the passwords
配置密码:
1.登陆密码(用户模式):防止未授权用户登陆
2.启用密码(特权模式):防止未授权用户修改配置
setting the user mode and enable mode passwords
1900下,输入k进入cli,输入enable进入特权模式,再输入config t进入全局配置模式,如下:
>en
#config t
(config)#
当进入全局配置模式后,使用enable password命令配置登陆密码个启用密码,如下:
(config)#enable password ?
level set exec level password
(config)#enable password level ?
<1-15> level number
level1为登陆密码,level15为启用密码,密码长度范围是4到8字符之间,如下:
(config)#enable password level 1 nocoluvsnoko
error: invalid password length.
password must be between 4 and 8 characters
重配置并验证:
(config)#enable password level 1 noco
(config)#enable password level 15 noko
(config)#exit
#exit
2950下的配置和配置router有点类似,如下:
switch>en
switch#conf t
switch(config)#line ?
<0-16> first line number
console primary terminal line
vty virtual terminal
switch(config)#line vty ?
<0-15> first line number
switch(config)#line vty 0 15
switch(config-line)#login
switch(config-line)#password noko
switch(config-line)#line con 0
switch(config-line)#login
switch(config-line)#password noco
switch(config-line)#exit
switch(config)#exit
switch#
set the enable secret password
enable secret比enable password更 安全 ,而且同时设置了2者的话,只有前者起作用1900下的配置,注意在1900下,enable secret和enable password可以设置成一样的,如下:
(config)#enable secret noko
2950下的配置和router类似,但是enable secret和enable passwor不可以设置成一样的,如下:
switch(config)#enable password noko
switch(config)#enable secret noko
the enable secret you have chosen is the same as your enable password.
this is not recommended. re-enter the enable secret.
switch(config)#enable secret noco
switch(config)#
setting the hostname
给1900配置主机名,使用hostname命令,如下:
(config)#hostname noko
noko(config)#
给2950配置主机名,使用hostname命令,如下:
switch(config)#hostname noco
noco(config)#
setting ip information
你可以不配置ip信息,直接把线缆插进端口,一样可以工作.配置ip地址信息有2点原因:
1.通过telnet或其他软件方式来 管理 switch
2.配置vlans和其他等 网络 功能
默认下,没有ip地址和默认网关信息配置,在1900下,使用show ip命令查看默认ip配置,如下:
1900#sh ip
ip address: 0.0.0.0
subnet mask: 0.0.0.0
default gateway: 0.0.0.0
management vlan: 1
domain name:
name server 1: 0.0.0.0
name server 2: 0.0.0.0
http server: enable
http port: 80
rip: enable
在1900下使用ip address和ip default-gateway命令来配置ip地址信息和默认网关信息,如下:
1900(config)#ip address 172.16.10.16 255.255.255.0
1900(config)#ip default-gateway 172.16.10.1
1900(config)#
2950下的配置是在vlan1接口下配置,vlan1是管理vlan,默认所有接口均是vlan1的成员,配置如下:
2950(config)#int vlan1
2950(config-if)#ip address 172.16.10.17 255.255.255.0
2950(config-if)#no shut
2950(config-if)#exit
2950(config)#ip default-gateway 172.16.10.1
2950(config)#
注意2950的ip地址配置是在vlan1接口下,另外要注意打开接口
configuring interface description
配置描述信息,在接口配置模式下使用description命令,1900下的描述信息不能使用空格键,如下:
1900(config)#int e0/1
1900(config-if)#description cisco _vlan
1900(config-if)#int f0/26
1900(config-if)#description trunk_to_building_4
1900(config-if)#
2950下的描述就可以使用空格键,如下:
2950(config)#int fa 0/1
2950(config-if)#description sales printer
2950(config-if)#^z
可以使用show interface和show running-config命令来查看这些描述信息
erasing the switch configuration
1900和2950的配置文件是存储在nvram里的,但是1900里你不能查看nvram或startup-config的内容,只能查看running-config的内容,在1900里,你对配置所进行的修改自动被复制到nvram里,所以没有copy run start这样的命令;但是2950就有startup-config和running-config,使用copy run start来保存配置到nvram里,擦除2950里startup-config文件使用erase startup-config命令;擦除1900里的使用delete命令.如下:
1900#delete ?
nvram nvram configuration
vtp reset vtp configuration to defaults
1900#delete nvram
2950:
2950#erase startup-config
上一篇文章: 思科MDS与McDATA存储局域网交换机 下一篇文章: CCNA笔记:EIGRP and OSPF

