實驗六 利用路由器實現VLAN
【實驗目的】
熟悉路由器子接口相關配置,實現不同VLAN間主機的通信。
- 了解路由器子接口的含義及作用
- 正確配置路由器子接口的相關配置
【背景描述】
某公司建立網路,划分了銷售部和技術部兩個VLAN,銷售部的一台計算機划分到VLAN10中,技術部的一台計算機划分到VLAN20中。先要對路由器和交換機進行相應的配置,以實現兩個部門主機間進行通信。
【實驗功能】
通過對路由器子接口進行相關配置,實現不同VLAN間主機的通信。
【實驗原理】
在交換網絡中,通過VLAN對一個物理網絡進行了邏輯划分,不同的VLAN之間是無法直接訪問的,必須通過三層的路由設備進行連接。一般利用路由器或三層交換機來實現不同VLAN之間的互相訪問。
將路由器和交換機相連,使用IEEE 802.1q 來啟動路由器上的子接口成為干道模式,就可以利用路由器來實現VLAN之間的通信。
路由器可以從某一個VLAN接收數據包,並將這個數據包轉發到另一個VLAN,要實施VLAN間的路由,必須在一個路由器的物理接口上啟用子接口,也就是將一太網物理接口划分為多個邏輯的,可編址的接口,並配置成干道模式,每個VLAN對應一個這樣的接口,這樣路由器就能夠知道如何到達這些互連VLAN。
二層交換機和路由器之間只連一根線,在路由器以太網口上做VLAN相應的子接口,VLAN內的PC的網關都指向相應的子接口地址,而路由器有路由功能,這樣VLAN間就可以通信了。這種連接方式有一個缺點,就是路由器的轉發能力會是一個瓶頸,現實中一般不會采用這種方式。
配置路由器子接口的相關命令如下:
interface interface-id. subinterface-id
encapsulation dot1Q vlan-id
ip address ip-address network
舉例
interface fastEthernet 0/0.10 //配置接口f0的子接口10
encapsulation dot1Q 10 //配置802.1q封裝,VLANID為10
ip address 192.168.0.1 255.255.255.0 //配置子接口IP地址
【實驗拓撲】
利用路由器實現VLAN間通信
【實驗步驟】
第1步 路由器子接口配置:
Route #configure terminal //進入全局配置模式
Route (config)#interface fastEthernet 0/0
Route (config-if-FastEthernet 0/0)#no ip address //端口不能設置IP
Route (config-if-FastEthernet 0/0)#no shutdown
Route (config-if-FastEthernet 0/0)#exit
Route (config)#interface fastEthernet 0/0.10
Route (config-subif)#encapsulation dot1Q 10 //配置802.1q封裝,VLANID為10
Route (config-subif)#ip address 192.168.0.1 255.255.255.0 //配置子接口IP地址
Route (config-subif)#no shutdown
Route (config-subif)#exit
Route (config)#interface fastEthernet 0/0.20
Route (config-subif)#encapsulation dot1Q 20 //配置802.1q封裝,VLANID為20
Route (config-subif)#ip address 192.168.1.1 255.255.255.0 //配置子接口IP地址
Route (config-subif)#no shutdown
Route (config-subif)#exit
第2步 交換機VLAN配置
Switch# configure terminal //進入全局配置模式
Switch(config)#vlan 10 //創建VLAN10
Switch(config-vlan)#name sales //對VLAN10進行命名
Switch(config-vlan)#exit
Switch(config)#vlan 20 //創建VLAN20
Switch(config-vlan)#name technology //對VLAN20進行命名
Switch(config-vlan)#exit
Switch(config)#interface range f 0/1-9
Switch(config-if-range)#switchport access vlan 10 //將1-9端口划入到VLAN10
Switch(config-if-range)#exit
Switch(config)#interface f 0/10
Switch(config-if)#switchport access vlan 20 //將10端口划入到VLAN20
Switch(config-if)#exit
第3步 配置Trunk口
Switch(config)#interface fastEthernet 0/24
Switch(config-if)#switchport mode trunk
Switch(config-if)#exit
第4步 顯示配置
在交換機上運行下列命令
show run
vlan 1 ! vlan 10 name sales ! vlan 20 name technology ! interface fastEthernet 0/1 switchport access vlan 10 ! interface fastEthernet 0/10 switchport access vlan 20 ! interface fastEthernet 0/24 switchport mode trunk ! end
|
show vlan
VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- 1 default active 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 10 sales active Fa0/1 ,Fa0/2 ,Fa0/3 Fa0/4 ,Fa0/5 ,Fa0/6 Fa0/7 ,Fa0/8 ,Fa0/9
20 technology active Fa0/10
|
從以上都可以看出VLAN10和VLAN20都已經創建成功,相應的端口也划入了VLAN。
在路由器上運行下列命令
show run
interface FastEthernet 0/0 duplex auto speed auto ! interface FastEthernet 0/0.10 encapsulation dot1Q 10 ip address 192.168.0.1 255.255.255.0 ! interface FastEthernet 0/0.20 encapsulation dot1Q 20 ip address 192.168.1.1 255.255.255.0
|
上面顯示出了路由器子接口的IP地址。
show vlan
Virtual LAN ID: 10 (IEEE 802.1Q Encapsulation) vLAN Interface FastEthernet 0/0.10 IP address: 192.168.0.1 Received:4 packets, Transmitted: 2 packets
Virtual LAN ID: 20 (IEEE 802.1Q Encapsulation) vLAN Interface FastEthernet 0/0.20 IP address: 192.168.1.1 Received:1 packets, Transmitted: 2 packets |
上面是路由器子接口VLAN信息。
驗證測試:
將連接在F0/1上的計算機IP地址改為192.168.0.10,子網掩碼設成255.255.255.0,網關設置為192.168.0.1。
將連接在F0/10上的計算機IP地址改為192.168.1.10,子網掩碼設成255.255.255.0,網關設置為192.168.1.1。然后在連接在F0/1上的計算機上執行如下命令。
Ping 192.168.0.1
Ping 192.168.1.1
Ping 192.168.1.10
如果都能ping通,則說明路由器配置正確。
【注意事項】
- 要對路由器的子接口進行封裝
- 要對路由器的子接口配置IP地址
- 要把路由器的子接口划分到不同的VLAN中