【IT168 专稿】作为网络管理员,我们在工作中会遇到各种各样的网络设备,交换机是其中最常见的一种。对于交换机来说,最实用的操作就是划分VLAN,利用VLAN技术,可以在一根传输介质上同时传送多个网络的同时又保证各个网络的相互隔离,从而使很多看似不可能完成的任务最后也能够完成了。熟练运用VLAN技术,是一个网管员必备素质。
本篇文章我们要介绍如何通过图形化界面对交换机进行VLAN配置,拥有图形化的配置界面,是很多厂商在介绍产品时会着重强调的一个优点。
但在实际工作中我们发现,如果一名网络工程师没有通过CLI(命令行界面)模式成功的配置过VLAN的话,即使使用图形化界面,也无法顺利的完成VLAN的配置,在网络工程师的生涯中,没有什么捷径可走。下面我们会分两部分,从使用命令行的配置VLAN入手,将相关的概念逐一介绍清楚。
通过命令行方式在交换机上配置VLAN
为了让这个例子更有权威性,我们摘取了CISCO网站上的一篇介绍VLAN配置文章(小提示:CISCO公司的网站技术资料极为丰富,可以系统而全面的学习到交换机配置的各个方面的知识,而且是免费的,大家在遇到交换机配置方面的问题的时侯,不妨多访问一下CISCO的网站,一定会有收获的),本例中所用到的例子网址如下:http://www.cisco.com/en/US/tech/tk389/tk815/technologies_configuration_example09186a008015f17a.shtml。
这是一个典型的上网用的配置。
(一)CISCO3550交换机的配置
CISCO3550交换机上联一台路由器(拥有互联网出口),下面连接一台CISCO29450交换机,在CISCO3550上还对各个VLAN作了定义,CISCO3550交换机的配置如下所示:
Catalyst 3550 (Catalyst 3550-48 Switch)
Cat3550#show running-config
Building configuration...
Current configuration : 3092 bytes
!
version 12.1
no service single-slot-reload-enable
no service pad
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname Cat3550
ip subnet-zero
!--- Enable IP routing for interVLAN routing.(这一步非常重要,通过ip routing命令了实现了各个VLAN间的路由,这样各个VLAN间是可以互访的,但是由于每个VLAN都是一个独立的广播域,所以即使在一个VLAN中发生诸如ARP地址欺骗之类的病毒,也不会影响其它的VLAN)
ip routing
!
spanning-tree extend system-id
!
interface FastEthernet0/1
no ip address
!
!--- Output suppressed.
!
interface FastEthernet0/5
description to SERVER_1
!--- Configure the server port to be in the server VLAN, VLAN 3.
switchport access vlan 3
!--- Configure the port to be an access port to prevent trunk negotiation delays.
switchport mode access
no ip address
!--- Configure PortFast for initial Spanning Tree Protocol (STP) delay. Refer to
!--- Using PortFast and Other Commands to Fix Workstation Startup Connectivity Delays
!--- for more information. (这里又介绍了一个非常重要的概念,即如果确认交换机下某个端口连接的是一台重要的服务器,那就可以将该端口设置为“spanning-tree portfast”状态,从而实现服务器与交换机端口的快速连接)
spanning-tree portfast
!
!--- Output suppressed.
!
interface FastEthernet0/48
description To Internet_Router
!--- The port that connects to the router converts into a routed (L3) port.(fa0/48是上连到一台路由器)
no switchport
!--- Configure the IP address on this port. (为了实现与路由器的通讯,在端口上设置了IP地址)
ip address 200.1.1.1 255.255.255.252
!
interface GigabitEthernet0/1
description To 2950
!--- Configure IEEE 802.1 (dot1q) trunking, with negotiation, on the L2 switch.
!--- If there is not support for Dynamic Trunking Protocol (DTP) on the far switch,
!--- issue the switchport mode trunk command to force the switch port to trunk mode.
!--- Note: The default trunking mode is dynamic auto. If you establish a trunk link
!--- with the default trunking mode, the trunk does not appear
!--- in the configuration, even though a trunk has been established on
!--- the interface. Use the show interfaces trunk command to verify the
!--- establishment of the trunk.
(G0/1下连到一台CISCO2950的交换机,其实CISCO3550交换机是支持自动设置为TRUNK模式的,即如果下连的网络端口被设置为TRUNK模式的话,3550上的对应端口就会自动的变成TRUNK模式,但是本例中为了详细说明TRUNK的设置,还是把端口封装802.1Q的命令写了出来)
switchport trunk encapsulation dot1q
no ip address
!
interface Vlan1
no ip address
shutdown
!
interface Vlan2
description USER_VLAN
!--- This IP address is the default gateway for users. (VLAN2是接入用户的VLAN,VLAN上设置的IP地址就作为下接用户的网关,这也是一个非常重要的概念)
ip address 10.1.2.1 255.255.255.0
!
interface Vlan3
description SERVER_VLAN
!--- This IP address is the default gateway for servers. (VLAN3是连接服务器的)
ip address 10.1.3.1 255.255.255.0
!
interface Vlan10
description MANAGEMENT_VLAN
!--- This IP address is the default gateway for other L2 switches. (VLAN10是管理VLAN,下面所连接交换机会以VLAN10的IP作为自己的网关,为管理专门划分一个VLAN,将管理VLAN与业务VLAN区别开了这也是非常重要的一个概念)。
ip address 10.1.10.1 255.255.255.0
!
ip classless
!--- This route statement allows the 3550 to send Internet traffic to
!--- the default router which, in this case, is the 7200VXR (Fe 0/0 interface). (因为是上连到一台路由器,所以在这台交换机上设置了默认路由)
ip route 0.0.0.0 0.0.0.0 200.1.1.2
ip http server
!
line con 0
line vty 5 15
!
end
(二)CISCO2950交换机的配置
Catalyst 2950 (Catalyst 2950G-48 Switch)
Cat2950#show running-config
Building configuration...
Current configuration : 2883 bytes
!
version 12.1
no service single-slot-reload-enable
no service pad
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname Cat2950
!
ip subnet-zero
!
spanning-tree extend system-id
!
interface FastEthernet0/1
no ip address
!
!--- Output suppressed.
interface FastEthernet0/16
no ip address
!
interface FastEthernet0/17
description SERVER_2
switchport access vlan 3
switchport mode access
no ip address
spanning-tree portfast
! fa0/17是连接服务器_2的端口,属于VLAN3,而且设置为“spanning-tree portfast”模式
!--- Output suppressed.
!
interface FastEthernet0/33
description HOST_1
!--- Configure HOST_1 to be the user VLAN, VLAN 2. fa0/33端口接入了用户主机_1所以设置为VLAN2
switchport access vlan 2
switchport mode access
no ip address
spanning-tree portfast
!
!--- Output suppressed.
interface GigabitEthernet0/1
switchport trunk encapsulation dot1q
no ip address
! 因为端口g0/1是上连到CISCO3550交换机的,所以设置为TRUNK模式
interface GigabitEthernet0/2
no ip address
!
interface Vlan1
no ip address
no ip route-cache
shutdown
!
interface Vlan10
description MANAGEMENT
!--- This IP address manages this switch. (VLAN10是管理VLAN)
ip address 10.1.10.2 255.255.255.0
no ip route-cache
!
!--- Configure the default gateway so that the switch is reachable from other
!--- VLANs/subnets. The gateway points to the VLAN 10 interface on the 3550.
ip default-gateway 10.1.10.1
ip http server
!
line con 0
line vty 5 15
!
End
(三)总结VLAN配置的三大步骤
看过了文档,我们再来总结一下VLAN配置的三个步骤:
1、新建一个VLAN
2、将端口划归相应的VLAN
3、将级联口设置为TRUNK模式