思科交换机【学习笔记】

一、基础部分

1.保存、重置、查看命令

1-1.保存

Switch#write

1-2.重置

Switch#erase startup-config //清除交换机的启动配置
Switch#deleted flash:vlan.dat //清除交换机的vlan文件
Switch#reload //重启

1-3.查看Show命令

Switch#show running-config //查看当前配置
Switch#show startup-config //查看启动配置
Switch#show vlan //查看vlan
Switch#show etherchannel summary //查看是否形成EtherChannel
Switch#show etherchannel load-balance //查看EtherChannel汇聚方式
Switch#show etherchannel port-channel //查看EtherChannel使用协议及对应端口

2.敲错命令后dns解析过慢的解决方法

错误样式:
在这里插入图片描述

2-1.使用快捷键
快捷键:Ctrl+Shift + 6

2-2.修改配置

Switch>enable
Switch#configure terminal 
Switch(config)#no ip domain-lookup 

3.配置交换机远程登陆

3-1.telnet登陆

Switch>enable //特权模式
Switch#configure terminal //全局模式
Switch(config)#line vty 0 15 //指定vty线路并进入配置
Switch(config-line)#login local //登陆需要用户名和密码
Switch(config-line)#transport input telnet  //开启telnet服务
Switch(config)#username test password test //回到全局模式创建用户和密码

3-2.ssh登陆
(省略)

4.access配置(划分vlan)

4-1.创建vlan
全局模式下直接输入vlan+编号即可

例:
Switch(config)#vlan 2
Switch(config-vlan)#name XXX //vlan命名

4-2.端口添加vlan

Switch(config)#interface fastEthernet 0/1 //进入对应端口
Switch(config-if)#switchport mode access //修改端口模式为access
Switch(config-if)#switchport access vlan 2 //在端口中加入vlan2

4-3.批量为端口添加vlan

Switch(config)#interface range fastEthernet 0/1-3 
Switch(config-if-range)#switchport mode access 
Switch(config-if-range)#switchport access vlan 2 

5.trunk配置

在这里插入图片描述
5-1.修改端口模式为trunk

例:
Switch(config)#interface fastEthernet 0/23
Switch(config-if)#switchport trunk encapsulation dot1q //修改trunk链路的封装类型,同一链路的两端封装要相同
Switch(config-if)#switchport mode trunk //修改端口模式为trunk

5-2.trunk模式指定通过vlan
端口修改为trunk模式后,不指定vlan将通过所有vlan

指定通过单vlan

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

指定通过多个不连续vlan(Vlan号之间用 “,” 间隔)

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

指定通过多个连续vlan(Vlan号之间用 “-” 连接)

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

5-3.修改本征vlan(Native Vlan

  • trunk链路上数据帧会根据ISL或者IEEE 802.1q被重新封装;
  • Native Vlan的数据,是不会被重新封装就直接在trunk链路上传输,链路两端Native Vlan需要一致。
Switch(config)#interface fastEthernet 0/23
Switch(config-if)#switchport trunk native vlan 2

6.hybrid配置

  • pvid 端口默认 //默认为vlan1,接入PC时应修改为所属vlan;
  • tagged 打标签 //设备发送数据包均打上标签
  • untagged 去标签 //PC接收数据包均剥离标签

7.配置DHCP

Switch(config)#vlan 10 //创建vlan10
Switch(config)#interface vlan 10 //进入vlan10
Switch(config-if)#ip address 192.168.1.254 255.255.255.0 //配置vlan10地址
Switch(config)#ip dhcp pool vlan10 //创建dhcp池
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0 //配置dhcp地址池
Switch(dhcp-config)#default-router 192.168.1.254  //配置dhcp网关
Switch(config)#interface fastEthernet 0/1  //进入端口0/1
Switch(config-if)#switchport mode access   //配置端口模式为access
Switch(config-if)#switchport access vlan 10 //在端口中加入vlan10

8.端口动态协议:DTP配置(Dynamic Trunking Protocol)

  • 管理员可以用手动的方法指定交换机之间的链路是否形成Trunk,也可以让Cisco交换机自动协商;
  • DTP还可以协商Trunk链路的封装类型。
DTP总结(链路两端是否可以形成Trunk)
nonegotiatenegotiatedesirableauto
nonegotiate××
negotiate
desirable×
auto××
  • nonegotiate:强制端口修改为trunk,不主动请求对方启用trunk,不响应对方的请求,除非对方也强制端口修改成trunk否则无法形成trunk
  • negotiate:强制端口修改为trunk,主动请求对方启用trunk,响应对方的请求;
  • desirable:期望端口修改为trunk,主动请求对方启用trunk,响应对方的请求,对方响应请求则协商成trunk
  • auto:不主动请求对方启用trunk,响应对方的请求,对方主动请求成功协商成trunk

个人思路:核心动态协商模式为negotiate,汇聚动态协商模式为auto或desirable,可自动协商汇聚设备的端口模式

8-1.种动态协商模式的修改方法
(1)动态协商模式为nonegotiate

Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#switchport mode trunk
Switch(config-if)#switchport nonegotiate //默认值

(2)动态协商模式为negotiate

Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#switchport mode trunk
Switch(config-if)#no switchport nonegotiate  //默认非动态协商

(3)动态协商模式为desirable(不必手动修改trunk)

Switch(config-if)#switchport mode dynamic desirable
Switch(config-if)#switchport trunk encapsulation dot1q 

(4)动态协商模式为auto(不必手动修改trunk)

Switch(config-if)#switchport mode dynamic auto
Switch(config-if)#switchport trunk encapsulation dot1q

9.链路汇聚:EtherChannel配置

  • EtherChannel是交换机之间的多条链路捆绑技术;
  • 达到增加带宽、均衡流量分配、负载分担的作用;
  • EtherChannel要求物理端口有同一特性,如access或trunk以及都是三层端口,无法混合捆绑
  • 一个EtherChannel最多捆绑16个端口,其中最多8个活动端口
  • EtherChannel可以使用自动协商协议
  • 以下表格中“NO”表示管理员手动配置EtherChannel。
PAGP(Cisc专有协议)协商的规律总结
NOdesirableauto
NO××
desirable×
auto××
LACP(公共标准)协商的规律总结
NOactivepassive
NO××
active×
passive××

9-1.手动配置EtherChannel
链路两端的channel-group可以不一致,编号只在设备本地有效

Switch(config)#interface port-channel 1 //创建汇聚
Switch(config)#interface range fastEthernet 0/23-24
Switch(config-if-range)#channel-group 1 mode on //指定汇聚,配置为no模式
Switch(config-if-range)#switchport trunk encapsulation dot1q
Switch(config-if-range)#switchport mode trunk
Switch(config)#port-channel load-balance dst-ip //配置均衡方式

均衡方式:
src-ip         -IP
dst-ip         -目的IP
src-dst-ip     -IP和目的IP组合
src-mac        -源Mac
dst-mac        -目的MAC
src-dst-mac    -MAC和目的MAC组合
部分支持:      
src-port       -源端口
dst-port       -目的端口
src-dst-port   -源端口和目的端口组合

9-2.自动协商汇聚协议:RAGP配置

Switch(config)#interface range fastEthernet 0/23-24
Switch(config-if-range)#channel-portocol pagp //修改ethernet协议
Switch(config-if-range)#channel-group 1 mode desirable //指定汇聚,配置为desirable协商模式
Switch(config-if-range)#switchport trunk encapsulation dot1q
Switch(config-if-range)#switchport mode trunk

9-3.自动协商汇聚协议:LACP配置

Switch(config)#interface range fastEthernet 0/23-24
Switch(config-if-range)#channel-portocol lacp //修改ethernet协议
Switch(config-if-range)#channel-group 1 mode active //指定汇聚,配置为active协商模式
Switch(config-if-range)#switchport trunk encapsulation dot1q
Switch(config-if-range)#switchport mode trunk

10.Vlan动态协议:VTP配置(VLAN Trunking Protocol)

  • VTP协议:将变化通告其他交换机,其他交换机自动更新Vlan的信息(VLAN id与VLAN name);
  • VTP域:在相邻交换机,同VTP域VTP域name相同)的交换机才能同步VLAN信息,无法跨VTP域
  • VTP通告:只能在Trunk链路上传输;
  • VTP通告:中修订号是32位数字,数字越大级别越高,反之反向覆盖VLAN信息;
  • VTP修剪功能:可以提高带宽利用率;
  • 交换机在VTP域中作用不同,VTP可以分为3种模式
VTP模式比较
模式能创建、修改、删除VLAN能转发VTP信息会根据收到VTP包更改VLAN信息会保存VLAN信息会影响其他交换机上的VLAN
Server(服务器)
Client(客户)否(见提醒)
Transparent(透明)是(非自身是(自身
  1. Server(服务器模式):特点见上表格;
    Ps:交换机默认服务器模式,VTP域至少有一台服务器,可以多台;
  2. Client(客户机模式):特点见上表格;
    Ps:VLAN信息保存在RAM中,重启数据丢失
  3. Transparent(透明模式):特点见上表格;
    Ps:会保存VLAN信息:仅保存自身VLAN信息
    在这里插入图片描述

10-1.配置模式为Server,配置VTP域名
相邻交换机,同VTP域才会更新VLAN信息,无法跨VTP域

Switch#show vtp status //查看默认VTP情况
Switch#config //进入全局模式
Switch(config)#vtp mode server //配置VTP模式为Server
Switch(config)#vtp domain XXXX //配置VTP域名

10-2.配置模式为Transparent

Switch(config)#vtp mode transparent //配置VTP模式为Transparent

10-3.配置模式为Client

Switch(config)#vtp mode client //配置VTP模式为Client

10-4.配置VTP密码

Switch#show vtp password //查看VTP密码
Switch(config)#vtp password XXX //配置VTP密码

10-5.配置VTP版本,只能在Server上配置

Switch(config)#vtp version X //配置VTP版本

11.私有VLAN(隔离作用)

普通端口隔离:switchport protected(protected 端口可以访问 非protected 端口);

  • VTP模式transparent,才能配置PVLAN

私有VLAN端口类型
(1)IsoIated Port(隔离端口)
(2)Community Port(团体端口)
(3)Promiscuous Port(混杂端口)
在这里插入图片描述

私有VLAN互相通信总结
IsoIatedCommunityPromiscuous普通vlan
IsoIated××
Community×
Promiscuous
普通vlan

在这里插入图片描述
11-1.配置pvlan中团体vlan

Switch(config)#vtp mode transparent //VTP模式必须是transparent才能配置PVLAN
Switch(config)#vlan 101 //创建普通vlan101
Switch(config-vlan)#private-vlan community //指定私有vlan是辅助vlan团体
Switch(config)#vlan 100 //创建普通vlan100
Switch(config-vlan)#private-vlan primary //指定私有vlan是主vlan
Switch(config-vlan)#private-vlan association 101 //将辅助vlan101加入主vlan
Switch(config)#interface fastEthernet 0/1 //进入0/1端口
Switch(config-if)#switchport mode private-vlan host //修改端口模式为私有vlan团体
Switch(config-if)#switchport private-vlan host-association 100 101 //关联主vlan与辅助vlan

11-2.配置pvlan中隔离vlan

Switch(config)#vlan 102 //创建普通vlan102
Switch(config-vlan)#private-vlan isolated //指定私有vlan是辅助vlan团体
--1.使用相同方法将辅助vlan102加入主vlan100中
--2.使用相同方法配置端口

11-3.配置pvlan中混杂vlan

Switch(config)#interface fastEthernet 0/10 //进入0/10端口
Switch(config-if)#switchport mode private-vlan promiscuous //修改端口模式为私有vlan混杂
Switch(config-if)#switchport private-vlan mapping 100 101,102 //关联主vlan与辅助vlan

二、STP生成树

1.STP配置与PVST配置

  • 目的:解决交换环路
  • 为了在网络中形成没有环路的拓扑,交换机需要完成:
    1. 每个网络环境中选举一个根桥
    2. 每个非根桥上选举一个根口
    3. 每段链路选举一个指定口
  • 取决于以下因素:
    最小的根桥ID > 最小的根路径代价 > 最小发送者桥ID > 最小发送者端口ID
  • 交换机端口的5种状态
    ①阻塞(Blocking)②转发(Forwarding)③禁用(Disable)④监听(Listening)⑤学习(Learning)
STP各端口状态总结
状 态阻 塞转 发禁 用监 听学 习
接收并处理BPDU×
接收端口上收到的数据帧××××
发送其他端口交换过来的数据帧××××
学习MAC地址×××

1-1.检查默认STP树

Switch#show spanning-tree

1-2.修改根桥优先级方法

1)指定根桥优先级
Switch(config)#spanning-tree vlan 1 priority 4096 //默认值为327682)指定比根桥优先级低
Switch(config)#spanning-tree vlan 1 root secondary
(3)指定比根桥优先级高
Switch(config)#spanning-tree vlan 1 root primary
根桥数值越小,优先级越高

1-3.修改根桥路径方法

Switch(config)#interface fastEthernet 0/1 //进入端口0/1
Switch(config-if)#spanning-tree vlan 1 cost 18 //修改路径值为18

1-4.修改端口优先级方法

Switch(config)#interface fastEthernet 0/1 //进入端口0/1
Switch(config-if)#spanning-tree vlan 1 port-priority 112 //默认值为128
数值越小,优先级越高,优先级为16的倍数

2.STP加强配置(portfast、uplinkfast、backbonefast)

  • portfast:使端口立即进入转发状态,适合不运行STP的设备,设置portfast后,端口up或down,交换机不再发送TCN消息;
  • uplinkfast:链路出现故障时,可及时切换至备份链路(2~3s),适合接入层交换机,uplinkfast只需要在接入层交换机配置,uplinkfast可能导致严重的不稳定,不应出现在核心层或分布层;
  • backbonefast:链路出现故障时,可及时切换至备份链路(20~30s),适合主干交换机,backbonefast需要在全部交换机上配置
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值