此篇來談DHCP~Dynamic Host Configuration Protocol
不是只能派發IP/Mask Gateway給dhcpclient的通訊協定
基本上主機的基本相關設定都可以派…~
比方說…dns server指定、主機名稱…哩哩扣扣的一堆東西
首先當一下考古學家 查看一下RFC文件2131
--> 點這兒 <--
當然…相關的DHCP RFC文件不只這冊…這冊是打基本功~
DHCP messages(相關封包類型)
DHCPDISCOVER - Client broadcast to locate available servers.
DHCPOFFER - Server to client in response to DHCPDISCOVER with offer of configuration parameters.
DHCPREQUEST - Client message to servers either
(a) requesting offered parameters from one server and implicitly declining offers from all others,
(b) confirming correctness of previously allocated address after,
e.g., system reboot, or (c) extending the lease on a particular network address.
DHCPACK - Server to client with configuration parameters, including committed network address.
DHCPNAK - Server to client indicating client's notion of network address is incorrect (e.g., client has moved to new subnet) or client's lease as expired.
DHCPDECLINE - Client to server indicating network address is already in use.
DHCPRELEASE - Client to server relinquishing network address and cancelling remaining lease.
DHCPINFORM - Client to server, asking only for local configuration parameters; client already has externally configurednetwork address.
解釋一下…Client送出DhcpDiscover…收到DhcpDiscover的DhcpServer會發出DhcpOffer
圖中兩台Server皆收到DhcpDiscover…故兩台都發出DhcpOffer
接下來由Client發出兩個DhcpRequest(requesting offered parameters from one server and implicitly declining offers from all others)
再由DhcpServer發出DhcpAck此時Client完成設定…等到用戶不再使用時…送出DhcpRelease
當Client要繼續租用該位址時(租約快到期時)也是發出DhcpRequest
一個MAC只能得到一組DHCP設定,虛擬機器走橋接模式則不在此限(因有多個MAC在同一張網卡上)
這兒架構圖…
S1:網卡eth0對外連接Internet,eth1接在Switch/Hub上
S2:網卡eth0接在Switch/Hub,eth1接Client B
A:接在Switch/Hub上
目標實作:
A可以透過S1的DHCP服務,取得相關網路設定
進階目標:
B可以透過S2取得S1的DHCP服務,取得相關網路設定(Dhcp Relay)。
DHCP over IPv6。
多台DHCP Server的用途與管理問題。
開始吧…先看基本的目標實作~
@S1(OpenSuSE 11.1 32Bits,eth1:172.16.0.254)
#zypper install dhcp-server
裝上dhcp-server套件
#vi /etc/sysconfig/dhcpd
約在17行左右修改DHCPD_INTERFACE選項,設定負責進行Listen動作的網路介面
DHCPD_INTERFACE="eth1"
#SuSEconfig
套用sysconfig目錄下的修改
#man 5 dhcpd.conf
查看dhcpd.conf的設定手冊,由dhcp-server套件所提供
區域設定中未指示的則取用部分的gloabal parameters
#vi /etc/dhcpd.conf
加入subnet的設定
subnet 172.16.0.0 netmask 255.255.0.0{ #宣告一網段(記住要用網段的表達方式)
range 172.16.0.1 172.16.0.253; #派發的IP範圍
option subnet-mask 255.255.0.0; #mask設定
option domain-name-servers 168.95.1.1; #派發DNS設定
option routers 172.16.0.254; #派發Gateway設定
}
觀察一下設定檔當中的註解,註解掉不要的東西
#/etc/init.d/dhcpd restart
重新啟動Dhcp Server(Service)
#netstat -lnup | grep 67
檢查是否成功,有成功則會Listen在eth1的UDP 67port上
@A(M$ Windows)
設定網卡為自動取得IP即可…
(注意架構,如果A位於DhcpDiscover封包無法送達S1的位置上,就不行囉)
觀察結果(ip/mask/gw/dns/dns suffix)
c:\>ipconfig /all
比較複雜的留到下篇再來實作~架構圖將在下篇繼續延用~ >.<
留言列表