VLAN實驗
如圖所示:圖中共有四個廣播域,左邊邏輯的分為兩個廣播域,右邊也是邏輯的分為兩個廣播域,
配置順序先配置交換機,在配置路由器
SW1 配置:
1、首先建立vlan
[sw1]vlan batch 2 3
2、把對應介面劃入VLAN
因為是交換機和電腦連線的口,所以鏈路型別為access
這個口所屬的 VLAN 為 VLAN 2,相當於把0/0/2劃入vlan 2
0/0/2介面配置:
[sw1-GigabitEthernet0/0/2]port link-type access
[sw1-GigabitEthernet0/0/2]port default vlan 2
同樣0/0/3介面配置:
[sw1-GigabitEthernet0/0/3]port link-type access
[sw1-GigabitEthernet0/0/3]port default vlan 3
3、配置trunk幹道
交換機與交換機相連配置鏈路型別為trunk
[sw1-GigabitEthernet0/0/1]port link-type trunk
[sw1-GigabitEthernet0/0/1]port trunk allow-pass vlan all
4、配置VLAN間路由:
sw1 無直連路由
SW2 配置:
<sw2>undo terminal monitor -------去除配置成功後的日誌:
[sw2]vlan batch 2 3
[sw2]int g 0/0/3
[sw2-GigabitEthernet0/0/3]p l a
[sw2-GigabitEthernet0/0/3]p d v 2
[sw2-GigabitEthernet0/0/3]int g 0/0/4
[sw2-GigabitEthernet0/0/4]p l a
[sw2-GigabitEthernet0/0/4]p d v 3
[sw2-GigabitEthernet0/0/4]int g 0/0/2
[sw2-GigabitEthernet0/0/2]p l t
[sw2-GigabitEthernet0/0/2]p t a v a
[sw2-GigabitEthernet0/0/2]int g 0/0/1
[sw2-GigabitEthernet0/0/1]p l t
[sw2-GigabitEthernet0/0/1]p t a v a
[sw2-GigabitEthernet0/0/1]
SW3 配置:
<sw3>undo terminal monitor
[sw3]vlan batch 2 3
[sw3]int g 0/0/2
[sw3-GigabitEthernet0/0/2]p l a
[sw3-GigabitEthernet0/0/2]p d v 2
[sw3-GigabitEthernet0/0/2]int g 0/0/3
[sw3-GigabitEthernet0/0/3]p l a
[sw3-GigabitEthernet0/0/3]p d v 3
[sw3-GigabitEthernet0/0/3]int g 0/0/1
[sw3-GigabitEthernet0/0/1]p l t
[sw3-GigabitEthernet0/0/1]p t a v a
[sw3-GigabitEthernet0/0/1]
配完以後,我們要想做到一個跨VLAN的通訊的話,我們要配置路由器
首先一共是四個廣播域,對應介面分別管對應廣播域的VLAN,網段劃分如下:
先0/0/0口,建立VLAN,建立子介面0/0/0.1,子介面對應 vlan 2 閘道器配置,劃分vlan,記得開啟arp,
[r1]vlan batch 2 3
[r1]interface GigabitEthernet 0/0/0.1
[r1-GigabitEthernet0/0/0.1]ip address 192.168.1.254 24
[r1-GigabitEthernet0/0/0.1]dot1q termination vid 2
[r1-GigabitEthernet0/0/0.1]arp broadcast enable
同理子介面0/0/0.2配置VLAN 3
[r1]interface GigabitEthernet 0/0/0.2
[r1-GigabitEthernet0/0/0.2]ip address 192.168.2.254 24
[r1-GigabitEthernet0/0/0.2]dot1q termination vid 3
[r1-GigabitEthernet0/0/0.2]arp broadcast enable
然後0/0/1口,同樣建立子介面0/0/1.1,子介面對應 vlan 2 閘道器配置,劃分vlan,記得開啟arp
[r1]interface GigabitEthernet 0/0/1.1
[r1-GigabitEthernet0/0/1.1]ip address 192.168.3.254 24
[r1-GigabitEthernet0/0/1.1]dot1q termination vid 2
[r1-GigabitEthernet0/0/1.1]arp broadcast enable
同理子介面0/0/1.2配置VLAN 3
[r1]interface GigabitEthernet 0/0/1.2
[r1-GigabitEthernet0/0/1.2]ip address 192.168.4.254 24
[r1-GigabitEthernet0/0/1.2]dot1q termination vid 3
[r1-GigabitEthernet0/0/1.2]arp broadcast enable
要去電腦使用DHCP獲取,所以路由開啟DHCP
1、開啟DCHP
[r1]dhcp enable
2、建立IP池,宣告,閘道器,DNS
四個網段,所以建立四個池
aa
[r1]ip pool aa
[r1-ip-pool-aa]network 192.168.1.0 mask 24
[r1-ip-pool-aa]gateway-list 192.168.1.254
[r1-ip-pool-aa]dns-list 114.114.114.114
bb
[r1]ip pool bb
[r1-ip-pool-bb]network 192.168.2.0 mask 24
[r1-ip-pool-bb]gateway-list 192.168.2.254
[r1-ip-pool-bb]dns-list 114.114.114.114
cc
[r1]ip pool cc
[r1-ip-pool-cc]network 192.168.3.0 mask 24
[r1-ip-pool-cc]gateway-list 192.168.3.254
[r1-ip-pool-cc]dns-list 114.114.114.114
dd
[r1]ip pool dd
[r1-ip-pool-dd]network 192.168.4.0 mask 24
[r1-ip-pool-dd]gateway-list 192.168.4.254
[r1-ip-pool-dd]dns-list 114.114.114.114
進入對應的介面選取配置
[r1]int g 0/0/0.1
[r1-GigabitEthernet0/0/0.1]dhcp select global
[r1]int g 0/0/0.2
[r1-GigabitEthernet0/0/0.2]dhcp select global
[r1]int g 0/0/1.1
[r1-GigabitEthernet0/0/1.1]dhcp select global
[r1]int g 0/0/1.2
[r1-GigabitEthernet0/0/1.2]dhcp select global
全網可達完成