交换机上配置VLAN

>enable         (en)
#config t <script language="JavaScript1.1" src="http://ad.ccw.com.cn/adshow.asp?positionID=29&js=1&innerJs=1" type="text/javascript"></script>
Enter configuration commands,one per line.End with CNTL/Z
(config)#
为了安全和方便起见,我们给这个交换机起个名字,并且设置登陆密码。
(config)#hostname 1900Switch
1900Switch(config)# enable password level 15 goodwork
1900Switch(config)#
注意:密码必须是4-8位的字符。交换机密码的设置和路由器稍微不同,交换机用 level 级别的大小来决定密码的权限。Level 1 是进入命令行界面的密码,也就是说,设置了 level 1 的密码后,你下次连上交换机,并输入 K 后,就会让你输入密码,这个密码就是 level 1 设置的密码。而 level 15 是你输入了enable命令后让你输入的特权模式密码。路由器里面是使用 enable password 和 enable screet做此区分的。
好拉,我们已经设置好了名字和密码这样就足够安全了,让我们设置VLAN。VLAN的设置分以下2步:
1. 设置VLAN名称
2. 应用到端口
我们先设置VLAN的名称。使用 vlan vlan号 name vlan名称。 在特权配置模式下进行配置:
1900Switch (config)#vlan 2 name accounting
1900Switch (config)#vlan 3 name marketing
我们新配置了2个VLAN,为什么VLAN号从2开始呢?这是因为默认情况下,所有的端口否放在VLAN 1上,所以要从2开始配置。1900系列的交换机最多可以配置1024个VLAN,但是,只能有64个同时工作,当然了,这是理论上的,我们应该根据自己网络的实际需要来规划VLAN的号码。配置好了VLAN名称后我们要进入每一个端口来设置VLAN。在交换机中,要进入某个端口比如说第4个端口,要用 interface Ethernet 0/4,好的,结合上面给出的图我们让端口2、3、4和5属于VLAN2 ,端口17---22属于VLAN3 。命令是 vlan-membership static/ dynamic VLAN号 。 静态的或者动态的两者必须选择一个,后面是刚才配置的VLAN号。好的,我们看结果:
1900Switch(config)#interface ethernet 0/2        (进入第二个端口)有的int fa0/2也可以进入2端口
1900Switch(config-if)#vlan-membership static 2 (把该端口划归Vlan2)switchport access vlan XLS
1900Switch(config-if)#int e0/3
1900Switch(config-if)#vlan-membership static 2 
1900Switch(config-if)#int e0/4
1900Switch(config-if)#vlan-membership static 2
1900Switch(config-if)#int e0/5
1900Switch(config-if)#vlan-membership static 2
1900Switch(config-if)#int e0/17
1900Switch(config-if)#vlan-membership static 3
。。。。。。
1900Switch(config-if)#int e0/22
1900Switch(config-if)#vlan-membership static 3
1900Switch(config-if)#    

(设好后是两台交换机的话进入互联的端口比如24口连int fa0/24 switchport mode trunk)把fa0/24的模式设置为trunk

要实验跨交换机之间的VLAN通信,就必须先定义管道(trunk)。

管道(trunk)是交换机之间传递信息的一种链路。被划为Trunk的端口,从属于交换机上的每一个Vlan。


好的,我们已经把VLAN都定义到了交换机的端口上了。这儿,我们只是配置的静态的,关于动态的,我们在后面会有提及的。到现在为止,我们已经把交换机的VLAN配置好了,怎么样,没有你想象的那么复杂吧:)。为了验证我们的配置,我们在特权模式使用 show vlan命令。输出如下:
1900Switch(config)#show vlan
VLAN Name Status Ports
1 default Enabled 1,6-16,22-24,AUI,A,B
2 acconting Enabled 2-5
3 marketing Enabled 17-22
1002 fdd <script language="JavaScript1.1" src="http://ad.ccw.com.cn/adshow.asp?positionID=29&js=1&innerJs=1" type="text/javascript"></script>i-default Suspended
1003 token-ring-defau Suspended
1004 fddinet-default Suspended
1005 trnet-default Suspended
这是一个24口的交换机,并且带有AUI和两个100兆端口(A、B),可以看出来,我们的设置已经正常工作了,什么,还要不要保存running configure?当然不用了,交换机是即时自动保存的,所以不用我们使用命令来保存设置了。当然了,你也可以使用 show vlan vlan号 的命令来查看某个VLAN,比如show vlan 2 , show vlan 3. 还可以使用show vlan-membership ,改命令主要是显示交换机上的每一个端口静态或动态的属于哪个VLAN。
以上是给交换机配置静态VLAN的过程,下面我们看看动态的VLAN。动态的V L A N 形成很简单,由端口自己决定它属于哪个V L A N 时,就形成了动态的V L A N 。不过,这并不意味着就一层不变了,它只是一个简单的映射,这个映射取决于网络管理员创建的数据库。分配给动态V L A N 的端口被激活后,交换机就缓存初始帧的源M A C 地址,随后,交换机便向一个称为VMPS (V L A N 管理策略服务器)的外部服务器发出请求,V M P S 中包含一个文本文件,文件中存有进行V L A N 映射的M A C 地址。交换机对这个文件进行下载,然后对文件中的M A C 地址进行校验。如果在文件列表中找到M A C 地址,交换机就将端口分配给列表中的V L A N 。如果列表中没有M A C 地址,交换机就将端口分配给默认的V L A N (假设已经定义默认了V L A N )。如果在列表中没有M A C 地址,而且也没有定义默认的V L A N ,端口不会被激活。这是维护网络安全一种非常好的的方法。从表面上看,动态V L A N 的优势很大,但它也有致命的缺点,即创建数据库是一项非常艰苦而且非常繁琐的工作。如果网络上有数千个工作站,则有大量的输入工作要做。即使有人能胜任这项工作,也还会出现与动态的V L A N 有关的很多问题。另外,保持数据库为最新也是要随时进行的非常费时的工作。所以不经常用到它,这里我们就不做详细的讲解,可以参考相关的CISCO的文档资料。
这么样,没有你想象的那么复杂吧。我们已经把VLAN配置好了,那么VLAN的另一部分不容忽视的工作,就是前期的对网络的规划。就是说,哪些机器在一个VLAN中,各自的IP地址、子网掩码如何分配,以及VLAN之间互相通讯的问题。只有规划计划好了,才能够在配置和以后的使用维护过程中轻松省事。

一、交换机的配置:
>en
#conf t
(config)#hostname S1
S1(config)#ip add 172.16.1.1 255.255.255.0
S1(config)#ip default-gateway 172.16.1.254
S1(config)#vlan 2 name vlan2
S1(config)#int e0/3
S1(config-if)#vlan-membership static 2
S1(config-if)#exit
S1(config)#int e0/4
S1(config-if)#vlan-membership static 2
S1(config-if)#exit
S1(config-if)#^z
----------------------------------------------------------------------------------------------------------------
  1.在基于IOS的交换机上设置主机名/系统名:
  switch(config)# hostname hostname
  在基于CLI的交换机上设置主机名/系统名:
  switch(enable) set system name name-string
  2.在基于IOS的交换机上设置登录口令:
  switch(config)# enable password level 1 password
  
  在基于CLI的交换机上设置登录口令:
  switch(enable) set password
  switch(enable) set enalbepass
  3.在基于IOS的交换机上设置远程访问:
  switch(config)# interface vlan 1
  switch(config-if)# ip address ip-address netmask
  switch(config-if)# ip default-gateway ip-address
  在基于CLI的交换机上设置远程访问:
  switch(enable) set interface sc0 ip-address netmask broadcast-address
  switch(enable) set interface sc0 vlan
  switch(enable) set ip route default gateway
  4.在基于IOS的交换机上启用和浏览CDP信息:
  switch(config-if)# cdp enable
  switch(config-if)# no cdp enable
  为了查看Cisco邻接设备的CDP通告信息:
  switch# show cdp interface [type modle/port]
  switch# show cdp neighbors [type module/port] [detail]
  在基于CLI的交换机上启用和浏览CDP信息:
  switch(enable) set cdp module/port
  为了查看Cisco邻接设备的CDP通告信息:
  switch(enable) show cdp neighbors[module/port] [vlan|duplex|capabilities|detail]
  5.基于IOS的交换机的端口描述:
  switch(config-if)# description description-string
  基于CLI的交换机的端口描述:
  switch(enable)set port name module/number description-string
  6.在基于IOS的交换机上设置端口速度:
  switch(config-if)# speed
  在基于CLI的交换机上设置端口速度:
  switch(enable) set port speed moudle/number
  switch(enable) set port speed moudle/number
  7.在基于IOS的交换机上设置以太网的链路模式:
  switch(config-if)# duplex
  在基于CLI的交换机上设置以太网的链路模式:
  switch(enable) set port duplex module/number
  8.在基于IOS的交换机上配置静态VLAN:
  switch# vlan database
  switch(vlan)# vlan vlan-num name vla
  switch(vlan)# exit
  switch# configure teriminal
  switch(config)# interface interface module/number
  switch(config-if)# switchport mode access
  switch(config-if)# switchport access vlan vlan-num
  switch(config-if)# end
  在基于CLI的交换机上配置静态VLAN:
  switch(enable) set vlan vlan-num [name name]
  switch(enable) set vlan vlan-num mod-num/port-list
  9. 在基于IOS的交换机上配置VLAN中继线:
  switch(config)# interface interface mod/port
  switch(config-if)# switchport mode trunk
  switch(config-if)# switchport trunk encapsulation
  switch(config-if)# switchport trunk allowed vlan remove vlan-list
  switch(config-if)# switchport trunk allowed vlan add vlan-list
  在基于CLI的交换机上配置VLAN中继线:
  switch(enable) set trunk module/port [on|off|desirable|auto|nonegotiate]
  Vlan-range [isl|dotlq|dotl0|lane|negotiate]
  10.在基于IOS的交换机上配置VTP管理域:
  switch# vlan database
  switch(vlan)# vtp domain domain-name
  在基于CLI的交换机上配置VTP管理域:
  switch(enable) set vtp [domain domain-name]
  
  11.在基于IOS的交换机上配置VTP 模式:
  switch# vlan database
  switch(vlan)# vtp domain domain-name
  switch(vlan)# vtp
  switch(vlan)# vtp password password
  在基于CLI的交换机上配置VTP 模式:
  switch(enable) set vtp [domain domain-name] [mode{ sever|cilent|transparent }][password password]
  12. 在基于IOS的交换机上配置VTP版本:
  switch# vlan database
  switch(vlan)# vtp v2-mode
  在基于CLI的交换机上配置VTP版本:
  switch(enable) set vtp v2 enable
  13. 在基于IOS的交换机上启动VTP剪裁:
  switch# vlan database
  switch(vlan)# vtp pruning
  在基于CL I 的交换机上启动VTP剪裁:
  switch(enable) set vtp pruning enable
  14.在基于IOS的交换机上配置以太信道:
  switch(config-if)# port group group-number [distribution ]
  在基于CLI的交换机上配置以太信道:
  switch(enable) set port channel moudle/port-range mode
  15.在基于IOS的交换机上调整根路径成本:
  switch(config-if)# spanning-tree [vlan vlan-list] cost cost
  在基于CLI的交换机上调整根路径成本:
  switch(enable) set spantree portcost moudle/port cost
  switch(enable) set spantree portvlancost moudle/port [cost cost][vlan-list]
  16.在基于IOS的交换机上调整端口ID:
  switch(config-if)# spanning-tree[vlan vlan-list]port-priority port-priority
  在基于CLI的交换机上调整端口ID:
  switch(enable) set spantree portpri priority
  
  switch(enable) set spantree portvlanpri priority [vlans]
  17. 在基于IOS的交换机上修改STP时钟:
  switch(config)# spanning-tree [vlan vlan-list] hello-time seconds
  switch(config)# spanning-tree [vlan vlan-list] forward-time seconds
  ` switch(config)# spanning-tree [vlan vlan-list] max-age seconds
  在基于CLI的交换机上修改STP时钟:
  switch(enable) set spantree hello interval[vlan]
  switch(enable) set spantree fwddelay delay [vlan]
  switch(enable) set spantree maxage agingtiame[vlan]
  18. 在基于IOS的交换机端口上启用或禁用Port Fast特征:
  switch(config-if)#spanning-tree portfast
  在基于CLI的交换机端口上启用或禁用Port Fast 特征:
  switch(enable) set spantree portfast
  19. 在基于IOS的交换机端口上启用或禁用UplinkFast 特征:
  switch(config)# spanning-tree uplinkfast [max-update-rate pkts-per-second]
  在基于CLI的交换机端口上启用或禁用UplinkFast 特征:
  switch(enable) set spantree uplinkfast [rate update-rate] [all-protocols off|on]
--------------------------------------------------------------------------------------------------------------
sw1924_b#reload----------------重新启动交换机(初始提示符为> )
sw1924_b<config>#enable password level 1 cisco1-----------设置等级密码(1最低)
sw1924_b<config>#enable password level 15 cisco15----------设置等级密码(15最高)
sw1924_b<config>#ip address 192.168.14.1 255.255.255.0-----设置交换机的管理IP地址
sw1924_b<config>#ip default-gateway 192.168.198.2----------设置交换机的网关地址
sw1924_b<config>#ip domain-name pctc.com.cn----------------设置交换机所连域的域名
sw1924_b<config>#ip name-server 218.87.18.230--------------设置交换机所连域的域名服务器IP
sw1924_b#show ip-------------------------------------------查看上述设置环境
sw1924_b#show version--------------------------------------查看交换机的版本等信息
sw1924_b#show running-config-------------------------------查看交换机的当前运行配置等全部信息
sw1924_b#show int e0/1-------------------------------------查看交换机的第1个端口信息


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值