思科主要交换机设备有:Cisco 2906系列、Cisco 3560系列、Cisco 4500系列、Cisco 6500系列。
交换机工作原理
交换机在接收到数据帧以后,首先、会记录数据帧中的源 MAC 地址和对应的接口到 MAC 表中,接着、会检查自己的 MAC 表中是否有数据帧中目标 MAC 地址的信息,如果有则会根据 MAC 表中记录的对应接口将数据帧发送出去 (也就是单播),如果没有,则会将该数据帧从非接受接口发送出去 (也就是广播,或者泛洪 Flood)。
交换机的三个主要功能
交换机接口的双工模式
交换机命令行模式
Cisco交换机包括四种不同的命令行模式,每种命令行模式下所支持的命令也有所不同。
3.1. 用户模式
启动交换机后按Enter键(回车),进入的就是用户模式,在用户模式下的限制很大,只能查看一些统计信息。命令提示符如下:
Switch>
3.2. 特权模式
特权模式顾名思义,有一定的特权(但不多),在用户模式下输入enable或简写en命令,就能进入特权模式,在该模式下可以修改Cisco设备的配置。命令提示符如下:
Switch>enable
Switch#
3.3. 全局配置模式
全局配置模式,可以修改大多数的配置,例如修改设备名称。在特权模式下输入config terminal或简写conf t 命令,就可以进入全局匹配置模式。命令提示符如下:
Switch#config terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#
3.4. 接口模式
针对接口设置,查看自己的接口信息等。在全局配置模式输入interface fastethernet 0/1 或简写int f0/1就可以进入接口模式。命令解释如下:
Switch(config)#interface fastethernet 0/1
Switch(config-if)#
3.5.退出模式方法
实例如下:
Switch(config-if)#exit
Switch(config)#exit
Switch#
disable
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#end
Switch#
四种模式的进入有很明显的层次关系,想要进入全局模式就必须先进入特权模式不能直接跳到全局模式。退出的话只有end命令可以跳到特权模式,其他都是一层一层退出。
交换机常见命令
帮助命令
1.1. ”?“的用法
显示该模式下的所有命令及注释,按空格翻页,按回车下一行,q退出。也可以使用命令后加?查看该命令后的参数。
Switch#?
Exec commands:
clear Reset functions
clock Manage the system clock
configure Enter configuration mode
connect Open a terminal connection
copy Copy from one file to another
debug Debugging functions (see also 'undebug')
delete Delete a file
dir List files on a filesystem
#省略部分内容
Switch(config)#int ?
Ethernet IEEE 802.3
FastEthernet FastEthernet IEEE 802.3
GigabitEthernet GigabitEthernet IEEE 802.3z
Port-channel Ethernet Channel of interfaces
Vlan Catalyst Vlans
range interface range command
1.2. Tab键
这个用法就很简单了,它表示自动补全,为了命令的正确或者忘记命令;甚至简写就是默认使用Tab补全的,当然也可以不补全,一样会生效。
Switch(config)#interface f #敲到f的时候按Tab键
Switch(config)#interface fastEthernet #自动补充命令
1.3. 常用的快捷键
常用命令介绍
2.1. hostname
用于配置主机名,可简写为host
Switch(config)#host sw1
sw1(config)#
2.2. show version
用于显示系统ios名称及版本信息,可简写为sh ser(注意:在用户或特权模式,如果在全局模式需要在命令前加do)
sw1#sh ver
Cisco Internetwork Operating System Software
IOS (tm) C2950 Software (C2950-I6Q4L2-M), Version 12.1(22)EA4, RELEASE SOFTWARE(fc1)
Copyright (c) 1986-2005 by cisco Systems, Inc.
Compiled Wed 18-May-05 22:31 by jharirba
Image text-base: 0x80010000, data-base: 0x80562000
ROM: Bootstrap program is is C2950 boot loader
Switch uptime is 54 minutes, 37 seconds
System returned to ROM by power-on
#省略部分内容
交换机的基本配置
拓扑如下:根据下图搭建设备,pc配置:单击pc,点击Desktop,选择IP configuration配置网络,Command Prompt用来测试网络是否连接。
3.1. 查看MAC地址
dynamic:可选参数,可以使交换机只显示动态学习到的MAC地址。
sw1#show mac-address-table dynamic
Mac Address Table
-------------------------------------------
Vlan Mac Address Type Ports
---- ----------- -------- -----
1 000a.4104.9674 DYNAMIC Fa0/2
1 000c.8543.920e DYNAMIC Fa0/3
1 0090.0c10.88d8 DYNAMIC Fa0/1
配置接口的双工模式及速率
4.1. 指定接口的双工模式
命令格式如下:
duplex {full | half | auto }
配置实例:打开两台交换机,分别指定为全双工和半双工。
sw1(config)#int f0/1
sw1(config-if)#duplex full
sw2(config)#int f0/1
sw2(config-if)#duplex half
在实验环境中,双工不匹配,也可能ping通网络,这是因为通信量小。工作环境中,交换机的链路会很繁忙,可能会出现很严重的丢包现象。
如果ping不同,这里把sw1修改成半双工,这样就可以ping通了。
sw1(config)#int f0/1
sw1(config-if)#duplex half
4.2. 指定接口的通信速率
命令格式如下:
speed {10 | 100 | 1000 | auto }
配置实例:指定sw1接口速率10,sw2接口速率100
sw1(config)#int f0/1
sw1(config-if)#speed 10
sw2(config)#int f0/1
sw2(config-if)#speed 100
这是通过ping命令,发现两台交换机无法正常通信。
查看sw1交换机接口的双工模式和通信速率
sw1(config-if)#do sh int f0/1
FastEthernet0/1 is down, line protocol is down (disabled)
Hardware is Lance, address is 0060.5c33.7d01 (bia 0060.5c33.7d01)
BW 10000 Kbit, DLY 1000 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Half-duplex, 10Mb/s
#省略部分内容
下面把两个交换机的双工模式和速率修改为auto
sw1(config)#int f0/1
sw1(config-if)#duplex auto
sw1(config-if)#speed auto
sw2(config)#int f0/1
sw2(config-if)#duplex auto
sw2(config-if)#speed auto
然后在查看sw1交换机的接口,可以看到自动协商为全双工,通信速率协商为100。
sw1(config-if)#do sh int f0/1
FastEthernet0/1 is up, line protocol is up (connected)
Hardware is Lance, address is 0060.5c33.7d01 (bia 0060.5c33.7d01)
BW 100000 Kbit, DLY 1000 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s
#省略部分内容