轉自:http://7c0bab95.wiz03.com/share/s/1Y2WKl218k5e2gpBCl2BeEsq0Yy3ew3HcQys2wxOLl08agY4
利用三層交換機實現VLAN間路由
技術原理
1)三層交換機是帶有三層路由功能的交換機,也就是這臺交換機的端口既有三層路由功能,也具有二層交換功能。三層交換機端口默認爲二層口,如果需要啓用三層功能就需要在此端口輸入no switchport命令。
2)三層交換機具備網絡層的功能,實現VLAN相互訪問的原理:
利用三層交換機的路由功能,通過識別數據包的IP地址,查找路由表進行選路轉發,三層交換機利用直連路由可以實現不同VLAN之間的相互訪問;
三層交換機給接口配置IP地址,採用SVI(交換虛擬接口)的方式實現VLAN間互連,SVI是指爲交換機中的VLAN創建虛擬接口,並且配置IP地址。
實驗說明
在同一個局域網中,在 05.交換機劃分Vlan的基礎上,PC0、PC2 和 PC1、PC3分別屬於同一個Vlan分組(PC0、PC1和PC2、PC3分別歸屬同一個交換機),但同時還要實現兩個分組之間可以相互訪問;
使用三層交換機代替原來的一個交換機,在三層交換機上分別設置各VLAN的接口IP地址。三層交換機將vlan做爲一種接口對待,就象路由器上的一樣,再在各接入VLAN的計算機上設置與所屬VLAN的網絡地址一致的IP地址,並且把默認網關設置爲該VLAN的接口地址。這樣,所有的VLAN也可以互訪了。
實驗步驟
1)在二層交換機上配置VLAN2、VLAN3,分別將端口2、端口3劃分給VLAN2、VLAN3。
2)將二層交換機與三層交換機相連的端口fa 0/1都定義爲tag Vlan模式。
3)在三層交換機上配置VLAN2、VLAN3,此時驗證二層交換機VLAN2、VLAN3下的主機之間不能相互通信。
4)設置三層交換機VLAN間的通信,創建VLAN2,VLAN3的虛接口,並配置虛接口VLAN2、VLAN3的IP地址。
5)查看三層交換機路由表。
6)將二層交換機VLAN2、VLAN3下的主機默認網關分別設置爲相應虛擬接口的IP地址。
7)驗證二層交換機VLAN2,VALN3下的主機之間可以相互通信。
實驗設備
Switch_2960 1臺;Swithc_3560 1臺;PC 3臺;直連線
實驗設備配置
PC0
IP: 192.168.1.2
Submark: 255.255.255.0
Gateway: 192.168.1.1
PC1
IP: 192.168.2.2
Submark: 255.255.255.0
Gateway: 192.168.2.1
PC2
IP: 192.168.1.3
Submark: 255.255.255.0
Gateway: 192.168.1.1
PC3
IP: 192.168.2.3
Submark: 255.255.255.0
Gateway: 192.168..1
將PC0、PC2 和 PC1、PC3 劃分到不同網關,此時兩個網關分組無法相互連通
PC1 Ping PC3 reply
PC1 Ping PC2 timeout
S2960交換機配置(同05.交換機Vlan配置)
Switch>en
Switch#conf t
//創建2個新vlan分組,並將相應的端口綁定到vlan分組
Switch(config )#vlan 2
Switch(config-vlan)#exit
Switch(config )#vlan 3
Switch(config-vlan)#exit
Switch(config )#interface fa 0/2
Switch(config-if)#switchport access vlan 2
Switch(config-if)#exit
Switch(config )#inter fa 0/3
Switch(config-if)#switchport access vlan 3
Switch(config-if)#exit
//修改交換機連接端口模式爲 trunk
Switch(config )#inter fa 0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#end
Switch#show vlan //查看vlan端口情況
S3560
Switch>en
Switch#conf t
//新建vlan2 vlan3
Switch(config )#vlan 2
Switch(config-vlan)#exit
Switch(config )#vlan 3
Switch(config-vlan)#exit
- //對各個端口進行配置
//(1)配置交換機和三層交換機的連接端口
Switch(config )#inter fa 0/1
Switch(config-if)#switchport trunk encapsulation dot1q //給該接口的trunk封裝爲802.1Q的幀格式
Switch(config-if)#switchport mode trunk //定義該接口的工作模式爲trunk
Switch(config-if)#exit
//(2)配置終端連接端口
//將終端端口綁定到vlan指定分組
Switch(config )#inter fa 0/2
Switch(config-if)#switchport access vlan 2
Switch(config-if)#exit
Switch(config )#inter fa 0/3
Switch(config-if)#switchport access vlan 3
Switch(config-if)#exit
//對2個vlan虛擬接口進行路由轉發配置
Switch(config )#inter vlan 2 //進入vlan2 虛擬接口
Switch(config-if)#ip address 192.168.1.1 255.255.255.0 //配置IP地址
Switch(config-if)#no shutdown //開啓該三層端口(路由功能)
Switch(config-if)#exit
Switch(config )#inter vlan 3
Switch(config-if)#ip address 192.168.2.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#end
Switch#show ip route //顯示路由表
Switch#show vlan //顯示vlan信息
實驗驗證
PC1 Ping PC3 reply
PC1 Ping PC2 reply