一、vlan简介
默认时交换机分割冲突域,路由器分割广播域,vlan可以分割广播域,而且vlan可以对硬件地址、协议、和应用程序实施限制,这样可以保证安全性,vlan还具有灵活性和可扩张性
通常有管理员建立的valn并将端口放入每个vlan,这样的vlan成为静态vlan
将主机硬件地址放入数据库,主机接入交换机时,交换机自动为其分配vlan,成为动态vlan
vlan识别:
         交换机间链路(inter-switch link,ISL),在以太网帧上标记vlan信息,isl外部封装方法允许这是cisco交换机专用的方法
         IEEE802.1Q,在帧中插入一个字段以标示vlan
2960系列只支持ieee802.1Q中继协议,3560系列能支持ISL和IEEE802.1Q
vlan中继协议VTP,子vtp域中有三种操作模式:服务器(默认模式,vtp域中至少要有一台服务器,可以之心创建添加删除等操作,在vtp服务器模式下,vlan配置保存在NVRAM中)、客户机(从服务器接收信息,转发汇总通告不做更改)、透明
vtp修剪:用来保存带宽的一种方法;默认时vlan2--1001是可以启用修剪的,扩展vlan1006--4096不能被修剪但vlan1从来不启用修剪,vtp1和2 版本都支持vtp修剪
使用show   interface  trunk  命令可以看到穿越中继链路的vlan
使用switchport  trunk  pruning  vlan 3-4  为3-4vlan启用vtp修剪
二、VLAN间的路由
实例演示如图所示规划:pc0 、pc3属于vlan10,pc2、pc1属于vlan20,ip地址如图所示分配,route4ip为1.1.1.2/16
1、首先规划ip地址
2、在switch0 上Switch>en
                              Switch#config terminal
                              Switch(config)#vlan 10
                              Switch(config)#vlan 20
      创建vlan,在switch1上执行相同命令;可以用Switch#show vlan命令查看建立的valn
3、将端口分配到vlan
进入switch0
      Switch#config ter
       Enter configuration commands, one per line.  End with CNTL/Z.
      Switch(config)#inter fa0/2
      Switch(config-if)#switchport mode access   
      Switch(config-if)#switchport access valn 10
      Switch(config)#inter fa0/5
      Switch(config-if)#switchport mode access
      Switch(config-if)#switchport access valn 20
在switch1上执行相同命令将fastEthernet 0/2加入vlan20,将fastEthernet 0/5加入vlan10
使用interface  range  可以同时设置许多端口,dynamic和trunk分别用于中继端口
4、配置中继端口
       Switch(config)#inter fa0/3
       switchport  mode   trunk
       Switch(config)#inter fa0/4
       switchport  mode   trunk
        Switch(config)#inter fa0/1
        switchport  mode   trunk
(cisco3560交换机上有encapsulation命令,而2960则没有
      Switch(config-if)#switchport trunk encapsulation dot1q
      Switch(config-if)#switchport mode trunk)
在中继端口上定义允许的vlan
Switch(config-if)#switchport trunk allowed vlan ?
           WORD    VLAN IDs of the allowed VLANs when this port is in trunking mode
           add     add VLANs to the current list
           all     all VLANs
           except  all VLANs except the following
           none    no VLANs
           remove  remove VLANs from the current list
Switch(config-if)#switchport trunk allowed vlan all其后有其它选项remove可以防止特定vlan穿越中继链路
变更或修改本机vlan
           Switch(config-if)#switchport trunk native vlan 40
使用Switch(config-if)# no   switchport trunk native vlan 可以将本机vlan设置回默认,交换机必须使用相同的本机vlan
配置vlan间路由,在route1的fa0/1上划分子接口
Router>en
Router#config ter.
Router(config)#int fa0/1.1
Router(config-subif)#encapsulation dot1Q ?
  <1-1005>  IEEE 802.1Q VLAN ID
Router(config-subif)#encapsulation dot1Q 10
Router#config ter.
Router(config)#int fa0/1.2
Router(config-subif)#encapsulation dot1Q ?
  <1-1005>  IEEE 802.1Q VLAN ID
Router(config-subif)#encapsulation dot1Q 20
给子接口fa0/1.1配置ip为192.168.0.13/24,fa0/1.2ip为192.168.1.23/24
并把fa0/1设置成trunk口,然后s0/0/0设置ip为1.1.1.1/16,并且需要配置时钟频率clock  rate
5、测试如图所示: