全名是 Dynamic Host Configuration Protocol, 它的主要功能是讓一部機器能夠透過自己的
Ethernet Address 廣播, 向 DHCP server 取得有關 ip, netmask, default gateway,
dns 等設定.
這樣網管人員只要把 DHCP server 設定好, 就可以讓 client machine 透過
DHCP protocol 自動取得 IP 相關的設定, 而不需要去每一部機器上辛苦地做 IP,
netmask, default gateway, dns 等設定
Static vs. Dynamic
當 DHCP server 聽到網路上有 DHCP cilent 發出 broadcast 時, DHCP server
會在它的 database 中找有關這個 cilent 的相關設定值, 並且將其回傳給 cilent.
這個 database 一般來說分為 static 和 dynamic 兩部份
1. static
詳細列出 client 的 Ethernet Address 與相關的 IP, netmask, gateway,dns.. 設定值
2. dynamic
DHCP server 會保留一段 IP 範圍, 當 cilent 的 Ethernet Address 在 Static table 中找不到時, DHCP server 就從這段 IP 範圍中挑一個還沒有人使用的 IP 給這個 cilent.
lease time
考慮 dynamic 發放 IP 的情形, DHCP server 會記住哪個 cilent (根據 Ethernet
Address)曾經來要過 IP, 如果同一個 Client 重覆來要 IP, 就發同一個 IP 給它,
同時這個 IP 也不會發給其它的 client, 以免造成網路上兩個 client 使用相同的
IP.
但是一個 client 很可能在要過 IP後, 接著關機很久, 產生 IP 沒人使用,
而 DHCP server 又不敢之發給其它 client 的情形, 造成 IP address 的浪費
lease time 就是 DHCP server 用來決定一個 IP address 在使用多久之後,
就將這個 IP 回收, 轉發給其它的 Client. DHCP client 必須在 lease time 用完之前,
重新向 DHCP server 要一次 IP, 以免這個 IP 被回收.
DHCP server 會對 lease time 做一個上限設定, DHCP client 在一開始 request
時, 也可以指定它喜歡的 lease time 長度, 不過不能超過上限
BOOTP vs DHCP
DHCP 的前身是 BOOTP (Bootstrap Protocol), 本來是設計用來給無磁碟主機透過網路開機用的 Protocol, 它與 DHCP 最大的不同有
1. 會要求一個 boot file, 用來開機
2. 不支援 Dynamic IP allocation, 也因此 BOOTP client 不知到有關 DHCP
中 lease time 的部份.
由於 BOOTP 與 DHCP 的封包格式極為相似, 因此有的 DHCP server 也支援 BOOTP
protocol, 也能夠回應 BOOTP cilent 的 request, 但是由於 BOOTP cilent 不支援
DHCP 的 lease time option, 因此 DHCP server 在發放 IP 給 BOOTP client 時,
基本上是假設 lease time 無限上, 也就是不回收發給 BOOTP cilent 的 IP.