![vlan](https://i-blog.csdnimg.cn/blog_migrate/a1004b77ca592d497ae7e8f8727bec60.jpeg)
如图所示拓扑中我们使用了三层交换机一台(3560)一台二层交换机(2960)以及三台pc
在这里我们将pc的地址设成这个样子就可以了
Pc0 1.1.1.1 255.255.255.0 1.1.1.254
Pc1 2.2.2.2 255.255.255.0 2.2.2.254
Pc3 3.3.3.3 255.255.255.0 3.3.3.254
首先
我们需要在二层交换机中起vlan
S1(config)#vlan 2
S1(config-vlan)#vlan 3
S1(config-vlan)#vlan 4
S1(config-vlan)#exit
S1(config)#exit
设完后我们来进行一下验证 会有下面的显示
S1#show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, 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, Fa0/16
Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23, Fa0/24
Gig1/1, Gig1/2
2 VLAN0002 active
3 VLAN0003 active
4 VLAN0004 active
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
然后我们要做一个必不可少的步骤,就是要把没个接口调入相应的vlan
S1(config)#interface fastEthernet 0/1
S1(config-if)#switchport access vlan 2
S1(config-if)#exit
S1(config)#interface fastEthernet 0/2
S1(config-if)#switchport access vlan 3
S1(config-if)#exit
S1(config)#interface fastEthernet 0/3
S1(config-if)#switchport access vlan 4
S1(config-if)#exit
在这里大家要注意了哦!!我们的三层交换机也是必须要起vlan的啊!否则会很郁闷的!!
![发火](http://js3.pp.sohu.com.cn/ppp/p_w_picpaths/emotion/base/detonate.gif)
sw1(config)#vlan 2
sw1(config-vlan)#vl 3
sw1(config-vlan)#vl 4
我们还得把端口设置成trunk模式,就像下面这样!!!
Trunk链两边都要设啊!!!!
sw1(config)#interface fastEthernet 0/1
sw1(config-if)#switchport mode trunk
然后进入每个vlan配置地址吧!一定要有的哦!!这可是pc的网关。
sw1(config)#interface vlan 2
sw1(config-if)#ip address 1.1.1.254 255.255.255.0
做完后show一下vlan
sw1#show vlan brief
Vlan1 unassigned YES manual administratively down down
Vlan2 1.1.1.254 YES manual up up
Vlan3 2.2.2.254 YES manual up up
Vlan4 3.3.3.254 YES manual up up
你也可以show一下路由表
sw1#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
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Vlan2
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Vlan3
3.0.0.0/24 is subnetted, 1 subnets
C 3.3.3.0 is directly connected, Vlan4
好了这里已经完成了
下面只是我们的测试
PC>ping 2.2.2.2
Pinging 2.2.2.2 with 32 bytes of data:
Reply from 2.2.2.2: bytes=32 time=125ms TTL=127
Reply from 2.2.2.2: bytes=32 time=109ms TTL=127
Reply from 2.2.2.2: bytes=32 time=110ms TTL=127
Reply from 2.2.2.2: bytes=32 time=125ms TTL=127
Ping statistics for 2.2.2.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 109ms, Maximum = 125ms, Average = 117ms
转载于:https://blog.51cto.com/xuefan/146409