DHCP及DHCP中繼的配置

  一、DHCP概述


    DHCP(Dynamic Host Configurationg Protocal,動態主機配置協議)。採用客戶端/服務器(client/server)模式,能夠從預先設置好的DHCP服務器地址池裏動態的爲客戶端分發地址,避免管理員手工指定地址;同時又能保證IP地址不重複分配,且能及時回收提高利用率。


二、DHCP的工作原理

    

    1、客戶端:客戶機向當前子網發送discover廣播報文,向服務器請求一個IP地址。

    2、服務器:服務器收到discover報文後會通過廣播offer報文向客戶端提供一個沒有分配                出去的IP地址,並將這個IP地址標記爲不可用。

    3、客戶端:客戶端收到offer報文後,會向服務器發送request報文,請求使用該地址。

    4、服務器:服務器收到request報文後,向客戶端發送包含原先分配的IP地址和分配方案的ack報文

  


三、DHCP的配置


wKioL1ZifWehiP7MAACc3j8Ilvw968.jpg

    讓R2和PC通過DHCP自動獲取IP地址:


  DHCP服務器:

    DHCP(config)#interface f0/0

    DHCP(config-if)#ip address 172.16.30.1 255.255.255.0

    DHCP(config-if)#no shutdown

    DHCP#configure terminal

    DHCP(config)#service dhcp                       //開啓DHCP服務

    DHCP(config)#no ip dhcp conflict logging        //關閉DHCP衝突日誌

    DHCP(config)#ip dhcp pool ccie                  //定義DHCP地址池名字爲ccie

    DHCP(dhcp-config)#network 172.16.30.0 /24       //定義地址池

    DHCP(dhcp-config)#domain-name cisco.com         //定義域名cisco.com

    DHCP(dhcp-config)#default-router 172.16.30.1    //指定默認網關

    DHCP(dhcp-config)#lease infinite                //定義租約時間

    DHCP(dhcp-config)#dns-server 172.16.30.2        //指定DNS服務器地址

    DHCP(dhcp-config)#netbios-name-server 172.16.30.3   //wins服務器地址

    DHCP(dhcp-config)#option 150 ip 172.16.30.4         //TFTP服務器地址

    DHCP(dhcp-config)#exit

    DHCP(config)#ip dhcp excluded-address 172.16.30.1 172.16.30.5  //排除的地址段

  

  客戶端:

    R2(config)#interface f0/0

    R2(config-if)#no shutdown

    R2(config-if)#ip address dhcp

    

  查看是否獲取到了地址:


    R2#show ip interface brief

    

wKioL1ZigkCzoOLDAAB6agRARLg586.jpg


四、DHCP中繼

    當客戶端和DHCP服務器不在同一子網時,路由器會隔離客戶端廣播的discover消息,使DHCP服務器收不到discover消息,在這種情況下客戶端無法通過DHCP服務器獲取地址,這時可以設置DHCP中繼,將客戶端廣播的discover消息通過DHCP中繼轉發到DHCP服務器,實現自動獲取地址。

如下圖所示:當R3和PC想通過DHCP自動獲取地址時,就需要將R2設置爲DHCP中繼。

wKiom1ZijnrQQG-8AADSItkMijo282.jpg

 

    R1#conf t

    R1(config)#interface f0/0

    R1(config-if)#no shutdown

    R1(config-if)#ip address 10.1.1.2 255.255.255.0

    R1(config-if)#exit

    R1(config)#interface f0/1

    R1(config-if)#no shutdown

    R1(config-if)#ip address 12.1.1.1 255.255.255.0

    R1(config-if)#exit

    R1(config)#router rip

    R1(config-router)#no auto-summary

    R1(config-router)#version 2

    R1(config-router)#network 10.1.1.0

    R1(config-router)#network 12.1.1.0


    R2#conf t

    R2(config)#interface f1/0

    R2(config-if)#no shutdown

    R2(config-if)#ip address 12.1.1.2 255.255.255.0

    R2(config-if)#exit

    R2(config)#interface f1/1

    R2(config-if)#no shutdown

    R2(config-if)#ip address 172.16.30.1 255.255.255.0

    R2(config-if)#exit

    R2(config)#router rip

    R2(config-router)#no auto-summary

    R2(config-router)#version 2

    R2(config-router)#network 12.1.1.0

    R2(config-router)#network 172.16.30.0


   DHCP服務器:    

      DHCP(config)#int

      DHCP(config)#interface f0/0

      DHCP(config-if)#no shutdown

      DHCP(config-if)#ip address 10.1.1.1 255.255.255.0

      DHCP(config-if)#exit

      DHCP(config)#router rip

      DHCP(config-router)#no auto-summary

      DHCP(config-router)#version 2

      DHCP(config-router)#network 10.1.1.0

      DHCP(config)#service dhcp                     

      DHCP(config)#no ip dhcp conflict logging        

      DHCP(config)#ip dhcp pool ccie               

      DHCP(dhcp-config)#network 172.16.30.0 /24      

      DHCP(dhcp-config)#domain-name cisco.com       

      DHCP(dhcp-config)#default-router 172.16.30.1    

      DHCP(dhcp-config)#lease infinite                       

      DHCP(dhcp-config)#exit

      DHCP(config)#ip dhcp excluded-address 172.16.30.1 172.16.30.5 

  DHCP中繼:

      R2(config)#interface f1/1

      R2(config-if)#ip helper-address 10.1.1.1    //配置中繼地址


五、DHCP常用命令

    開啓DHCP服務                  server dhcp

    定義DHCP地址池名字            ip dhcp pool

    定義DHCP分配的網絡、掩碼      network 172.16.30.0 /24

    關閉DHCP衝突日誌              no ip dhcp conflict logging

    設置默認網關                  default-router

    設置DNS域名服務器地址         dns-server

    設置域名                      domain-name

    定義DHCP地址租約              lease infinite

    地址池排除地址段              ip dhcp excluded-address

    查看DHCP數據庫                show ip dhcp database

    查看DHCP地址池                show ip dhcp pool

    查看DHCP地址池綁定狀況        show ip dhcp binding

    查看接口信息                  show ip interface

    配置DHCP中繼地址              ip helper-address

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章