思科基础知识:虚拟局域网(VLAN)(5)

网络
在一个纯交换式的互联网络中,通过创建虚拟局域网(VLAN)就可以分隔广播域。

配置VTP

所有的交换机,在默认时都配置为VTP服务器。要配置VTP,首先必须配置你想要使用的VTP域名。在创建VTP域时,有一些选项,包括设置域名、口令、操作模式和交换机的修建功能。可使用VTP全局配置模式命令来设置所有这些信息。在下面的列兹中,我将交换机设置为VTP server,将VTP域名设置为Cisco,将VTP口令设置为12345:

  1. 1900(config)#vtp server  
  2.  
  3. 1900(config)#vtp domain Cisco  
  4.  
  5. 1900(config)#vtp password 12345 

默认时所有的交换机都设置为VTP服务器模式,如果想在交换机上改动任何有关VLAN的信息,都必须在VTP服务器模式下进行。

在2950交换机上配置VTP,同样要首先配置想要使用的域名。同样,一旦在交换机上配置了VTP信息,就需要验证它。可使用VTP全局配置模式命令来设置这些信息。例子中,把交换机设置为服务器模式,域名设置为SZ_Lab

  1. Switch(config)#vtp mode server  
  2.  
  3. Switch(config)#vtp domain SZ_Lab 

配置示例互联网络中的交换

先配置2950C,如下:

  1. 2950C(config)#enable secret noko  
  2.  
  3. 2950C(config)#line con 0  
  4.  
  5. 2950C(config-line)#login  
  6.  
  7. 2950C(config-line)#password noco  
  8.  
  9. 2950C(config-line)#line vty 0 15  
  10.  
  11. 2950C(config-line)#login  
  12.  
  13. 2950C(config-line)#password noco  
  14.  
  15. 2950C(config-line)#banner motd #  
  16.  
  17. 2950C  
  18.  
  19. #  
  20.  
  21. 2950C(config-line)#exit  
  22.  
  23. 2950C(config)#int vlan1  
  24.  
  25. 2950C(config-if)#ip address 172.16.10.2 255.255.255.0  
  26.  
  27. 2950C(config-if)#no shut  
  28.  
  29. 2950C(config-if)#exit  
  30.  
  31. 2950C(config)#up default-gateway 172.16.10.1  
  32.  
  33. 2950C(config)#^Z  
  34.  
  35. 2950C#copy run start 

配置2950B,如下:

  1. 2950B(config)#enable secret noko  
  2.  
  3. 2950B(config)#line con 0  
  4.  
  5. 2950B(config-line)#login  
  6.  
  7. 2950B(config-line)#password noco  
  8.  
  9. 2950B(config-line)#line vty 0 15  
  10.  
  11. 2950B(config-line)#login  
  12.  
  13. 2950B(config-line)#password noco  
  14.  
  15. 2950B(config-line)#banner motd #  
  16.  
  17. 2950B  
  18.  
  19. #  
  20.  
  21. 2950B(config-line)#exit  
  22.  
  23. 2950B(config)#int vlan1  
  24.  
  25. 2950B(config-if)#ip address 172.16.10.3 255.255.255.0  
  26.  
  27. 2950B(config-if)#no shut  
  28.  
  29. 2950B(config-if)#exit  
  30.  
  31. 2950B(config)#up default-gateway 172.16.10.1  
  32.  
  33. 2950B(config)#^Z  
  34.  
  35. 2950B#copy run start 

#p#

配置trunk,2950B如下:

  1. 2950B(config)#int f0/1  
  2.  
  3. 2950B(config-if)#switchport mode trunk  
  4.  
  5. 2950B(config-if)#int f0/4  
  6.  
  7. 2950B(config-if)#switchport mode trunk  
  8.  
  9. 2950B(config-if)#int f0/5  
  10.  
  11. 2950B(confgi-if)#switchport mode trunk 

配置trunk,2950C如下:

  1. 2950C(config)#int f0/4  
  2.  
  3. 2950C(confgi-if)#switchport mode trunk  
  4.  
  5. 2950C(config-if)#int f0/5  
  6.  
  7. 2950C(config-if)#switchport mode trunk 

验证trunk信息,使用show interface trunk命令.如下:

  1. 2950B#sh int trunk  
  2.  
  3. Port Mode Encapsulation Status Native vlan  
  4.  
  5. Fa0/1 on 802.1q trunking 1  
  6.  
  7. Fa0/4 on 802.1q trunking 1  
  8.  
  9. Fa0/5 on 802.1q trunking 1  
  10.  
  11. (略) 

之前我们已经对2950B和2950C做了基本配置和trunk端口的配置,接下来应该设置VTP和创建VLAN,并且进行验证.2950C如下:

  1. 2950C(config)#vtp mode server  
  2.  
  3. 2950C(config)#vtp domain Cisco  
  4.  
  5. 2950C(config)#^Z  
  6.  
  7. 2950C#vlan database  
  8.  
  9. 2950C(vlan)#vlan 2 name sales  
  10.  
  11. 2950C(vlan)#vlan 3 name marketing  
  12.  
  13. 2950C(vlan)#apply  
  14.  
  15. 2950C(vlan)#^C  
  16.  
  17. 2950C#sh vlan brief  
  18.  
  19. (略) 

接下来分配端口,把Fa0/2分配给VLAN2,Fa0/3分配给VLAN3,默认所有的端口都处在VLAN1下,配置如下:

  1. 2950C(config)#int fa0/2  
  2.  
  3. 2950C(config-if)#switchport access vlan2  
  4.  
  5. 2950C(config)#int fa0/3  
  6.  
  7. 2950C(config-if)#switchport access vlan3 

验证信息,注意VLAN1里的Ports栏,如下:

  1. 2950C#sh vlan brief  
  2.  
  3. VLAN Name Status Ports  
  4.  
  5. ----------------------------------------------------------------------------  
  6.  
  7. 1 default active Fa0/1 Fa0/5...Fa0/10  
  8.  
  9. 2 sales active Fa0/2  
  10.  
  11. 3 marketing active Fa0/3 

#p#

配置2950B,把它设置成客户模式,2950B从2950C接收VLAN信息,如下:

  1. 2950B(config)#vtp mode client  
  2.  
  3. 2950B(config)#vtp domain Cisco  
  4.  
  5. 2950B(config)#^Z 

验证,注意2950B已经从2950C知道了VLAN的信息,如下:

  1. 2950B#sh vlan brief  
  2.  
  3. VLAN Name Status Ports  
  4.  
  5. ----------------------------------------------------------------------------  
  6.  
  7. 1 default active Fa0/1...Fa0/12  
  8.  
  9. 2 sales active  
  10.  
  11. 3 marketing active 

但是仍然要给2950B分配端口,如下:

  1. 2950B(config)#int fa0/2  
  2.  
  3. 2950B(config-if)#switchport access vlan2  
  4.  
  5. 2950B(config)#int fa0/3  
  6.  
  7. 2950B(config-if)#switchport access vlan3 

验证信息,如下:

  1. VLAN Name Status Ports  
  2.  
  3. ----------------------------------------------------------------------------  
  4.  
  5. 1 default active Fa0/1 Fa0/5...Fa0/12  
  6.  
  7. 2 sales active Fa0/2  
  8.  
  9. 3 marketing active Fa0/3 

到现在,2950C和2950B的配置就算是完成了,经过验证,我们也没发现什么问题,接下来该配置什么呢?当然是配置VLAN间的通信,根据上面的拓扑图,可以知道需要在RouterB上进行配置,如下:

  1. RouterB(config)#hostname Trunkrouter  
  2.  
  3. Trunkrouter(config)#int f0/0  
  4.  
  5. Trunkrouter(config-if)#no ip address  
  6.  
  7. Trunkrouter(config-if)#no shut 

创建子接口,并定义封装类型,如下:

  1. Trunkrouter(config-if)#int f0/0.1  
  2.  
  3. Trunkrouter(config-subif)#encapsulation dot1q 1  
  4.  
  5. Trunkrouter(config-subif)#ip address 172.16.10.1 255.255.255.0  
  6.  
  7. Trunkrouter(config-if)#int f0/0.2  
  8.  
  9. Trunkrouter(config-subif)#encapsulation dot1q 2  
  10.  
  11. Trunkrouter(config-subif)#ip address 172.16.20.1 255.255.255.0  
  12.  
  13. Trunkrouter(config-if)#int f0/0.3  
  14.  
  15. Trunkrouter(config-subif)#encapsulation dot1q 3  
  16.  
  17. Trunkrouter(config-subif)#ip address 172.16.30.1 255.255.255.0  
  18.  
  19. Trunkrouter(config-if)#exit 

创建子接口,每个接口对应1个VLAN.注意,如果你试图在***个子接口分配IP地址,将收到错误信息,除非你先定义了封装类型,如下:

  1. Trunkrouter(config-if)#int f0/0.1  
  2.  
  3. Trunkrouter(config-subif)#ip address 172.16.10.1 255.255.255.0  
  4.  
  5. Configuring IP routing on a LAN subinterface is only allowed if that subinterface is already configured as part of an IEEE 802.10, IEEE 802.1Q, or ISL VLAN. 

【编辑推荐】

  1. 思科基础知识:虚拟局域网(VLAN)(1)
  2. 思科基础知识:虚拟局域网(VLAN)(2)
  3. 思科基础知识:虚拟局域网(VLAN)(3)
  4. 思科基础知识:虚拟局域网(VLAN)(4)
责任编辑:佚名 来源: 51CTO整理
相关推荐

2011-06-01 13:18:34

VLAN交换机

2011-06-01 13:18:17

VLANtrunk路由

2011-06-01 13:18:30

VLAN交换交换机

2011-06-01 13:18:26

VLAN

2010-04-16 10:57:43

无线局域网

2011-06-02 09:36:10

广域网协议ISDN

2009-11-26 11:00:51

局域网接口路由器

2011-05-31 10:14:28

协议IP网络地址

2011-06-01 09:26:55

路由路由器IGRP

2010-01-18 17:02:06

2009-12-28 15:56:42

VLAN协议

2011-05-31 13:52:22

口令CiscoIOS

2011-09-19 16:06:55

路由器局域网分段

2011-06-02 09:36:07

广域网协议虚电路帧中继

2011-06-02 09:35:58

WAN交换广域网

2011-06-02 09:36:03

帧中继广域网协议

2011-06-02 09:24:29

广域网协议DDR路由

2011-06-02 09:36:01

PPP数据链路广域网协议

2010-06-09 10:38:05

局域网协议

2010-08-23 17:18:54

DHCP协议
点赞
收藏

51CTO技术栈公众号