且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VLAN间路由和VTP协议

更新时间:2022-10-04 12:45:41

     这些天都忙于公司的招聘,太忙了。可能还要忙上一阵子,自上个月22号才写了一篇。今天下雨没有到外面去。写了一篇贴出来:

一、拓扑图:
 
VLAN间路由和VTP协议
 
 
二、详细配置及说明:
1
、首先配置各PCIP,并指定默认网关:
VLAN间路由和VTP协议
VLAN间路由和VTP协议
VLAN间路由和VTP协议
 
2、由于它默认就封装了dot1q packet tracer不支持switchport trunk encapsulation dot1q 此命令:
 
SW1(config)#int f0/1
SW1(config-if)#switchport trunk encapsulation dot1q
                                ^
% Invalid input detected at '^' marker. (发现此IOS不支持此命令)
 
SW1(config-if)#end
SW1#sh int f0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: dynamic auto
Operational Mode: static access
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: native
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Voice VLAN: none
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk encapsulation: dot1q (发现默认就封装成dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk private VLANs: none
Operational private-vlan: none
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL
Protected: false
Appliance trust: none
SW1#
 
3、为了保证管理域能够覆盖到两台交换机,我们配置SW1SW2trunk
SW1(config)#int f0/1
SW1(config-if)#switchport mode trunk (在SW1上指定端口为trunk模式)
 
SW2(config)#int f0/2
SW2(config-if)#switchport mode trunk (在SW2上指定端口为trunk模式)
 
4、在R2上查看一下trunk信息:
SW2(config-if)#do sh int trunk
Port        Mode         Encapsulation  Status       Native vlan
Fa0/2       on           802.1q         trunking     1   (缺省VLAN被称为Native Vlan
 
Port        Vlans allowed on trunk
Fa0/2       1-1005  (允许在trunk上传输数据的VLAN列表)
 
Port        Vlans allowed and active in management domain
Fa0/2       1
 
Port        Vlans in spanning tree forwarding state and not pruned
Fa0/2       1
 
5、在配置VTP之前,先查看一下交换机的VTP状态,以观察配置之后的变化:
SW2#sh vtp status
VTP Version                     2  VTP协议的版本号为2,增加了支持令牌环交换和令牌环VLAN
Configuration Revision           (配置的版本号,每变更一次将会增加1,为0说明没有配置)
Maximum VLANs supported locally : 255
Number of existing VLANs        : 5
VTP Operating Mode              Server (默认情况下所有交换机都为VTP server 模式)
VTP Domain Name                 :
VTP Pruning Mode                Disabled (VTP修剪默认关闭的)
VTP V2 Mode                     : Disabled
VTP Traps Generation            : Disabled
MD5 digest                      0x7D 0x5A 0xA6 0x0E 0x9A 0x72 0xA0 0x3A (VTP的密码)
Configuration last modified by 0.0.0.0 at 0-0-00 00:00:00
Local updater ID is 0.0.0.0 (no valid interface found)
 
6、分别在VLAN模式下配置SW1和在全局模式下配置SW2VTP协议:
SW1#vlan database
SW1(vlan)#vtp domain wxs (配置VTP的域名为 wxs 
SW1(vlan)#vtp server  (定义VTP的模式为client)
SW1(vlan)#vtp password cisco (为了vtp的安全,配置VTP的密码为cisco)
 
SW2(config)#vtp domain wxs
SW2(config)#vtp mode client
SW2(config)#vtp password cisco
 
7、现在我们再看一下SW2VTP状态信息:
SW2#sh vtp status
VTP Version                     : 2
Configuration Revision          0 (因为没有对VLAN进行操作,故还为0)
Maximum VLANs supported locally : 255
Number of existing VLANs        : 5
VTP Operating Mode              Client (VTP的操作模式从默认的server变成client)
VTP Domain Name                 wxs (VTP域名为wxs)
VTP Pruning Mode                : Disabled
VTP V2 Mode                     : Disabled
VTP Traps Generation            : Disabled
MD5 digest                      : 0x37 0x56 0xD3 0xEA 0x66 0xC8 0xA3 0x39
Configuration last modified by 0.0.0.0 at 0-0-00 00:00:00
 
8、在SW1SW2上创建VLAN
SW1(config)#vlan 10 (在全局配置模式下创建VLAN 10
SW1(config-vlan)#name cisco (命名为cisco
SW1(config-vlan)#end
SW1#vlan database(同理在服务器模式交换机SW1上进入vlan database模式下)
SW1(vlan)#vlan 20 name microsoft (在vlan database模式下建立vlan 20并命名为microsoft)
 
9、查看一下SW1VLAN配置信息:
SW1#sh vlan
 
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/2, Fa0/3, Fa0/4, Fa0/6
                                                Fa0/7, Fa0/8, Fa0/9, Fa0/10
                                                Fa0/11, Fa0/12, Fa0/13, Fa0/14
                                                Fa0/15, Fa0/16, Fa0/17, Fa0/18
                                                Fa0/19, Fa0/20, Fa0/21, Fa0/22
                                                Fa0/23, Fa0/24, Gig1/1, Gig1/2
10   cisco                            active   
20   microsoft                        active  
1002 fddi-default                     act/unsup
1003 token-ring-default               act/unsup
1004 fddinet-default                  act/unsup
1005 trnet-default                    act/unsup
………………
SW1#
 
10、查看SW2VLAN配置信息,发现同步了VTP server角色SW1VLAN配置信息:
SW2#sh vlan
 
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/1, Fa0/3, Fa0/4, Fa0/5
                                                Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                Fa0/10, Fa0/11, Fa0/12, Fa0/13
                                                Fa0/14, Fa0/15, Fa0/16, Fa0/17
                                                Fa0/18, Fa0/19, Fa0/20, Fa0/21
                                                Fa0/22, Fa0/23, Fa0/24, Gig1/1
                                                Gig1/2
10   cisco                            active   
20   microsoft                        active   
1002 fddi-default                     act/unsup
1003 token-ring-default               act/unsup
1004 fddinet-default                  act/unsup
1005 trnet-default                    act/unsup
………………
SW2#
 
11、在SW1SW2上将相应的交换机端口加入到对应的VLAN当中:
SW1(config)#int f0/11
SW1(config-if)#switchport access vlan 10 (f0/11交换机端口加入到VLAN 10 当中)
SW1(config-if)#int f0/12
SW1(config-if)#sw ac vlan 20
 
SW2(config)#int f0/11
SW2(config-if)#sw ac vlan 20
 
12、在三台PC上用ping 命令测试VLAN间的通信:
VLAN间路由和VTP协议
VLAN间路由和VTP协议
VLAN间路由和VTP协议
 
三、在R1路由器上配置单臂路由,确保两个VLAN之间能够通信。
1、为了R1SW1仅通过一条链路就能连接多个VLAN,我们要在R1SW1trunk链路:
SW1(config)#int f0/5
SW1(config-if)#switchport mode trunk (因为此IOS默认就封装了dot1q,我们指定接口trunk模式)
 
R1(config)#int f0/0
R1(config-if)#no sh (激活此接口)
R1(config-if)#no ip address (但不要配置IP
R1(config-if)#int f0/0.10
R1(config-subif)#encapsulation dot1Q 10 (封装dot1q类型并指定VLAN,作用是出去的数据包打上10VLAN标记,同时只接收VLAN 10 的数据包)
R1(config-subif)#ip add 192.168.1.1 255.255.255.0 (为子接口配置IP用于VLAN 10的默认网关)
 
R1(config-subif)#int f0/0.20 (进入f0/0.20的子接口)
R1(config-subif)#en dot1Q 20(发出的数据包会打上20VLAN标记,同时只接收VLAN 20 的数据包)
R1(config-subif)#ip add 192.168.2.1 255.255.255.0(为子接口配置IP用于VLAN 20的默认网关)
 
2、查看R1的路由表:
R1(config-subif)#do sh ip 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
 
四、验证一下连通性:
VLAN间路由和VTP协议
VLAN间路由和VTP协议
VLAN间路由和VTP协议
 
 
 本文转自wxs-163 51CTO博客,原文链接:http://blog.51cto.com/supercisco/279354