思科设备三层交换机的vlan间通信配置

本次主要讲解三层交换实现vlan间的相互通信:

思科设备三层交换机的vlan间通信配置

本例配置模型图

命令行:

swA配置命令:

Switch>enable

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 name TztA //在swA上创建vlan 2 名为TztA VLAN 2 added:

Name: TztA

Switch(vlan)#vlan 3 name TztB //在swA上创建vlan 3 名为TztB VLAN 3 added:

Name: TztB

Switch(vlan)#exit

APPLY completed.

Exiting....

Switch#conf t

Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#int f0/2

Switch(config-if)#switchport mode access

Switch(config-if)#switchport access vlan 2 //将f0/2划分给vlan 2

Switch(config-if)#exit

Switch(config)#int f0/3

Switch(config-if)#switchport mode access

Switch(config-if)#switchport access vlan 3 //将f0/3划分给vlan 3

Switch(config-if)#exit

Switch(config)#int f0/1

Switch(config-if)#switchport mode trunk //配置与三层设备连接的f0/1为trunk模式

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

Switch(config-if)#switchport trunk allowed vlan all //允许所有vlan通过f0/1端口Switch(config-if)#exit

Switch(config)#exit

Switch#

%SYS-5-CONFIG_I: Configured from console by console

Switch#wr

Building configuration...

[OK]

Switch#

(三层交换机)M sw命令配置:

Switch>

Switch>enable

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 name TztA //在Msw上创建vlan 2 名为TztA

VLAN 2 added:

Name: TztA

Switch(vlan)#vlan 3 name TztB //在Msw上创建vlan 2 名为TztA

VLAN 3 added:

Name: TztB

Switch(vlan)#exit

APPLY completed.

Exiting....

Switch#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Switch(config)#int f0/1

Switch(config-if)#switchport mode trunk //配置三层设备与二层设备连接的f0/1为trunk模式

Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode.

Switch(config-if)#switchport trunk allowed vlan all //允许所有vlan通过f0/1端口Switch(config-if)#no shutdown //激活端口

Switch(config-if)#exit

Switch(config)#ip routing //使用三层设备的路由功能

Switch(config)#int vlan 2 //进入vlan 2配置模式虚拟端口

%LINK-5-CHANGED: Interface Vlan2, changed state to up

Switch(config-if)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan2, changed state to up

Switch(config-if)#ip address 192.168.1.1 255.255.255.0 //配置vlan 2的ip地址Switch(config-if)#no shutdown //激活端口

Switch(config-if)#exit

Switch(config)#int vlan 3 //配置vlan 3虚拟端口

Switch(config-if)#

%LINK-5-CHANGED: Interface Vlan3, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan3, changed state to up

Switch(config-if)#ip address 192.168.2.1 255.255.255.0

Switch(config-if)#no shutdown

Switch(config-if)#exit

Switch(config)#do show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area * - candidate default, U - per-user static route, o - ODR

P - periodic downloaded static route

Gateway of last resort is not set

C 192.168.1.0/24 is directly connected, Vlan2 //上述的配置成果

C 192.168.2.0/24 is directly connected, Vlan3

Switch(config)#

Switch(config)#exit

Switch#

%SYS-5-CONFIG_I: Configured from console by console

Switch#wr

Building configuration...

[OK]

以上配置结束完成后,两台PC能够相互通信(如图):

思科设备三层交换机的vlan间通信配置

注意:通信基础需要配置网关

本次讲解结束!

相关推荐
相关主题
热门推荐