不同vlan间的通信如何简单配置 ?
1.单臂路由(图)
环境:一台路由器,一台二层交换机,两台pc机
二层交换机的配置
一般模式:
Switch
输入enable进入特权模式:
Switchenable
输入configure terminal进入全局配置模式:
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
创建vlan 10 和 vlan 20:
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)# exit
进入接口配置模式:
Switch(config)#interface fastEthernet 0/1
把0/1变成trunk口(默认是access口)
Switch(config-if)#switchport mode 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)#exit
进入接口配置模式分别把对应的接口,加入对应的vlan:
Switch(config)#interface fastEthernet 1/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#interface fastEthernet 2/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
到此而层交换机配置完毕!
路由器的配置:
Router
Routerenable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#inter fas 0/0
Router(config-if)#no ip address
Router(config-if)#no shutdown
注意:单臂路由的配置父接口一定要no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#int fas 0/0.10
%LINK-5-CHANGED: Interface FastEthernet0/0.10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.10, changed state to up
Router(config-subif)#encapsulation dot1Q 10
注意:在配置ip时一定要先封装802.1q协议
Router(config-subif)#ip address 192.168.10.1 255.255.255.0
Router(config-subif)#no shutdown
Router(config-subif)#int fas 0/0.20
%LINK-5-CHANGED: Interface FastEthernet0/0.20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.20, changed state to up
Router(config-subif)#ip address 192.168.20.1 255.255.255.0
% Configuring IP routing on a LAN subinterface is only allowed if that
subinterface is already configured as part of an IEEE 802.10, IEEE 802.1Q,
or ISL vLAN.
Router(config-subif)#encapsulation dot1Q 20
Router(config-subif)#ip address 192.168.20.1 255.255.255.0
Router(config-subif)#no shutdown
Router(config-subif)#
查看路由表:
Router#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.10.0/24 is directly connected, FastEthernet0/0.10
C 192.168.20.0/24 is directly connected, FastEthernet0/0.20
Router#
PC0的配置:
ip 192.168.10.10
netmask 255.255.255.0
gateway 192.168.10.1
PC1的配置:
ip 192.168.20.20
netmask 255.255.255.0
gateway 192.168.20.1
2.使用SVI实现VLAN间的通信(图)
环境:一台三层交换机,两台pc机
三层交换机的配置:Switchenable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
创建vlan 10 20
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#exit
配置SVI接口ip
Switch(config)#interface vlan 10
%LINK-5-CHANGED: Interface Vlan10, changed state to up
Switch(config-if)#ip address 192.168.10.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#interface vlan 20
%LINK-5-CHANGED: Interface Vlan20, changed state to up
Switch(config-if)#ip address 192.168.20.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
改变接口模式并加入vlan
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
Switch(config-if)#interface fastEthernet 0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
Switch(config-if)#
看三层交换机的路由表:
Switch#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.10.0/24 is directly connected, Vlan10
C 192.168.20.0/24 is directly connected, Vlan20
Switch#
两主机的配置与单臂路由中两主机的配置一样
3.跨交换机实现VLAN间的通信(图)
环境:一台三层交换机,两台二层交换机,两台pc机
三层交换机的配置(SW3)
Switchenable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
创建vlan 10 、 20 并设置ip
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#exit
Switch(config)#interface vlan 10
%LINK-5-CHANGED: Interface Vlan10, changed state to up
Switch(config-if)#ip address 192.168.10.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#interface vlan 20
%LINK-5-CHANGED: Interface Vlan20, changed state to up
Switch(config-if)#ip address 192.168.20.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
设置接口模式并加入相应的vlan(注意trunk口的设置)
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#interface fastEthernet 0/1
Switch(config-if)#switchport access vlan 10
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
Switch(config)#interface fastEthernet 0/2
Switch(config-if)#switchport mode trunk
Switch(config-if)#interface fastEthernet 0/2
Switch(config-if)#switchport access vlan 20
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
Switch#
看路由表
Switch#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.10.0/24 is directly connected, Vlan10
C 192.168.20.0/24 is directly connected, Vlan20
SW21的配置
Switchenable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport mode 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)#interface fastEthernet 1/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#
SW22的配置
Switch
Switchen
Switch#
Switch#configure ter
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#inter fas 1/1
Switch(config-if)#switchport mode trunk
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/1, changed state to up
Switch(config-if)#switchport mode access
Switch(config-if)#inter fas 2/1
Switch(config-if)#switchport mode trunk
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet2/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet2/1, changed state to up
Switch(config-if)#exit
Switch(config)#vlan 20
Switch(config-vlan)#inter fas 1/1
Switch(config-if)#switchport access vlan 20
Switch(config-if)#
注意:两交换机之间的链接是trunk链路
4.以上配置在模拟器上都可实现
在模拟器上配置其中pc图片
上述三种方式pc机的配置都一样
验证:
本文出自 “linuxme” 博客,请务必保留此出处http://linuxme.blog.51cto.com/1850814/389229
绛旓細瀵逛簬璺ㄤ笁灞備氦鎹㈡満瀹炵幇VLAN闂撮氫俊锛屽彲浠ュ湪涓ゅ彴浜ゆ崲鏈轰箣闂撮厤缃崟鑷傝矾鐢辨垨涓夊眰浜ゆ崲鏈烘潵瀹炵幇銆傚叾涓紝鍗曡噦璺敱鏄氳繃涓涓墿鐞嗘帴鍙h繛鎺ヤ袱涓猇LAN锛屽苟鍦ㄨ繖涓や釜VLAN涔嬮棿杩涜璺敱锛涜屼笁灞備氦鎹㈡満鍒欏彲浠ュ湪鍘熸湁浜屽眰浜ゆ崲鏈虹殑鍩虹涓婂鍔犺矾鐢卞姛鑳斤紝鏁版嵁鍖呬笉闇瑕佺粡杩囩墿鐞嗙嚎璺繘琛岃矾鐢便傛祴璇曡繛閫氭с傚畬鎴愪笂杩伴厤缃悗锛屽彲浠ラ氳繃...
绛旓細1.鍦ㄤ笁灞備氦鎹㈡満涓婅缃袱涓獀lan锛歷lan 10鍜寁lan 20锛2.鍦ㄤ笁灞備氦鎹㈡満涓婂垱寤轰袱涓猄VI锛堜氦鎹㈣櫄鎷熸帴鍙o級锛3.涓篠VI vlan 10鍜寁lan 20鍒嗛厤IP鍦板潃锛屼袱涓帴鍙g殑IP搴旇灞炰簬鐙珛鐨勫瓙缃戯紱4.鍦ㄤ笁灞備氦鎹㈡満涓婂惎鐢╥p routing锛5.灏嗚繛鎺ョ數鑴戠殑绔彛鍒掑垎鍒扮浉搴旂殑VLAN涓紱6.涓嶅悓VLAN涓殑鐢佃剳IP鎵灞炵綉缁滐紝搴斿拰涓夊眰浜ゆ崲...
绛旓細鑻ユ偍浣跨敤浜嗕笁灞備氦鎹㈡満,鎴栬呬簩灞備氦鎹㈡満涓婂姞涓涓狹SFC(鏃㈠灞備氦鎹㈢壒鎬у崱),灏卞彲浠ュ疄鐜拌矾鐢卞姛鑳,閭d箞鍦ㄤ笁灞備腑鎴戜滑鍙互灏嗚矾鐢卞姛鑳藉紑鍚,瀵涓嶅悓VLAN鍋歋VI,璧风敤闈欐佹垨鑰呭姩鎬佽矾鐢卞崗璁,灏卞彲浠ュ疄鐜颁簡.鏂瑰紡2: 鍗曡噦璺敱 鎴戠粰鎮ㄦ弿杩颁竴涓绠鍗鐨勬ā鍨,涓鍙拌矾鐢卞櫒,涓鍙颁氦鎹㈡満. 浜ゆ崲鏈轰笂鏈変袱涓猇LAN,閭e湪浜屽眰鑲畾鏃犳硶閫...
绛旓細褰撴垜浠湪浜ゆ崲鏈轰笂閰嶇疆VLAN鏃讹紝鍙互瀹炵幇鍚屼竴涓猇LAN鍐呯殑涓绘満涔嬮棿鐩镐簰閫氫俊锛屽苟涓涓嶅悓VLAN涔嬮棿鐨涓绘満鏃犳硶鐩存帴閫氫俊銆備笅闈㈡垜灏嗕粠閫昏緫鍜屾楠ゆ柟闈㈣В閲婂浣曢氳繃浜ゆ崲鏈洪厤缃潵瀹炵幇杩欎竴鐐广傞鍏堬紝璁╂垜浠簡瑙d粈涔堟槸铏氭嫙灞鍩熺綉锛圴irtual Local Area Network, VLAN锛夈俈LAN鏄竴绉嶅皢鐗╃悊缃戠粶鍒掑垎涓哄涓昏緫瀛愮綉缁滅殑鎶鏈紝鍦...
绛旓細铏氭嫙灞鍩熺綉锛VLAN锛夋槸涓缁勯昏緫涓婄殑璁惧鍜岀敤鎴凤紝杩欎簺璁惧鍜岀敤鎴峰苟涓嶅彈鐗╃悊浣嶇疆鐨勯檺鍒讹紝鍙互鏍规嵁鍔熻兘銆侀儴闂ㄧ瓑鍥犵礌灏嗗畠浠粍缁囪捣鏉ワ紝鐩镐簰涔嬮棿鐨勯氫俊灏卞ソ鍍忓畠浠湪鍚屼竴涓綉娈典腑涓鏍枫vlan涓巚lan杩炴帴鏂规硶锛1銆侀氳繃璺敱鍣ㄧ殑涓嶅悓鐗╃悊鎺ュ彛涓庝氦鎹㈡満涓婄殑姣忎釜vlan鍒嗗埆杩炴帴锛氳繖绉嶆柟寮忕殑浼樼偣鏄鐞绠鍗锛岀己鐐规槸缃戠粶鎵╁睍闅惧害...
绛旓細1.涓嶅悓VLAN瑕佸疄鐜閫氫俊锛屽繀椤荤涓夊眰璁惧锛屾瘮濡傝矾鐢卞櫒銆2.杩炶矾鐢卞櫒鐨勪氦鎹㈡満绔彛闇閰嶇疆鎴愪腑缁фā寮忥紝鍗冲懡浠witchport mode trunk锛涜繛鍒颁富鏈虹殑绔彛闇閰嶇疆鎴愯闂ā寮忥紝鍗硈witchport mode access銆3.杩炰氦鎹㈡満鐨勮矾鐢卞櫒鎺ュ彛涓嶈兘閰嶇疆ip鍦板潃锛岃屾槸瑕侀厤缃瓙鎺ュ彛锛屽瓙鎺ュ彛鐨刬p鏄煇涓猇LAN鐨勭綉鍏筹紝瀛愭帴鍙p鍜孷LAN涓殑...
绛旓細涓嶅悓vlan闂撮氫俊闂鍙互閫氳繃鍗曠瑪璺敱瀹炵幇 浠ヤ笅鏄瘮杈冩爣鍑嗙殑鍗曡噦璺敱閰嶇疆锛氫氦鎹㈡満锛氫氦鎹㈡満涓庤矾鐢卞櫒鐨勭鍙i厤缃负Trunk妯″紡 鎺ョ粓绔殑閰嶇疆涓篴ccess妯″紡 璺敱鍣細杩涘叆f0/0.1 鐢╠ot1q灏佽vlan2 閰嶇疆 ip鍦板潃浣滀负vlan2 鐨勭綉鍏 杩涘叆f0/0.2 鐢╠ot1q灏佽vlan3 閰嶇疆 ip鍦板潃浣滀负vlan3 鐨勭綉鍏 鏈鍚庡皢PC閰嶇疆濂藉悗...
绛旓細鍙互 浣跨敤澶栭儴璺敱鍣ㄥ疄鐜VLAN闂璺敱锛堝崟鑷傝矾鐢憋級灏辨槸鍦ㄤ氦鎹㈡満杩炴帴涓涓矾鐢卞櫒,鍏堕厤缃涓嬶紱鍦ㄨ矾鐢卞櫒鐨勭墿鐞嗕互澶綉鎺ュ彛涓嬪垱寤哄瓙鎺ュ彛锛屽苟瀹氫箟灏佽绫诲瀷 R1(config)#int fa0/0 R1(config-if)#no shutdown R1(config)#int fa0/0.1 R1(config-subif)#encapture dot1q 10 native //浠ヤ笂鏄畾涔夎瀛愭帴鍙...
绛旓細vlan10鐨刬nterface vlan ip璁剧疆璧锋潵锛屽亣璁句负192.1.1.254 Juniper闃茬伀澧欎笂璁剧疆闈欐佽矾鐢憋紝route add 10.1.1.0 255.255.255.0 192.1.1.254 route add 10.2.1.0 255.255. 255.0 192.1.1.254
绛旓細鍙互閫氫俊,浣嗘槸蹇呴』浣犵殑浜ゆ崲鏈烘槸涓夊眰浜ゆ崲鏈,缁欑浉搴旂殑vlan閰嶇疆涓奍P鍦板潃,鎴栬呭湪浜屽眰浜ゆ崲鏈轰笂鎺ヤ笂涓涓矾鐢卞櫒,灏嗚矾鐢卞櫒鐨勬帴鍙e垝鍑鸿澶氬瓙鎺ュ彛鏉,鍦ㄥ瓙鎺ュ彛涓婇厤缃浉搴旂殑鍚嶇О鍜孖P鍦板潃,涔熸槸涓鏍峰彲浠ヤ娇浜屽眰浜ゆ崲鏈轰笂鐨剉lan閫氫俊.