歡迎您光臨本站 註冊首頁

Linux系統上DHCP伺服器的配置 .

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

Linux系統上DHCP伺服器的配置 .

Linux系統上DHCP伺服器的配置 .

一、DHCP的工作流程

(1) DHCP伺服器發現階段。DHCP客戶機向廣播地址255.255.255.255發送DHCPDiscover消息。

(2) DHCP伺服器響應階段。DHCP伺服器從尚未出租的IP地址池中選擇一個分配給DHCP客戶機,向DHCP客戶機發送一個包含出租的IP地址和其他設置的DHCPoffer提供信息。

(3) IP地址選擇階段。DHCP客戶機選擇某個DHCP伺服器提供的IP地址,以廣播方式回答一個DHCPrequest請求信息.

(4) IP地址確認階段。伺服器回應包含它所提供的IP地址和其他設置的DHCPack確認信息。然後客戶機將其與TCP/IP協議與網卡綁定。

(5) 客戶機重新登錄。再次發送前次分配的IP地址的DHCPRequest請求請求信息,DHCP伺服器檢查是否可以繼續讓客戶機使用,然後發回DHCPack確認信息或者DHCPnck否認信息。如果IP已不能用,客戶機需從(1)開始重新申請。

(6) 更新租約。IP地址租借期限到了,如果DHCP客戶機要延長其租約,必須更新。DHCP客戶機啟動時和IP租約期限過一半時,都會向伺服器發送更新期IP租約的信息。




二、DHCP伺服器配置文件

路徑在/etc/dhcp/dhcpd.conf。下面是一個配置文件的例子:view plaincopy to clipboardprint?
01.# dhcpd.conf  
02.#  
03.# Sample configuration file for ISC dhcpd  
04.#  
05.  
06.# option definitions common to all supported networks...  
07.option domain-name "example.org";  
08.option domain-name-servers ns1.example.org, ns2.example.org;  
09.  
10.default-lease-time 600;  
11.max-lease-time 7200;  
12.  
13.# Use this to enble / disable dynamic dns updates globally.  
14.#ddns-update-style none;  
15.  
16.# If this DHCP server is the official DHCP server for the local  
17.# network, the authoritative directive should be uncommented.  
18.#authoritative;  
19.  
20.# Use this to send dhcp log messages to a different log file (you also  
21.# have to hack syslog.conf to complete the redirection).  
22.log-facility local7;  
23.  
24.# No service will be given on this subnet, but declaring it helps the   
25.# DHCP server to understand the network topology.  
26.  
27.subnet 10.152.187.0 netmask 255.255.255.0 {  
28.}  
29.  
30.# This is a very basic subnet declaration.  
31.  
32.subnet 10.254.239.0 netmask 255.255.255.224 {  
33.  range 10.254.239.10 10.254.239.20;  
34.  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;  
35.}  
36.  
37.# This declaration allows BOOTP clients to get dynamic addresses,  
38.# which we don't really recommend.  
39.  
40.subnet 10.254.239.32 netmask 255.255.255.224 {  
41.  range dynamic-bootp 10.254.239.40 10.254.239.60;  
42.  option broadcast-address 10.254.239.31;  
43.  option routers rtr-239-32-1.example.org;  
44.}  
45.  
46.# A slightly different configuration for an internal subnet.  
47.subnet 10.5.5.0 netmask 255.255.255.224 {  
48.  range 10.5.5.26 10.5.5.30;  
49.  option domain-name-servers ns1.internal.example.org;  
50.  option domain-name "internal.example.org";  
51.  option routers 10.5.5.1;  
52.  option broadcast-address 10.5.5.31;  
53.  default-lease-time 600;  
54.  max-lease-time 7200;  
55.}  
56.  
57.# Hosts which require special configuration options can be listed in  
58.# host statements.   If no address is specified, the address will be  
59.# allocated dynamically (if possible), but the host-specific information  
60.# will still come from the host declaration.  
61.  
62.host passacaglia {  
63.  hardware ethernet 0:0:c0:5d:bd:95;  
64.  filename "vmunix.passacaglia";  
65.  server-name "toccata.fugue.com";  
66.}  
67.  
68.# Fixed IP addresses can also be specified for hosts.   These addresses  
69.# should not also be listed as being available for dynamic assignment.  
70.# Hosts for which fixed IP addresses have been specified can boot using  
71.# BOOTP or DHCP.   Hosts for which no fixed address is specified can only  
72.# be booted with DHCP, unless there is an address range on the subnet  
73.# to which a BOOTP client is connected which has the dynamic-bootp flag  
74.# set.  
75.host fantasia {  
76.  hardware ethernet 08:00:07:26:c0:a5;  
77.  fixed-address fantasia.fugue.com;  
78.}  
79.  
80.# You can declare a class of clients and then do address allocation  
81.# based on that.   The example below shows a case where all clients  
82.# in a certain class get addresses on the 10.17.224/24 subnet, and all  
83.# other clients get addresses on the 10.0.29/24 subnet.  
84.  
85.class "foo" {  
86.  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";  
87.}  
88.  
89.shared-network 224-29 {  
90.  subnet 10.17.224.0 netmask 255.255.255.0 {  
91.    option routers rtr-224.example.org;  
92.  }  
93.  subnet 10.0.29.0 netmask 255.255.255.0 {  
94.    option routers rtr-29.example.org;  
95.  }  
96.  pool {  
97.    allow members of "foo";  
98.    range 10.17.224.10 10.17.224.250;  
99.  }  
100.  pool {  
101.    deny members of "foo";  
102.    range 10.0.29.10 10.0.29.230;  
103.  }  
104.}  
105.
  
# 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 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

subnet 10.152.187.0 netmask 255.255.255.0 {
}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
  range 10.5.5.26 10.5.5.30;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.31;
  default-lease-time 600;
  max-lease-time 7200;
}

# 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 0:0:c0:5d:bd:95;
  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;
}

# 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 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

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

shared-network 224-29 {
  subnet 10.17.224.0 netmask 255.255.255.0 {
    option routers rtr-224.example.org;
  }
  subnet 10.0.29.0 netmask 255.255.255.0 {
    option routers rtr-29.example.org;
  }
  pool {
    allow members of "foo";
    range 10.17.224.10 10.17.224.250;
  }
  pool {
    deny members of "foo";
    range 10.0.29.10 10.0.29.230;
  }
}
DHCP配置文件通常包括3部分:declarations, parameters, options。
declarations:描述網路的布局;描述客戶;提供客戶的地址。

parameters:表明如何執行任務,是否要執行任務,或將哪些網路配置選項發送給客戶。

option:配置DHCP可選參數。

常用聲明:

shared-network 告知DHCP伺服器是否為一些子網路分享相同網路

subnet 描述一個IP是否屬於子網

range 提供動態分配IP地址的起始和結束範圍

host 為特定的主機提供網路參數

group 為一組參數提供聲明

常用參數:

ddns-update-style 配置DHCP-DNS互動更新模式

default-lease-time 指定默認租賃時間的長度,單位為秒

max-lease-time 指定最大租賃時間長度,單位為秒

hardware 指定網卡介面類型和MAC地址

server-name 告知DHCP客戶伺服器名稱

fixed-address 為客戶端指定一個固定的IP地址

常用選項:

domain-name 為客戶端指定域名

domain-name-servers為客戶端指明DNS伺服器IP地址

host-name 為客戶端指明主機名稱

routers 為客戶端指明默認網關

broadcast-address 為客戶端設定廣播地址

subnet-mask 為客戶端設定子網掩碼

ntp-server 為客戶端設定格林威治時間的偏移時間,單位為秒




下面是一個DHCPv6的配置文件的例子:view plaincopy to clipboardprint?
01.# Server configuration file example for DHCPv6  
02.# From the file used for TAHI tests.  
03.  
04.# IPv6 address valid lifetime  
05.#  (at the end the address is no longer usable by the client)  
06.#  (set to 30 days, the usual IPv6 default)  
07.default-lease-time 2592000;  
08.  
09.# IPv6 address preferred lifetime  
10.#  (at the end the address is deprecated, i.e., the client should use  
11.#   other addresses for new connections)  
12.#  (set to 7 days, the  usual IPv6 default)  
13.preferred-lifetime 604800;  
14.  
15.# T1, the delay before Renew  
16.#  (default is 1/2 preferred lifetime)  
17.#  (set to 1 hour)  
18.option dhcp-renewal-time 3600;  
19.  
20.# T2, the delay before Rebind (if Renews failed)  
21.#  (default is 3/4 preferred lifetime)  
22.#  (set to 2 hours)  
23.option dhcp-rebinding-time 7200;  
24.  
25.# Enable RFC 5007 support (same than for DHCPv4)  
26.allow leasequery;  
27.  
28.# Global definitions for name server address(es) and domain search list  
29.option dhcp6.name-servers 3ffe:501:ffff:100:200:ff:fe00:3f3e;  
30.option dhcp6.domain-search "test.example.com","example.com";  
31.  
32.# Set preference to 255 (maximum) in order to avoid waiting for  
33.# additional servers when there is only one  
34.##option dhcp6.preference 255;  
35.  
36.# Server side command to enable rapid-commit (2 packet exchange)  
37.##option dhcp6.rapid-commit;  
38.  
39.# The delay before information-request refresh  
40.#  (minimum is 10 minutes, maximum one day, default is to not refresh)  
41.#  (set to 6 hours)  
42.option dhcp6.info-refresh-time 21600;  
43.  
44.# The path of the lease file  
45.dhcpv6-lease-file-name "/usr/local/var/db/dhcpd6.leases";  
46.  
47.# Static definition (must be global)  
48.host myclient {  
49.    # The entry is looked up by this  
50.    host-identifier option  
51.        dhcp6.client-id 00:01:00:01:00:04:93:e0:00:00:00:00:a2:a2;  
52.  
53.    # A fixed address  
54.    fixed-address6 3ffe:501:ffff:100::1234;  
55.  
56.    # A fixed prefix  
57.    fixed-prefix6 3ffe:501:ffff:101::/64;  
58.  
59.    # Override of the global definitions,  
60.    # works only when a resource (address or prefix) is assigned  
61.    option dhcp6.name-servers 3ffe:501:ffff:100:200:ff:fe00:4f4e;  
62.  
63.    # For debug (to see when the entry statements are executed)  
64.    #  (log "sol" when a matching Solicitation is received)  
65.    ##if packet(0,1) = 1 { log(debug,"sol"); }  
66.}  
67.  
68.# The subnet where the server is attached  
69.#  (i.e., the server has an address in this subnet)  
70.subnet6 3ffe:501:ffff:100::/64 {  
71.    # Two addresses available to clients  
72.    #  (the third client should get NoAddrsAvail)  
73.    range6 3ffe:501:ffff:100::10 3ffe:501:ffff:100::11;  
74.  
75.    # Use the whole /64 prefix for temporary addresses  
76.    #  (i.e., direct application of RFC 4941)  
77.    range6 3ffe:501:ffff:100:: temporary;  
78.  
79.    # Some /64 prefixes available for Prefix Delegation (RFC 3633)  
80.    prefix6 3ffe:501:ffff:100:: 3ffe:501:ffff:111:: /64;  
81.}  
82.  
83.# A second subnet behind a relay agent  
84.subnet6 3ffe:501:ffff:101::/64 {  
85.    range6 3ffe:501:ffff:101::10 3ffe:501:ffff:101::11;  
86.  
87.    # Override of the global definitions,  
88.    # works only when a resource (address or prefix) is assigned  
89.    option dhcp6.name-servers 3ffe:501:ffff:101:200:ff:fe00:3f3e;  
90.  
91.}  
92.  
93.# A third subnet behind a relay agent chain  
94.subnet6 3ffe:501:ffff:102::/64 {  
95.    range6 3ffe:501:ffff:102::10 3ffe:501:ffff:102::11;  
96.}  
《解決方案》

不錯的文章。呵呵。
《解決方案》

http://redking.blog.51cto.com/27212/127548

[火星人 ] Linux系統上DHCP伺服器的配置 .已經有968次圍觀

http://coctec.com/docs/service/show-post-1604.html