多层交换机VLAN的划分和VLAN间路由

更新时间:2023-04-11 04:18:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

多层交换机VLAN的划分和VLAN间路由

一、实验目的

1、了解VLAN原理;

2、学会使用各种多层交换设备进行VLAN的划分;

3、理解VLAN之间路由的原理和实现方法;

二、应用环境

软件实验室的IP地址段是192.168.10.0/24,多媒体实验室的IP地址段是192.168.20.0/24,为了保证它们之间的数据互不干扰,也不影响各自的通信效率,我们划分了VLAN,使两个实验室属于不同的VLAN。

两个实验室有时候也需要相互通信,此时就要利用三层交换机划分VLAN。

三、实验设备

1、DCRS-7604(或6804或5526S)交换机1台

2、PC机2台

3、Console线1根

4、直通网线若干

四、实验拓扑

使用一台交换机和两台PC机,还将其中PC2作为控制台终端,使用Console口配置方式;使用两根网线分别将PC1和PC2连接到交换机的RJ-45接口上。

五、实验要求

使得VLAN100VLAN100和VLAN200成员之间不能互相访问。

PC1和PC2的网络设置为:

再按照IP2配置地址,并在交换机上配置vlan接口IP地址,使用pc1 ping pc2,则通,该通信属于vlan间通信,要经过三层设备的路由。

若实验结果和理论相符,则本实验完成。

六、实验步骤

第一步:交换机恢复出厂设置

switch#set default

switch#write

switch#reload

第二步:给交换机设置IP地址即管理IP。

switch#config

switch(Config)#interface vlan 1

switch(Config-If-Vlan1)#ip address 192.168.1.1 255.255.255.0 switch(Config-If-Vlan1)#no shutdown

switch(Config-If-Vlan1)#exit

switch(Config)#exit

第三步:创建vlan100和vlan200。

switch(Config)#

switch(Config)#vlan 100

switch(Config-Vlan100)#exit

switch(Config)#vlan 200

switch(Config-Vlan200)#exit

switch(Config)#

验证配置:

switch#show vlan

VLAN Name Type Media Ports

---- ------------ ---------- --------- ---------------------------------------- 1 default Static ENET Ethernet1/1 Ethernet1/2

Ethernet1/3 Ethernet1/4

Ethernet1/5 Ethernet1/6

Ethernet1/7 Ethernet1/8

Ethernet1/9 Ethernet1/10

Ethernet1/11 Ethernet1/12

Ethernet1/13 Ethernet1/14

Ethernet1/15 Ethernet1/16

Ethernet1/17 Ethernet1/18

Ethernet1/19 Ethernet1/20

Ethernet1/21 Ethernet1/22

Ethernet1/23 Ethernet1/24

Ethernet1/25 Ethernet1/26

Ethernet1/27 Ethernet1/28

100 VLAN0100 Static ENET

200 VLAN0200 Static ENET

第四步:给vlan100和vlan200添加端口。

switch(Config)#vlan 100 !进入vlan 100

switch(Config-Vlan100)#switchport interface ethernet 1/1-12

Set the port Ethernet1/1 access vlan 100 successfully

Set the port Ethernet1/2 access vlan 100 successfully

Set the port Ethernet1/3 access vlan 100 successfully

Set the port Ethernet1/4 access vlan 100 successfully

Set the port Ethernet1/5 access vlan 100 successfully

Set the port Ethernet1/6 access vlan 100 successfully

Set the port Ethernet1/7 access vlan 100 successfully

Set the port Ethernet1/8 access vlan 100 successfully

Set the port Ethernet1/9 access vlan 100 successfully

Set the port Ethernet1/10 access vlan 100 successfully

Set the port Ethernet1/11 access vlan 100 successfully

Set the port Ethernet1/12 access vlan 100 successfully

switch(Config-Vlan100)#exit

switch(Config)#vlan 200 !进入vlan 200

switch(Config-Vlan200)#switchport interface ethernet 1/13-24

Set the port Ethernet1/13 access vlan 200 successfully

Set the port Ethernet1/14 access vlan 200 successfully

Set the port Ethernet1/15 access vlan 200 successfully

Set the port Ethernet1/16 access vlan 200 successfully

Set the port Ethernet1/17 access vlan 200 successfully

Set the port Ethernet1/18 access vlan 200 successfully

Set the port Ethernet1/19 access vlan 200 successfully

Set the port Ethernet1/20 access vlan 200 successfully

Set the port Ethernet1/21 access vlan 200 successfully

Set the port Ethernet1/22 access vlan 200 successfully

Set the port Ethernet1/23 access vlan 200 successfully

Set the port Ethernet1/24 access vlan 200 successfully

switch(Config-Vlan200)#exit

验证配置:

switch#show vlan

VLAN Name Type Media Ports

---- ------------ ---------- --------- ---------------------------------------- 1 default Static ENET Ethernet1/25 Ethernet1/26

Ethernet1/27 Ethernet1/28

100 VLAN0100 Static ENET Ethernet1/1 Ethernet1/2

Ethernet1/3 Ethernet1/4

Ethernet1/5 Ethernet1/6

Ethernet1/7 Ethernet1/8

Ethernet1/9 Ethernet1/10

Ethernet1/11 Ethernet1/12

200 VLAN0200 Static ENET Ethernet1/13 Ethernet1/14

Ethernet1/15 Ethernet1/16

Ethernet1/17 Ethernet1/18

Ethernet1/19 Ethernet1/20

Ethernet1/21 Ethernet1/22

Ethernet1/23 Ethernet1/24

switch#

第五步:验证实验。

第六步:添加vlan地址。

switch(Config)#interface vlan 100

switch(Config-If-Vlan100)#%Feb 13 15:47:45 2006 %LINK-5-CHANGED: Interface Vlan100, changed state to UP%Feb 13 15:47:45 2006 %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan100, changed state to UP

switch(Config-If-Vlan100)#

switch(Config-If-Vlan100)#ip address 192.168.10.1 255.255.255.0

switch(Config-If-Vlan100)#no shut

switch(Config-If-Vlan100)#exit

switch(Config)#interface vlan 200

switch(Config-If-Vlan200)#%Feb 13 15:48:06 2006 %LINK-5-CHANGED: Interface Vlan200, changed state to UPswitch(Config-If-Vlan200)#ip address 192.168.20.1 255.255.255.0

switch(Config-If-Vlan200)#no shut

switch(Config-If-Vlan200)#exit

switch(Config)#

验证配置:

switch#show ip route

Total route items is 3, the matched route items is 3

Codes: C - connected, S - static, R - RIP derived, O - OSPF derived

A - OSPF ASE,

B - BGP derived, D - DVMRP derived

Destination Mask Nexthop Interface Preference

C 192.168.1.0 255.255.255.0 0.0.0.0 Vlan1 0

C 192.168.10.0 255.255.255.0 0.0.0.0 Vlan100 0

C 192.168.20.0 255.255.255.0 0.0.0.0 Vlan200 0 switch#

第七步:验证实验。

七、注意事项和排错

和二层交换机不同,三层交换机可以在多个VLAN接口上配置IP地址。

八、配置序列

switch#show run

Current configuration:

!

hostname switch

!

Vlan 1

vlan 1

!

Vlan 100

vlan 100

!

Vlan 200

vlan 200

!

Interface Ethernet1/1

switchport access vlan 100 !

Interface Ethernet1/2

switchport access vlan 100 !

Interface Ethernet1/3

switchport access vlan 100 !

Interface Ethernet1/4

switchport access vlan 100 !

Interface Ethernet1/5

switchport access vlan 100 !

Interface Ethernet1/6

switchport access vlan 100 !

Interface Ethernet1/7

switchport access vlan 100 !

Interface Ethernet1/8

switchport access vlan 100 !

Interface Ethernet1/9

switchport access vlan 100 !

Interface Ethernet1/10

switchport access vlan 100 !

Interface Ethernet1/11

switchport access vlan 100 !

Interface Ethernet1/12

switchport access vlan 100 !

Interface Ethernet1/13

switchport access vlan 200 !

Interface Ethernet1/14

switchport access vlan 200 !

Interface Ethernet1/15

switchport access vlan 200 !

Interface Ethernet1/16

switchport access vlan 200 !

Interface Ethernet1/17

switchport access vlan 200 !

Interface Ethernet1/18

switchport access vlan 200 !

Interface Ethernet1/19

switchport access vlan 200 !

Interface Ethernet1/20

switchport access vlan 200 !

Interface Ethernet1/21

switchport access vlan 200 !

Interface Ethernet1/22

switchport access vlan 200 !

Interface Ethernet1/23

switchport access vlan 200 !

Interface Ethernet1/24

switchport access vlan 200 !

Interface Ethernet1/25

!

Interface Ethernet1/26

!

Interface Ethernet1/27

!

Interface Ethernet1/28

!

!

interface Vlan1

interface vlan 1

ip address 192.168.1.1 255.255.255.0

!

interface Vlan100

interface vlan 100

ip address 192.168.10.1 255.255.255.0

!

interface Vlan200

interface vlan 200

ip address 192.168.20.1 255.255.255.0

!

Interface Ethernet0

switch#

九、共同思考

如果第二次配置IP地址的时候,没有给PC机配置网关,请问还会通信么?为什么?。

十、课后练习

请给交换机划分多个vlan,验证vlan实验。

十一、相关配置命令详解

vlan

命令:vlan

no vlan

功能:创建VLAN并且进入VLAN配置模式,在VLAN模式中,用户可以配置VLAN名称和为该VLAN分配交换机端口;本命令的no操作为删除指定的VLAN。

参数:为要创建/删除的VLAN的VID,取值范围为1~4094。

命令模式:全局配置模式

缺省情况:交换机缺省只有VLAN1。

使用指南:VLAN1为交换机的缺省VLAN,用户不能配置和删除VLAN1。允许配置VLAN 的总共数量为4094个。另需要提醒的是不能使用本命令删除通过GVRP学习到的动态VLAN。

举例:创建VLAN100,并且进入VLAN100的配置模式。

DCRS-7604 (Config)#vlan 100

DCRS-7604 (Config-Vlan100)#

name

命令:name

no name

功能:为VLAN指定名称,VLAN的名称是对该VLAN一个描述性字符串;本命令的no 操作为删除VLAN的名称。

参数:为指定的vlan名称字符串。

命令模式:VLAN配置模式

缺省情况:VLAN缺省名称为vlanXXX,其中XXX为VID。

使用指南:交换机提供为不同的VLAN指定名称的功能,有助于用户记忆VLAN,方便管理。

举例:为VLAN100指定名称为TestVlan。

DCRS-7604 (Config-Vlan100)#name TestVlan

switchport access vlan

命令:switchport access vlan

no switchport access vlan

功能:将当前Access端口加入到指定VLAN;本命令no操作为将当前端口从VLAN里删除。

参数:为当前端口要加入的vlan VID,取值范围为1~4094。

命令模式:接口配置模式

缺省情况:所有端口默认属于VLAN1。

使用指南:只有属于Access mode的端口才能加入到指定的VLAN中,并且Access端口同时只能加入到一个VLAN里去。

举例:设置某Access端口加入VLAN100。

DCRS-7604 (Config)#interface ethernet 1/8

DCRS-7604 (Config-ethernet1/8)#switchport mode access

DCRS-7604 (Config-ethernet1/8)#switchport access vlan 100

DCRS-7604 (Config-ethernet1/8)#exit

switchport interface

命令:switchport interface

no switchport interface

功能:给VLAN分配以太网端口的命令;本命令的no操作为删除指定VLAN内的一个或一组端口。

参数: 要添加或者删除的端口的列表,支持”;” ”-” ,如:ethernet 1/1;2;5 或ethernet 1/1-6;8。

命令模式:VLAN配置模式

缺省情况:新建立的VLAN缺省不包含任何端口。

使用指南:Access端口为普通端口,可以加入VLAN,但同时只允许加入一个VLAN。举例:为VLAN100分配百兆以太网端口1,3,4-7,8。

DCRS-7604 (Config-Vlan100)#switchport interface ethernet 1/1;3;4-7;8

switchport mode

命令:switchport mode {trunk|access}

功能:设置交换机的端口为access模式或者trunk模式。

参数:trunk表示端口允许通过多个VLAN的流量;access为端口只能属于一个VLAN。命令模式:接口配置模式

缺省情况:端口缺省为Access模式。

使用指南:工作在trunk mode下的端口称为Trunk端口,Trunk端口可以通过多个VLAN 的流量,通过Trunk端口之间的互联,可以实现不同交换机上的相同VLAN的互通;工作在access mode下的端口称为Access端口,Access端口可以分配给一个VLAN,并且同时只能分配给一个VLAN。

举例:将端口5设置为trunk模式,端口8设置为access模式。

DCRS-7604 (Config)#interface ethernet 1/5

DCRS-7604 (Config-ethernet1/5)#switchport mode trunk

DCRS-7604 (Config-ethernet1/5)#exit

DCRS-7604 (Config)#interface ethernet 1/8

DCRS-7604 (Config-ethernet1/8)#switchport mode access

DCRS-7604 (Config-ethernet1/8)#exit

switchport trunk allowed vlan

命令:switchport trunk allowed vlan {|all}

no switchport trunk allowed vlan

功能:设置Trunk端口允许通过VLAN;本命令的no操作为恢复缺省情况。

参数:为允许在该Trunk端口上通过的VLAN列表;all 关键字表示允许该Trunk 端口通过所有VLAN的流量。

命令模式:接口配置模式

缺省情况:Trunk端口缺省允许通过所有VLAN。

使用指南:用户可以通过本命令设置哪些VLAN的流量通过Trunk端口,没有包含的VLAN 流量则被禁止。

举例:设置Trunk端口允许通过VLAN1,3,5-20的流量。

DCRS-7604 (Config)#interface ethernet 1/5

DCRS-7604 (Config-ethernet1/5)#switchport mode trunk

DCRS-7604 (Config-ethernet1/5)#switchport trunk allowed vlan 1;3;5-20

DCRS-7604 (Config-ethernet1/5)#exit

switchport trunk native vlan

命令:switchport trunk native vlan

no switchport trunk native vlan

功能:设置Trunk端口的PVID;本命令的no操作为恢复缺省值。

参数:为Trunk端口的PVID。

命令模式:接口配置模式

缺省情况:Trunk端口默认的PVID为1。

使用指南:在802.1Q中定义了PVID这个概念。Trunk端口的PVID的作用是当一个untagged 的帧进入Trunk端口,端口会对这个untagged帧打上带有本命令设置的native PVID的tag 标记,用于VLAN的转发。

举例:设置某Trunk端口的native vlan为100。

DCRS-7604 (Config)#interface ethernet 1/5

DCRS-7604 (Config-ethernet1/5)#switchport mode trunk

DCRS-7604 (Config-ethernet1/5)#switchport trunk native vlan 100

DCRS-7604 (Config-ethernet1/5)#exit

vlan ingress disable

命令:vlan ingress disable

no vlan ingress disable

功能:关闭端口的VLAN入口规则;本命令的no操作为打开入口准则。

命令模式:接口配置模式

缺省情况:系统缺省打开端口的VLAN入口准则。

使用指南:当打开端口的VLAN入口规则,系统在接收数据时会检查源端口是否是该VLAN 的成员端口,如果是则接受数据并转发到目的端口,否则丢弃该数据。

举例:关闭端口的VLAN入口规则。

DCRS-7604 (Config-Ethernet1/1)# vlan ingress disable

本文来源:https://www.bwwdw.com/article/w8rl.html

Top