三层交换实现vlan间的相互通信

文章详细描述了如何通过配置命令行在两台交换机上创建VLAN,设置接口模式,配置trunk允许所有VLAN通过,以及在三层交换机上配置IP地址以实现VLAN间的通信。最终,两台PC能够通过配置后的交换机相互通信。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

配置命令行:

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能够相互通信(如图):

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值