首先,说明一下本例子。
vlan之间通讯需要用到的设备有:二层交换机两个(当然三层也可以,不过很贵~~),路由器/3层交换机一台(支持802.1q协议),pc4台。
试验环境为Cisco虚拟软件packet trcer 4.1二层交换机:首先要明白一点,对于vlan通讯来说,二层交换机上vlan没有必要配ip地址,唯一需要的是vlan1(配置的ip地址为管理地址)。
其次,二层交换机没有ip地址。
当然vlan可以设置ip,但是端口什么的没有ip。
虽然这点很简单,但是,很多人经常忘记,至少我身边的同学好多都不知道这个事实。
还有,这点很重要,二层交换机只能同一时刻存在一个vlan。
最后,要保证vlan之间可以相互通讯的前提,就是二层与路由的接口要设置为trunk模式。
路由器:由于要实现vlan之间通讯,所以路由器需要用到802.1q协议,来封装端口。
(下面开始配置)S1:vlan 1 :IP :10.1.0.2/16vlan 10: name--V1 下属pc:IP:192.168.1.x/24 网关 192.168.1.254/24vlan 20: name--V2 下属pc:IP:192.168.2.x/24 网关 192.168.2.254/24S2:vlan1:IP:10.2.0.2/16vlan 30: name--V3 下属pc:IP:192.168.3.x/24 网关 192.168.3.254/24vlan 40: name--V4 下属pc:IP:192.168.4.x/24 网关 192.168.4.254/24R1:F0/0:IP:10.1.0.1/16虚接口地址:F0/0.1: IP:192.168.1.254/24F0/0.2: IP:192.168.2.254/24F0/1:IP:10.2.0.1/16虚接口地址:F0/1.1: IP:192.168.3.254/24F0/1.2: IP:192.168.4.254/24拓扑图如下:S1配置如下:Switch>enSwitch#conf tEnter configuration commands, one per line. End with CNTL/Z.Switch(config)#hostSwitch(config)#hostname S1S1(config)#vlan 10S1(config-vlan)#name V1S1(config-vlan)#exitS1(config)#vlan 20S1(config-vlan)#name V2S1(config-vlan)#int vlan 1S1(config-if)#ip address 10.1.0.2 255.255.0.0S1(config-if)#no shut%LINK-5-CHANGED: Interface Vlan1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up S1(config-if)#int f0/2S1(config-if)#switchport mode accessS1(config-if)#switchport access vlan 10S1(config-if)#no shutS1(config-if)#int f0/3S1(config-if)#switchport mode accessS1(config-if)#switchport access vlan 20S1(config-if)#no shutS1(config-if)#int f0/1S1(config-if)#switchport mode trunkS1(config-if)#switchport trunk allowed vlan allS1(config-if)#no shutS1(config-if)#end%SYS-5-CONFIG_I: Configured from console by consoleS1#sh vlanVLAN Name Status Ports---- -------------------------------- --------- ------------------------------- 1 default active Fa0/1, Fa0/4, Fa0/5, Fa0/6Fa0/7, Fa0/8, Fa0/9, Fa0/10Fa0/11, Fa0/12, Fa0/13, Fa0/14Fa0/15, Fa0/16, Fa0/17, Fa0/18Fa0/19, Fa0/20, Fa0/21, Fa0/22Fa0/23, Fa0/2410 V1 active Fa0/220 V2 active Fa0/31002 fddi-default active1003 token-ring-default active1004 fddinet-default active1005 trnet-default activeVLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ 1 enet 100001 1500 - - - - - 0 010 enet 100010 1500 - - - - - 0 020 enet 100020 1500 - - - - - 0 01002 enet 101002 1500 - - - - - 0 01003 enet 101003 1500 - - - - - 0 01004 enet 101004 1500 - - - - - 0 01005 enet 101005 1500 - - - - - 0 0S2设置如上:Switch>enSwitch#conf tEnter configuration commands, one per line. End with CNTL/Z.Switch(config)#hostname S2S2(config)#vlan 30S2(config-vlan)#name V3S2(config-vlan)#no shut^% Invalid input detected at '^' marker.S2(config-vlan)#vlan 40S2(config-vlan)#name V4S2(config-vlan)#int vlan 1S2(config-if)#ip address 10.2.0.2 255.255.0.0S2(config-if)#no shut%LINK-5-CHANGED: Interface Vlan1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to upS2(config-if)#int f0/2S2(config-if)#swit m aS2(config-if)#swit access vlan 30S2(config-if)#no shutS2(config-if)#int f0/3S2(config-if)#swit m aS2(config-if)#swit a vlan 40S2(config-if)#no shutS2(config-if)#int f0/1S2(config-if)#swit m tS2(config-if)#swit trunk allowed vlan allS2(config-if)#no shutS2(config-if)#end%SYS-5-CONFIG_I: Configured from console by consoleS2#sh vlanVLAN Name Status Ports---- -------------------------------- --------- ------------------------------- 1 default active Fa0/1, Fa0/4, Fa0/5, Fa0/6Fa0/7, Fa0/8, Fa0/9, Fa0/10Fa0/11, Fa0/12, Fa0/13, Fa0/14Fa0/15, Fa0/16, Fa0/17, Fa0/18Fa0/19, Fa0/20, Fa0/21, Fa0/22Fa0/23, Fa0/2430 V3 active Fa0/240 V4 active Fa0/31002 fddi-default active1003 token-ring-default active1004 fddinet-default active1005 trnet-default activeVLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------1 enet 100001 1500 - - - - - 0 030 enet 100030 1500 - - - - - 0 040 enet 100040 1500 - - - - - 0 01002 enet 101002 1500 - - - - - 0 01003 enet 101003 1500 - - - - - 0 01004 enet 101004 1500 - - - - - 0 01005 enet 101005 1500 - - - - - 0 0路由器R1设置如下:Router>enableRouter#conf tEnter configuration commands, one per line. End with CNTL/Z.Router(config)#hostname R1R1(config)#R1(config)#int f0/0R1(config-if)#ip address 10.1.0.1 255.255.0.0R1(config-if)#no shut%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to upR1(config-if)#int f0/1R1(config-if)#ip address 10.1.1.1 255.255.0.0% 10.1.0.0 overlaps with FastEthernet0/0R1(config-if)#ip address 10.2.0.1 255.255.0.0R1(config-if)#no shut%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upR1(config-if)#int f0/0.1%LINK-5-CHANGED: Interface FastEthernet0/0.1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.1, changed state to upR1(config-subif)#encapsulation dot1q 10R1(config-subif)#ip address 192.168.1.254 255.255.255.0R1(config-subif)#no shutR1(config-subif)#int f0/0.2%LINK-5-CHANGED: Interface FastEthernet0/0.2, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to upR1(config-subif)#encapsulation dot1q 20R1(config-subif)#ip address 192.168.2.254 255.255.255.0R1(config-subif)#no shutR1(config-subif)#int f0/1.1%LINK-5-CHANGED: Interface FastEthernet0/1.1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1.1, changed state to upR1(config-subif)#encapsulation dot1q 30R1(config-subif)#ip address 192.168.3.254 255.255.255.0R1(config-subif)#no shutR1(config-subif)#int f0/1.2%LINK-5-CHANGED: Interface FastEthernet0/1.2, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1.2, changed state to upR1(config-subif)#encapsulation dot1q 40R1(config-subif)#ip address 192.168.4.254 255.255.255.0R1(config-subif)#no shutR1(config-subif)#end%SYS-5-CONFIG_I: Configured from console by consoleR1#show ip routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGPi - 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 - ODRP - periodic downloaded static routeGateway of last resort is not set10.0.0.0/16 is subnetted, 2 subnetsC 10.1.0.0 is directly connected, FastEthernet0/0C 10.2.0.0 is directly connected, FastEthernet0/1C 192.168.1.0/24 is directly connected, FastEthernet0/0.1C 192.168.2.0/24 is directly connected, FastEthernet0/0.2C 192.168.3.0/24 is directly connected, FastEthernet0/1.1C 192.168.4.0/24 is directly connected, FastEthernet0/1.2现在,可以设置PC的属性了,别忘了四处ping下,检查是否设置成功。