思科VLAN的基本配置命令

思科交换机的基本配置命令学习

CISCO交换机基本配置:Console端口连接
交换机口令设置:
switch>enable ;进入特权模式
switch#config terminal ;进入全局配置模式
switch(config)#hostname csico ;设置交换机的主机名
switch(config)#enable secret csico1 ;设置特权加密口令
switch(config)#enable password csico8 ;设置特权非密口令
switch(config)#line console 0 ;进入控制台口
switch(config-line)#line vty 0 4 ;进入虚拟终端
switch(config-line)#login ;虚拟终端允许登录
switch(config-line)#password csico6 ;设置虚拟终端登录口令csico6
switch#exit ;返回命令

switch(config)#int f0/1 ;进入端口1
switch(config)#speed ? 查看speed命令的子命令
switch(config)#speed 100 设置该端口速率为100mb/s (10/auto)
switch(config)#duplex ? 查看duplex的子命令
switch(config)#duplex full 设置该端口为全双工(auto/half)
switch(config)#description TO_PC1 这是该端口描述为TO_PC1
switch(config-if)#switchport access vlan 2 ;当前端口加入vlan 2
switch(config-if)#switchport mode trunk ;设置为trunk模式(access模式)
switch(config-if)#switchport trunk allowed vlan 1,2 ;设置允许的vlan
switch(config-if)#switchport trunk encap dot1q ;设置vlan 中继
switch(config)#vtp domain vtpserver ;设置vtp域名相同
switch(config)#vtp password ;设置发vtp密码
switch(config)#vtp server ;设置vtp服务器模式
switch(config)#vtp client ;设置vtp客户机模式


交换机设置IP地址,默认网关,域名,域名服务器,配置和查看MAC地址表:
switch(config)#interface vlan 1 ; 进入vlan 1
switch(config-if)#ip address 192.168.1.1 255.255.255.0 ;设置IP地址
switch(config)#ip default-gateway 192.168.1.6 ;设置默认网关
switch(config)#ip domain-name https://www.360docs.net/doc/b73820223.html, 设置域名
switch(config)#ip name-server 192.168.1.18 设置域名服务器
switch(config)#mac-address-table? 查看mac-address-table的子命令
switch(config)#mac-address-table aging-time 100 设置超时时间为100ms
switch(config)#mac-address-table permanent 0000.0c01.bbcc f0/3 加入永久地址在f0/3端口
switch(config)#mac-address-table restricted static 0000.0c02.bbcc f0/6 f0/7 加入静态地址目标端口f0/6源端口f0/7
switch(config)#end
switch#show mac-address-table 查看整个MAC地址表
switch#clear mac-address-table restricted static 清除限制性静态地址

交换机显示命令:
switch#write ;保存配置信息
switch#show vtp ;查看vtp配置信息
switch#show run ;查看当前配置信息
switch#show vlan ;查

看vlan配置信息
switch#show interface ;查看端口信息
switch#show int f0/0 ;查看指定端口信息
switch#show int f0/0 status;查看指定端口状态
switch#dir flash: ;查看闪存

(1)模式转换命令
用户模式----特权模式,使用命令"enable"
特权模式----全局配置模式,使用命令"config t"
全局配置模式----接口模式,使用命令"interface+接口类型+接口号"
全局配置模式----线控模式,使用命令"line+接口类型+接口号"
注:
用户模式:查看初始化的信息.
特权模式:查看所有信息、调试、保存配置信息
全局模式:配置所有信息、针对整个路由器或交换机的所有接口
接口模式:针对某一个接口的配置
线控模式:对路由器进行控制的接口配置
(2)配置命令
show running config 显示所有的配置
show versin 显示版本号和寄存器值
shut down 关闭接口
no shutdown 打开接口
ip add +ip地址 配置IP地址
secondary+IP地址 为接口配置第二个IP地址
show interface+接口类型+接口号 查看接口管理性
show controllers interface 查看接口是否有DCE电缆

【VLAN的基本配置命令】

创建配置vlan

1、从特权模式进入vlan模式,交换机添加VLAN创建,删除,端口属性的设置,配置trunk端口,将某端口加入vlan中,配置VTP:
Switch>
Switch>en
Switch#vlan database ;进入VLAN设置
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode.

switch(vlan)#vlan 2 ; 建VLAN 2
switch(vlan)#vlan 3 name vlan3 ;建VLAN 3并命名为vlan3
switch(vlan)#no vlan 2 ; 删vlan 2
如下实例:

Switch(vlan)#vlan 2 name yv1
VLAN 2 added:
Name: yv1
Switch(vlan)#vlan 3 name yv2
VLAN 3 added:
Name: yv2
Switch(vlan)#vlan 4 name yv3
VLAN 4 added:
Name: yv3
Switch(vlan)#exit 保存退出
APPLY completed.
Exiting....

划端口进VLAN

首先进入用户模式

在用户模式下输入”en“,进入特权模式”Sw#
en
switch#
在特权模式下输入”configure terminal“,进入全局模式”Sw(config)#
switch#configure terminal
switch#(config)#
接下来在全局模式下进入接口模式,输入”int range f0/1-3“,这里注意了使用range参数才可以进入多接口,这里选择f0/1、f0/2、f0/3,三个接口。


具体操作如下:
交换机在VLAN中如何添加一个端口。
Switch#
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int fa0/1
Switch(config-if)#switchport mode access
Switch(config-if)#sw acc vlan 2
S

witch(config-if)#no shutdown
Switch(config-if)#exit

交换机在VLAN中如何一次添加多个端口,
交换机
Switch(config)#int range fa0/2-12
Switch(config-if-range)#sw mode access
Switch(config-if-range)#sw acc vlan 3
Switch(config-if-range)#no shutdown
Switch(config-if-range)#exit

Switch(config)#int range fa 0/13-24
Switch(config-if-range)#sw mode access
Switch(config-if-range)#sw acc vlan 4
Switch(config-if-range)#no shutdown
Switch(config-if-range)#exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console

如何将一个端口划到多个Vlan中
交换机
Switch(config)#interface f0/1
Switch(config-if)#switchport mo access 搜索
Switch(config-if)#switchport access vlan 10
Switch(config-if)#switchport access vlan 20
Switch(config-if)#switchport access vlan 30
路由器
Router(config)#interface f0/0.1
Router(config-subif)#encapsulation dot1Q 1
Router(config-subif)#ip ad 192.168.2.1 255.255.255.0
Router(config-subif)#ex
Router(config)#interface f0/0.2
Router(config-subif)#encapsulation dot1Q 2
Router(config-subif)#ip address 192.168.1.1 255.255.255.0

3、 查看配置的vlan

Switch#
Switch#show vlan

VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active
2 yv1 active Fa0/1
3 yv2 active Fa0/2, Fa0/3, Fa0/4, Fa0/5
Fa0/6, Fa0/7, Fa0/8, Fa0/9
Fa0/10, Fa0/11, Fa0/12
4 yv3 active Fa0/13, Fa0/14, Fa0/15, Fa0/16
Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23, Fa0/24
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup

VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
2 enet 100002 1500 - - - - - 0 0
3 enet 100003 1500 - - - - - 0 0
4 enet 100004 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
1003 tr 101003 1500 - - - - - 0 0
1004 fdnet 101004 1500 - - - ieee - 0 0
1005 trnet 101005 1500 - - - ibm - 0 0

Remote SPAN VLANs
------------------------------------------------------------------------------


Primary Seco

ndary Type Ports
------- --------- ----------------- ------------------------------------------
Switch#





1、 创建vlan方法一
switch#vlan database
switch(vlan)#vlan 10 name vlan2
switch(vlan)#exit

2、 创建vlan方法二
switch(config)#vlan 10
switch(config-vlan)#name vlan2

3、 删除vlan方法一
switch(vlan)#no vlan 10
switch(vlan)#exit

4、 删除vlan方法二
switch(config)#no vlan 10

5、 删除vlan方法三
switch#delete vlan.dat

6、 将端口加入到vlan中
switch(config-if)#switchport access vlan 10

7、 将一组连续的端口加入到vlan中
switch(config)# interface range f0/1 – 5
switch(config-if-range)#switchport access vlan 10

8、 将端口从vlan中删除
switch(config-if)#no switchport access vlan 10
switch(config-if)#switchport access vlan 1
switch(config-if-range)#no switchport access vlan 10
switch(config-if-range)#switchport access vlan 1

9、 查看所有vlan的摘要信息
switch#show vlan brief

10、 查看指定vlan的信息
switch#show vlan id 10

11、 指定端口成为trunk
switch(config-if)#switchport mode trunk

12、 Trunk的自动协商
switch(config-if)#switchport mode dynamic desirable
switch(config-if)#switchport mode dynamic auto
注意:如果中继链路两端都设置成auto将不能成为trunk

13、 查看端口状态
switch#show interface f0/2 switchport
14、 在trunk上移出vlan
switch(config-if)#switchport trunk allowed vlan remove 20
15、 在trunk上添加vlan
switch(config-if)#switchport trunk allowed vlan add 20




【公司内部进行VLAN的划分实例】

对于每个公司而言都有自己不同的需求,下面我们给出一个典型的公司的VLAN的实例,这样也可以成为我们以后为公司划分VLAN的依据。
某公司现在有工程部、销售部、财务部。VLAN的划分:工程部VLAN10,销售部VLAN20,财务部VLAN30,并且各部门还可以相互通讯。现有设备如下:Cisco 3640路由器,Cisco Catalyst 2924交换机一台,二级交换机若干台。
交换机配置文件中的部分代码如下:
......
!
interface vlan10
ip address 192.168.0.1
!
interface vlan20
ip address 192.168.1.1
!
interface vlan30
ip address 192.168.2.1
!
......
路由器配置文件中的部分代码如下:
......
interface FastEthernet 1/0.1
encapsulation isl 10
ip address 192.168.0.2
!
interface FastEthernet 1/0.2
encapsulation isl 20
ip address 192.168.1.2
!
interface FastEthernet 1/0.3
encapsulation isl 30

ip address 192.168.2.2
!
......
!
router rip
network 192.168.0.0
!
【交换机的端口工作模式的利用】
交换机的端口工作模式通常可以分为三种,它们分别为Access模式、Multi模式、Trunk模式。允许多个vlan的是multi模式,而不是trunk模式。Access模式的交换端口往往只能属于1个VLAN,通常用于连接普通计算机的端口;Trunk模式的交换端口可以属于多个VLAN,能够发送和接受多个VLAN的数据报文,通常使用在交换机之间的级联端口上;multi模式的交换端口可以属于多个VLAN,能够发送和接受多个VLAN的数据报文,可以用于交换机之间的连接,也可以用于连接普通计算机的端口,所以access和trunk没有可比性。三种模式的交换端口能够共同使用在相同的一台交换机中,不过Trunk模式的交换端口和multi模式的交换端口相互之间不能直接切换,往往只能先将交换端口设置为Access模式,之后再设置为其他模式。


首先配置一下交换机

SC-2950>
SC-2950>en
SC-2950#conf t
Enter configuration commands, one per line. End with CNTL/Z.
SC-2950(config)#config-register 0x2102
SC-2950(config)#end

添加三个VLAN

SC-2950#vlan database
SC-2950(vlan)#vlan 10 name v1
VLAN 10 added:
Name: v1
SC-2950(vlan)#vlan 20 name v2
VLAN 20 added:
Name: v2
SC-2950(vlan)#vlan 30 name v3
VLAN 30 added:
Name: v3
SC-2950(vlan)#exit
APPLY completed.
Exiting....
SC-2950#

划分接口到各个VLAN

SC-2950#conf t
Enter configuration commands, one per line. End with CNTL/Z.
SC-2950(config)#int fa0/1 //留给管理员
SC-2950(config-if)#switchport mode access
SC-2950(config-if)#sw acc vlan 10
SC-2950(config-if)#no shutdown
SC-2950(config-if)#exit

SC-2950(config)#int range f0/2 - 15
SC-2950(config-if-range)#sw mode acc
SC-2950(config-if-range)#sw acc vlan 20
SC-2950(config-if-range)#no sh
SC-2950(config-if-range)#exit
SC-2950(config)#int range f0/16 - 24
SC-2950(config-if-range)#sw mode acc
SC-2950(config-if-range)#sw acc vlan 30
SC-2950(config-if-range)#no sh
SC-2950(config-if-range)#exit

激活VLAN,并且给VLAN 10加个IP以便管理

SC-2950(config)#int vlan 10
SC-2950(config-if)#ip add 192.168.1.1 255.255.255.0
SC-2950(config-if)#no sh
SC-2950(config-if)#exit
SC-2950(config)#int vlan 20
SC-2950(config-if)#no sh
SC-2950(config-if)#exit
SC-2950(config)#int vlan 30
SC-2950(config-if)#no sh
SC-2950(config-if)#exit
将交换机指向网关

SC-2950(config)#ip default-gateway 192.168.1.254
SC-2950(config)#end
SC-2950#
检测配置

SC-2950#sh vlan brief

VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active
10 v1

active Fa0/1
20 v2 active Fa0/2, 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
30 v3 active Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24
SC-2950#sh ip int b
Interface IP-Address OK? Method Status Prot
ocol
FastEthernet0/23 unassigned YES unset up down

FastEthernet0/24 unassigned YES unset up down

Vlan1 unassigned YES unset up down

Vlan10 192.168.1.1 YES manual up up

Vlan20 unassigned YES unset up up

Vlan30 unassigned YES unset up down
SC-2950#sh run
Building configuration...

Current configuration : 1482 bytes

...

!
interface FastEthernet0/24
switchport access vlan 30
!
interface Vlan1
no ip address
!
interface Vlan10
ip address 192.168.1.1 255.255.255.0
!
interface Vlan20
no ip address
!
interface Vlan30
no ip address
!
ip default-gateway 192.168.1.254
ip http server
!
...
保存配置

SC-2950#write
Building configuration...
[OK]


相关文档
最新文档