天天看點

RHEL6 上DHCP 伺服器的搭建

  1. 基礎知識:

    a. 端口号: 伺服器上68, 客戶機上67

    b. 擷取位址的過程

    RHEL6 上DHCP 伺服器的搭建

    簡單描述:

    1. 客戶機在區域網路内放松一個廣播包,說我要一個dhcp伺服器我要位址。

    2. 可能有一個或者多個dhcp伺服器說,我有我給你。但是客戶機隻需要積極的那個,是以他認同了他收到一個offer包

    3. 然後就是想伺服器發送請求我要一個IP了。

    4. 伺服器絲毫不吝啬的給了他,但是這是有期限的(租約),這個期限是看伺服器上是怎麼配置的。

    5. 注:一般租約期限到了50% 用戶端或繼續請求續租(renew)。正常情況下dhcp伺服器是會同意的。但是伺服器突然不見了,到了租約期限的85%,客戶機還會再次請求一次。要是還沒有,那用完就沒了。系統自己給自己劃分到169.254.0.0/24網段。當然伺服器要是一直沒有收到續租資訊。不會直釋放掉這個IP,會等到一定時間再釋放。(這個一定時間在伺服器中配置)。

  2. 伺服器的搭建過程

    過程很簡單, yum install -y dhcp* ,一次性解決依賴問題,把該裝的都裝了。(會裝4個包,但是其實三個包就夠了。)

    然後就是配置了,按照套路來說配置檔案肯定是放在etc中,裡面肯定會有一個叫做dhcp的。事實卻是是這樣的。

    我們進到檔案夾裡面。看到配置檔案 dhcpd.conf。這就太熟悉了。然後打開。他說有模闆在/usr/share/doc/dchp*/dhcp.conf.sa.. 然後就是直接把模闆覆寫掉配置檔案了。然後我們打開了呗覆寫後的dhcp配置檔案。

    注釋和以分号結尾這都不用說了。

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time ;
max-lease-time ;
           

這是配置檔案的上面部分,很簡單的可以看出,放在subnet域外面的就是全局作用。

第一條: 為dhcp設定域

第二條: 設定兩個dns伺服器的位址

第三條: 租約期限

第四條: 租約到期後,沒有收到續租包,伺服器保留ip的最大時間。

注: 這也可以寫到subnet中,下面就描述一下這個域的意思。

# A slightly different configuration for an internal subnet.
subnet  netmask  {
  range  ;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers ;
  option broadcast-address ;
  default-lease-time ;
  max-lease-time ;
}
           

這個是這執行個體中比較完整的配置檔案。 subnet 後面的就是網段和和子網路遮罩 , range 就是配置的配置設定池的範圍。 option routers 就是網關的意思。 (其他全部删除都沒關系,這個配好了重新開機就能運作)

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

host passacaglia {
  hardware ethernet ::c0:d:bd:;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
}
           

給網卡指定配置檔案

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address fantasia.fugue.com;
}
           

為指定的客戶機配置設定固定的ip位址。當然這些要解除安裝subnet中的。做全局沒意思。

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the / subnet, and all
# other clients get addresses on the / subnet.

class "foo" {
  match if substring (option vendor-class-identifier, , ) = "SUNW";
}

shared-network - {
  subnet  netmask  {
    option routers rtr-example.org;
  }
  subnet  netmask  {
    option routers rtr-example.org;
  }
  pool {
    allow members of "foo";
    range  ;
  }
  pool {
    deny members of "foo";
    range  ;
  }
}
           

自定義配置設定規則,然後放到檔案中。 一般來說配置一個符合的隻要一個subnet就行,比如說這樣:

RHEL6 上DHCP 伺服器的搭建

注意: 伺服器的網卡的ip位址一定要跟dhcp伺服器規定的網絡在同一網段。

區域網路中可以有多台dhcp伺服器。使用哪個dhcp伺服器由客戶機決定。

繼續閱讀