配置DHCP伺服器執行個體網絡環境:一台2811路由,一台2950交換機,一台3560交換機,三台自動擷取IP位址的PC。
劃分三個vlan1,vlan2,vlan3。拓撲如下
配置指令及步驟如下:
第一步:配置Router1 2811路由成為DHCP伺服器
1、設定位址池
Router1(Config)#ip dhcp pool test01
Router1(Config)#ip dhcp pool test02
Router1(Config-pool)#network 192.168.2.0 255.255.255.0
Router1(Config-pool)#Default-router 192.168.2.254
Router1(Config-pool)#lease 30
Router1(Config-pool)#exit
Router1(Config)#ip dhcp pool test03
Router1(Config-pool)#network 192.168.3.0 255.255.255.0
Router1(Config-pool)#Default-router 192.168.3.254
Router1(Config-pool)#lease 30
Router1(Config-pool)#exit
Router1(Config)Ip Dhcp Excluded-address 192.168.1.2 192.168.1.10
/* ip 192.168.1.2至192.168.1.10這9個IP位址伺服器不配置設定出去
Router1(Config)Ip Dhcp Excluded-address 192.168.2.2 192.168.2.10
/*同上 192.168.2.2至192.168.2.10不配置設定
Router1(Config)Ip Dhcp Excluded-address 192.168.3.2 192.168.3.10
/*同上 192.168.3.2至192.168.3.10不配置設定
PS:
一般要把網關位址設成不配置設定~~比如我們剛才設的子網網關192.168.1.254
3、設定連接配接端口IP
Router1(Config)#fastEthernet 0/1
Router1(Config-if)#switchport address 192.168.4.2 255.255.255.0
Router1(Config-if)#no shutdown
Router1(Config-if)#exit
4、配置路由表
Router1(Config)#ip route 192.168.1.0 255.255.255.0 192.168.4.1
/*要送到192.168.1.0網段的資料發往192.168.4.1 ip位址
Router1(Config)#ip route 192.168.2.0 255.255.255.0 192.168.4.1
Router1(Config)#ip route 192.168.3.0 255.255.255.0 192.168.4.1
Router1(Config)#ip route 192.168.4.0 255.255.255.0 192.168.4.1
Router1(Config)#exit
Switch#show ip route
/*會看到路由表上已經更新:
PS:
這裡使用的時靜态路由~~但是本人推薦用動态路由~這裡隻是因為需要設定的IP段比較少是以才選用靜态路由設定
但是一般情況下是不會選擇靜态路由的,特别是IP段特别多得時候,不然設定很麻煩~是以推薦使用動态路由!指令如下
Router1(Config)#router rip
Router1(Config-router)#network x.x.x.x /* x.x.x.x為位址段~~如192.168.1.0
5、開啟DHCP服務
Router1(Config)#Service Dhcp
Router1(Config)#ip dhcp relay information option
/*這個指令現在很少使用了,個人感覺可有可無,因為已經
設定helper-address了(下面的三層交換機裡設定),但是保險起見打吧- -
第二步:配置三層交換機3560
1、建立VLAN:
Switch>en
Switch#configure terminal
Switch(config)#vlan 2
Switch(config-vlan)#vlan 3
Switch(config-vlan)#exit
2、設定vlan的IP 以及相關參數
Switch(config)#interface vlan 1
Switch(config-if)#ip add 192.168.1.254 255.255.255.0
Switch(config-if)#ip helper-address 192.168.4.2
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#interface vlan 2
Switch(config-if)#ip add 192.168.2.254 255.255.255.0 //IP位址要和DHCP設定子網的網關一樣,
Switch(config-if)#ip helper-address 192.168.4.2 否則PC無法擷取IP位址且無法通信
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#interface vlan 3
Switch(config-if)#ip address 192.168.3.254 255.255.255.0
Switch(config-if)#ip helper-address 192.168.4.2 //此處為設定指定dhcp伺服器的位址,
Switch(config-if)#no shutdown 表示通過Ethernet0向該伺服器發送DHCP請求包
3、設定各個連接配接端口參數
Switch(Config)#Interface fastEthernet 0/4
Switch(Config)#switchport trunk encapsulation dot1q //二層交換機和三層不一樣,必須先設定資料封裝格式
Switch(Config)#switchport mode trunk //對應二層交換機,形成trunk口實作多vlan通信
Switch(Config)#Interface fastEthernet 0/1
Switch(config-if)#no switchport //使端口開啟三層功能,可以了解為變成路由端口
Switch(config-if)#ip address 192.168.4.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#ip routing //開啟路由功能
4、設定路由表
Switch(Config)#router rip //進入動态路由模式
Switch(Config-router)#network 192.168.1.0 //自動學習 192.168.1.0網段位址
Switch(Config-router)#network 192.168.2.0 //同上
Switch(Config-router)#network 192.168.3.0
Switch(Config-router)#network 192.168.4.0
Switch(Config-router)#exit
/*配置動态路由後,記得要在特權模式下檢視路由表,確定要學的IP位址都已學到
第三步:配置二層交換機2950
1、建立VLAN:
Switch1>en
Switch1#configure terminal
Switch1(config)#vlan 2
Switch1(config-vlan)#vlan 3
Switch1(config-vlan)#exit
2、設定端口全局參數
Switch1(Config)#Interface Range fastEthernet 0/1 - 3
/*注意:哪些端口連接配接PC就設定哪個端口,如果設定的端口是連接配接交換機或者路由的就有可能造成環路
Switch1(Config-if-range)#switchport mode access
/*此處把端口設成為portfast模式~即不在不再使用STP的算法,也就是說端口從堵塞直接變為轉發
3、将端口添加到VLAN2,3中(PS:所有端口預設VLAN1~~這個都知道吧~~)
Switch1(Config)#interface fastethernet 0/2
Switch1(Config)#switchport access Vlan 2
Switch1(Config)interface fastethernet 0/3
Switch1(Config-if-range)#switchport access vlan 3
4、将F0/4端口設成trunk模式
Switch1(Config)#interface fastethernet 0/4
Switch1(Config)#switchport mode trunk