CCNA 之 八 交换基础 VLAN TRUNK VTP
交换基础
主要知识点:
- 二层交换基础
- Vlan的概念
- Trunk的概念
- VTP
- 二层交换基本配置
首先来看下园区网分层结构

交换机的主要功能:
- Address learning 学习MAC地址
会维护一张MAC地址表,数据会根据此张表进行数据转发
- Forward/filter decision
转发和过滤的决策,主要是二层的转发(帧)
- Loop avoidance
环路的避免
MAC地址
硬件地址,一般像网卡,路由器的接口,交换机的端口,会在出厂的时候烧录一个地址。全球唯一;在一个LAN中,是绝对不允许MAC重复;
Vlan的概念
- 分段性
- 灵活性
- 安全性
默认一个没有配置的交换机,所有的接口在一个vlan中;
一个Vlan就是一个独立的广播域,一个单独的逻辑子网。
VLAN的成员模式
- 静态VLAN - 交换机上的端口以手动方式分配给VLAN;
- 动态VLAN - 使用VMPS可以根据链接到交换机端口的设备的源MAC地址,动态的将端口分配给VLAN;
- 语音VLAN - 将端口配置到语音模式可以使端口支持连接到改端口的IP电话;

Trunk的概念
ISL协议(思科私有协议)
- 通过硬件(ASIC)实现
- ISL表示不会出现在工作站,客户端并不知道ISL的封装信息
- 在交换机或路由器与交换机之间,在交换机与具有ISL网卡的服务器之间可以实现;
802.1Q共有协议
802.1Q 帧标记:
- 默认情况,在802.1Q Trunk上对所有的VLAN打Tag,除了Native VLAN;
- 交换机根据以太网帧头信息来转发数据包;
Tag标记字段详细信息:
Tag 标记字段包含一个2 bytes EtherType(以太类型)字段、一个3bits的PRI字段、1bit的CFI字段、12bits的VLAN ID字段;
VLAN的特点
- 一个
VLan钟的所有设备都是在同一个广播域内;广播域不能跨越VLAN传播 - 一个
VLAN为一个逻辑子网;由被配置为此VLAN成员的设备组成,不同的VLAN间需要通过路由器实现相互通信 VLAN中成员多基于Switch端口号码,划分VLAN就是对Switch接口划分VLAN工作于OSI参考模型的第二层
VLAN的范围
如下图:

VTP
VTP是思科的私有协议;使用性质不广泛;
- 一个能够宣告
VLAN配置信息的信息系统; - 通过一个工友的管理俞,维持
VLAN配置信息的一致性; VTP只能在主干端口发送和宣告的信息;- 支持混合的截止主干链接(快速以太网,FDDI,ATM);

VTP的运作
VTP协议通过组播地址01-00--c-cc-cc-cc在Trunk链路上发送VTP通告;VTP Server和clients通过最高的修订号来同步数据库;VTP协议每隔5分钟发送一次VTP通告或者有变化时发生;

VLAN的配置
VLAN的基本配置
分为两步:
第一步:创建VLAN信息
Switch(config)#vlan 2
Switch(config-vlan)#name VLAN2
第二步:将端口划入特定的VLAN
Switch(config)#interface fa0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access [vlan vlan# | dynamic]
Trunk的基本配置
第一步:配置Trunk封装方式
Switch(config)#interface f0/5
Switch(config-if)#switchport trunk encapsulation {isl | dot1q | negotiate}
第二步:开启端口trunk模式
Switch(config-if)#switchport mode {dynamic {auto | desirable} | trunk}
VTP的基本配置
Switch#configure terminal
Switch(config)#vtp mode [server | client | transparent]
Switch(config)#vtp domain domain-name
Switch(config)#vtp password password
Switch(config)#vtp runing
备注:
- 默认情况:VTP模式为server;
- VTP域名有大小敏感;
- VTP修建默认关闭;
Trunk 基本配置
本次试验环境中的交换机和PC都使用路由器来代替;
路由代替PC配置:
下面是配置案例
R3>en
R3#conf t
R3(config)#hostname PC1
PC1(config)#no ip routing
PC1(config)#int f 0/0
PC1(config-if)#ip add 192.168.1.1 255.255.255.0
PC1(config-if)#no shutdown
网络架构图

具体配置如下:
SW1
R1>en
R1#conf t
R1(config)#hostname SW1
SW1(config)#exit
SW1#
SW1#vlan database
SW1(vlan)#vlan 10
VLAN 10 modified:
SW1(vlan)#vlan 20
VLAN 20 modified:
SW1(vlan)#exit
APPLY completed.
Exiting....
SW1#conf t
SW1(config)#int f 0/1
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 10
SW1(config-if)#int f 0/2
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 20
SW1(config-if)#int f 0/15
SW1(config-if)#switchport trunk encapsulation dot1q
SW1(config-if)#switchport mode trunk
SW1(config-if)#end
查看SW1配置:
SW1#show vlan-s
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/0, Fa0/3, Fa0/4, Fa0/5
Fa0/6, Fa0/7, Fa0/8, Fa0/9
Fa0/10, Fa0/11, Fa0/12, Fa0/13
Fa0/14
10 VLAN0010 active > Fa0/1
20 VLAN0020 active > Fa0/2
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-defaul activeVLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 >- - - - >- 1002 1003
10 enet 100010 1500 >- - - - >- 0 0
20 enet 100020 1500 - - >- - - 0 0
1002 fddi 101002 1500 - >- - - - > 1 1003
1003 tr 101003 1500 1005 >0 - - >srb 1 1002
1004 fdnet 101004 1500 - >- 1 ibm - > 0 0
1005 trnet 101005 1500 - >- 1 ibm - &nbs>p; 0 0
SW1#show interfaces trunk
Port Mode Encapsulation Status Native vlan
Fa0/15 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/15 1-1005
Port Vlans allowed and active in management domain
Fa0/15 1,10,20
Port Vlans in spanning tree forwarding state and not pruned
Fa0/15 1,10,20
SW2
R2>en
R2#conf t
R2(config)#hostname SW2
SW2(config)#exit
SW2#vlan database
SW2(vlan)#vlan 10
VLAN 10 modified:
SW2(vlan)#vlan 20
VLAN 20 modified:
SW2(vlan)#exit
APPLY completed.
Exiting....
SW2#conf t
SW2(config)#int f 0/1
SW2(config-if)#switchport mode access
SW2(config-if)#switchport access vlan 10
SW2(config-if)#int f 0/2
SW2(config-if)#switchport mode access
SW2(config-if)#switchport access vlan 20
SW2(config-if)#int f 0/15
SW2(config-if)#switchport trunk encapsulation dot1q
SW2(config-if)#switchport mode trunk
查看SW2配置:
SW2#show vlan-s
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/0, Fa0/3, Fa0/4, Fa0/5
Fa0/6, Fa0/7, Fa0/8, Fa0/9
Fa0/10, Fa0/11, Fa0/12, Fa0/13
Fa0/14
10 VLAN0010 active > Fa0/1
20 VLAN0020 active > Fa0/2
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-defaul activeVLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 >- - - - >- 1002 1003
10 enet 100010 1500 >- - - - >- 0 0
20 enet 100020 1500 - - >- - - 0 0
1002 fddi 101002 1500 - >- - - - > 1 1003
1003 tr 101003 1500 1005 >0 - - >srb 1 1002
1004 fdnet 101004 1500 - >- 1 ibm - > 0 0
1005 trnet 101005 1500 - >- 1 ibm - &nbs>p; 0 0
SW2#show interfaces trunk
Port Mode Encapsulation Status Native vlan
Fa0/15 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/15 1-1005
Port Vlans allowed and active in management domain
Fa0/15 1,10,20
Port Vlans in spanning tree forwarding state and not pruned
Fa0/15 1,10,20
PC1配置:
R3>en
R3#conf t
R3(config)#hostname PC1
PC1(config)#no ip routing
PC1(config)#int f 0/0
PC1(config-if)#ip add 192.168.1.1 255.255.255.0
PC1(config-if)#no shutdown
PC2配置:
R4>en
R4#conf t
R4(config)#hostname PC2
PC2(config)#no ip routing
PC2(config)#int f 0/0
PC2(config-if)#ip address 192.168.2.1 255.255.255.0
PC2(config-if)#no shutdown
PC3配置:
R5>en
R5#conf t
R5(config)#hostname PC3
PC3(config)#no ip routing
PC3(config)#int f 0/0
PC3(config-if)#ip add 192.168.1.2 255.255.255.0
PC3(config-if)#no sh
PC4配置:
R6>en
R6#conf t
R6(config)#hostname PC4
PC4(config)#no ip routing
PC4(config)#int f 0/0
PC4(config-if)#ip add 192.168.2.2 255.255.255.0
PC4(config-if)#no sh
验证:
只要在PC1上能ping通PC3,在PC2上能ping通PC4的地址,则表示试验完成;
PC1验证:
PC1#ping 192.168.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
.!!!!
P2验证:
PC2#ping 192.168.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.2, timeout is 2 seconds:
.!!!!
单臂路由
上面的试验配置了两个VLAN,而这两个VLAN之间是不能相同通信的,如果想实现相互访问,则需要通过路由
本次使用单臂路由的方式,也就是在一个借口上,同时跑两个VLAN,使之能通信;
增加一个路由,如下图:

配置如下:
使用上面的试验,其他所有的设备不需要配置,需要对SW2和对R3进行配置
需要把SW2的 f0/0 接口配置成Trunk
SW2配置:
R2(config)#int f 0/0
R2(config-if)#switchport mode trunk
R2(config-if)#switchport trunk encapsulation dot1q
R3配置:
R3>en
R3#conf t
R3(config)#int f 0/0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#int f 0/0.10
R3(config-subif)#encapsulation dot1Q 10
R3(config-subif)#ip add 192.168.1.254 255.255.255.0
R3(config-subif)#no sh
R3(config-subif)#int f 0/0.20
R3(config-subif)#encapsulation dot1Q 20
R3(config-subif)#ip add 192.168.2.254 255.255.255.0
R3(config-subif)#no sh
R3(config-subif)#exit
R3(config)#exit
R3#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0.10
C 192.168.2.0/24 is directly connected, FastEthernet0/0.20
R3#show ip int b
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset up up
FastEthernet0/0.10 192.168.1.254 YES manual up up
FastEthernet0/0.20 192.168.2.254 YES manual up up
验证
PC1:
PC1#ping 192.168.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/12/36 ms
PC2:
PC2#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/22/60 ms
CCNA 之 八 交换基础 VLAN TRUNK VTP的更多相关文章
- 2.1-VLAN/TRUNK/VTP
2.1-VLAN/TRUNK/VTP 注意:配置VLAN时要退出VLAN配置模式才会执行 如果VLAN被删除或者shutdown,那么属于这个vlan的接口将被阻塞(灯一直是橙色,变不了绿色) ...
- 实验13:VLAN/TRUNK/VTP/
实验10-1: 划分VLAN Ø 实验目的通过本实验,读者可以掌握如下技能:(1) 熟悉VLAN 的创建(2) 把交换机接口划分到特定VLAN Ø 实验拓扑 实验步骤要配置VLAN,首先要 ...
- vlan trunk vtp端口聚合
第一步:端口聚合(两端都需要做相同的操作) 第二步:在服务器端配置为服务器模式 第四步:在服务器端添加vlan 第五步:在两端分别将不同的端口添加到不同的vlan
- 交换知识 VLAN VTP STP 单臂路由
第1章 交换基础 1.1 园区网分层结构 层次 作用 出口层 广域网接入 出口策略 带宽控制 核心层 高速转发 服务器接入 路由选择 汇聚层 流量汇聚 链路冗余 设备冗余 路由选择 接入层 用户接入 ...
- 交换机上的trunk,hybrid,access配置和应用(转)
交换机上的trunk,hybrid,access配置和应用 以太网端口的链路类型: Access类型:端口只能属于一个vlan,一般用于连接计算机. Trunk类型:端口可以属于端个vlan,可以接收 ...
- vlan trunk配置
vlan trunk配置 Trunk:中继干道 作用:一条链路能承载多个vlan的流量,并对不同vlan的流量进行不同标记 trunk能够使vlan跨越交换机 PT配置 配置vlan:两台交换机同样的 ...
- Swift语言指南(八)--语言基础之元组
原文:Swift语言指南(八)--语言基础之元组 元组 元组(Tuples)将多个值组合为一个复合值.元组内的值可以是任何类型,各个元素不需要为相同类型(各个元素之间类型独立,互不干扰--Joe.Hu ...
- 实验八 Web基础 SQL注入原理
实验八 Web基础 实验要求 (1)Web前端HTML 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. (2)Web前端javascipt ...
- 2017-2018-2 20155225《网络对抗技术》实验八 Web基础
2017-2018-2 20155225<网络对抗技术>实验八 Web基础 1.Web前端HTML 输入命令apachectl start打开apahce,并使用netstat -aptn ...
随机推荐
- Flask:网页路由及请求方式的设定
1.Flask路由的实现 Flask的路由是由route装饰器来实现的 @app.route("/index/") def index(): return "hello ...
- SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列
分享一道今天的面试题:SQL语句实现:数据库中有A B C三列,当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列 第一种:使用case when...then...else ...
- TICK技术栈(三)InfluxDB安装及使用
1.什么是InfluxDB? InfluxDB是一个用Go语言开发的时序数据库,用于处理高写入和查询负载,专门为带时间戳的数据编写,对DevOps监控,IoT监控和实时分析等应用场景非常有用.通过自定 ...
- InfluxDB常见疑问与解答 - 数据写入时如何在表级别指定保留策略
网友Siguoei:我想让一个库中不同的measurment能够指定不同的保存策略.而不是写入时使用数据库的默认保留策略. Answer:这个特性InfluxDB支持的,写入时序数据时,在行协议前加上 ...
- MIT线性代数:8.求解Ax=b,可解性和结构
- 学习笔记55_Nhibernate
另一种ORM框架 1.添加各种dll 2.添加配置信息,根据文档直接复制粘贴.config //一般下载Nhibernate-3.0.0.Alpha2-bin包,会有Configuration_Tem ...
- 奶牛邻居——treap+契比雪夫距离+并查集
题目描述 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发现她们已经结成了几个“群”. 每只奶牛在吃草的时候有一个独一无二的位置坐标Xi,Yi(l≤Xi,Yi ...
- 创建windows系统下的虚拟机
创建新的虚拟机 添加映像(windows系统下必须先添加映像) 选择相应的镜像文件:网上查找密钥输入:版本按要求选择:单击 下一步:设置虚拟机名称 位置 :下一步 默认的磁盘大小(不用管)——下一 ...
- HashMap深入分析及使用要点
本文内容来自深入理解HashMap.从数据结构谈HashMap.HashMap深度分析 先说使用要点. 1.不要在并发场景中使用HashMap HashMap是线程不安全的,如果被多个线程共享的操作, ...
- 小白学 Python(23):Excel 基础操作(上)
人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...