一、vlan概述
什麼是vlan:vifrtual lan(虛擬局域網)
二、vlan的優勢:廣播控制、安全性、帶寬利用、延遲。
三、vlan的種類:靜態vlan:基於端口劃分的靜態vlan;動態vlan:基於mac地址劃分的動態vlan;
四、vlan的配置:創建vlan有兩種方法
1、全局配置模式:全局:vlan 2 創建vlan2;進入vlan:直接全局輸入vlan;name 名字(給vlan2命名)
2、vlan數據庫配置模式:特權:vlan database;vlan 2 name caiwu(創建vlan2並命名爲caiwu)
3、刪除vlan:進入vlan數據庫或全局模式:no vlan 2.
4、接口加入vlan:進入將要加入vlan的接口然後輸入switchport access vlan 3
同時將多個接口加入vlan:全局:interface range f0/1 - 10 ;switchport access vlan 2將1-10 口同時加入vlan2.
注意:不同vlan配置不同的網絡ID。
5、查看vlan信息:特權:show vlan brief
6、description 添加vlan描述信息;no description 取消描述信息
五、trunk中級連接
1、作用:實現跨交換機之間的vlan通信
2、鏈路類型:接入鏈路;中級鏈路(可以承載多個vlan)
3、vlan的標識:isl(cisco私有的標記方法);ieee802.1q(公有的標記方法):內部封裝在標準以太網幀內插入了4字節,其中12位vlan標識。
4、isl和802.1q的異同:
相同點:都是限時了vlan的信息。
不同點:ieee802.1q是公有的標記方式,isl是私有的。isl採用外部標記的方法,802.1q採用內部標記的方法。isl標記的長度爲30字節,802.1q標記的長度爲4字節。
switchport mode trunk
5、trunk的模式和協商
trunk模式:接入access;幹道trunk;動態期望desirable主動;動態自動auto被動
模式協商結果:switch1 switch2 結果
trunk auto trunk
trunk desirable trunk
auto auto access
auto desirable trunk
desirable desirable trunk
6、trunk的配置:接口模式:switchport mode trunk(直接配置爲trunk )/dynamic desirable/dynamic auto/access/
7、在trunk鏈路上移除某vlan:進入trunk接口:switchport trunk allowed vlan remove 3 中繼鏈路不允許傳送vlan 3 的數據。
8、在trunk鏈路上添加某vlan:進入trunk接口:switchport trunk allowed vlan add 3
9、查看接口模式:show interface f0/5 switchport
六、ethernetchannel(以太網通道)
1、功能:多條線路負載均衡,帶寬提高,容錯,當一條線路失效時,其他線路通信,不會丟包。
2、以太網通道的配置:全局:interface range f0/6 - 8;switchport mode trunk ;channel-group 1 mode on
3、查看:show etherchannel summary
4、以太網通道必須遵循以下一些規則:參與捆綁的端口必須屬於同一個vlan,如果是在中繼模式下,要求所有參加捆綁的端口配置成相同的中繼模式。
所有參與捆綁的端口的物理參數設置比空虛相同,應該不同顏色的速度和全/辦雙攻模式設置。以太網一個通道最多八條鏈路。
七、在路由器上配置dhcp服務
1、全局ip dhcp pool 名字(定義地址池)
2、network 192.168.1.0 255.255.255.0(動態分配IP地址段)
3、default-router 192.168.1.254(動態分配的網關地址)
4、dns-server 202/106.0.20(動態分配的DNS服務器地址)此命令後可以跟多個備用的DNS服務器地址。
5、全局:ip dhcp excluded-address 192.168.1.1(預留已靜態分配的IP地址)後面空格加IP可範圍內應用。
實驗一
實驗名稱:跨交換機vlan通信
步驟1:基本環境配置
工作中常常碰到同一個部門在不同的交換機下工作,遇到這種情況我們該如何操作呢,下面是實驗。
首先打開cisco packet tracer ,購買兩臺交換機A B,併爲其各配4臺主機。組成以下環境
接着在交換機下爲各自主機分配vlan。
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode.
Switch(vlan)#vlan 2 name caiwu
VLAN 2 added:
Name: caiwu
Switch(vlan)#vlan 3 name renshi
VLAN 3 added:
Name: renshi
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface range f0/2 - 3
Switch(config-if-range)#switchport access vlan 2
Switch(config-if-range)#interface range f0/4 - 5
Switch(config-if-range)#switchport access vlan 3
Switch(config-if-range)#
在A交換機上分出vlan2 caiwu 、vlan3renshi並將兩臺電腦的IP設置成不同網段的主機。同樣操作到B交換機下。
步驟2:進行中繼鏈路的配置
此時基本環境以搭建好,下面我們來查看一下
1 default active Fa0/1, Fa0/6, Fa0/7, Fa0/8
Fa0/9, Fa0/10, 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, Fa0/24
2 caiwu active Fa0/2, Fa0/3
3 renshi active Fa0/4, Fa0/5
我們用192.168.1.3 ping 192.168.1.1 發現是不通的,這就無法實現實驗目的,下面接着操作。
進入鏈接兩個交換機的端口
Switch(config)#int f0/24
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to up
Switch(config-if)#
同樣方式設置B交換機。
再ping
發現是可以通信的。至此試驗完成。
實驗二
實驗名稱:配置以太網通道
在實驗一的基礎上,如果我們有很多主機需要中繼鏈路,那麼就會對鏈路造成很大負荷,如何解決這個問題呢,下面實驗配置以太網通道,可以有效的達到負載均衡,冗餘,提高帶寬等作用。
在實驗1的基礎上再連接兩條線到A B 兩臺交換機之間。
進入交換機A輸入以下命令:
Switch(config)#int range f0/22 - 24
Switch(config-if-range)#switchport mode trunk
Switch(config-if-range)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/22, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/22, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to up
Switch(config-if-range)#channel-group 1 mode on
Switch(config-if-range)#
Creating a port-channel interface Port-channel 1
%LINK-5-CHANGED: Interface Port-channel 1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Port-channel 1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/22, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/22, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to up
同樣方式進入B輸入同樣命令,這樣就建好了一條通道
同樣可以ping 通,且帶寬更高,負載均衡。
實驗三
實驗名稱:配置dhcp
步驟1:配置基本環境,併爲路由器設置IP
購買一臺路由器,一臺交換機,三臺主機並將之連接。
Router>enable
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip address 192.168.1.253 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
這樣就給路由器配置好了IP
步驟2:配置dhcp
在路由器輸入下列命令:
Router(config)#ip dhcp pool nsd
Router(dhcp-config)#network 192.168.1.0 255.255.255.0
Router(dhcp-config)#default-router 192.168.1.254
Router(dhcp-config)#dns-server 202.106.0.20
Router(dhcp-config)#
進入主機將IP設爲DHCP