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-ccTrunk链路上发送VTP通告;
  • VTP Serverclients通过最高的修订号来同步数据库;
  • 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

网络架构图
avatar

具体配置如下:

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         active

VLAN 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         active

VLAN 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

原文地址:https://www.cnblogs.com/winstom/p/9357643.html