Quick HOWTO : Ch08 : Configuring the DHCP Server/zh
文章出处: |
{{#if: | {{{2}}} | http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch08_:_Configuring_the_DHCP_Server }} |
点击翻译: |
English {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/af | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Afrikaans| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/af|Afrikaans]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ar | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|العربية| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ar|العربية]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/az | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|azərbaycanca| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/bcc | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|جهلسری بلوچی| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/bg | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|български| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/bg|български]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/br | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|brezhoneg| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/br|brezhoneg]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ca | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|català| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ca|català]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/cs | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|čeština| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/cs|čeština]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/de | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Deutsch| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/de|Deutsch]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/el | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Ελληνικά| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/es | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|español| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/es|español]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/fa | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|فارسی| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/fa|فارسی]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/fi | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|suomi| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/fi|suomi]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/fr | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|français| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/fr|français]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/gu | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|ગુજરાતી| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/he | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|עברית| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/he|עברית]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/hu | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|magyar| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/hu|magyar]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/id | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Bahasa Indonesia| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/it | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|italiano| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/it|italiano]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ja | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|日本語| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ja|日本語]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ko | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|한국어| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ko|한국어]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ksh | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Ripoarisch| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/mr | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|मराठी| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/mr|मराठी]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ms | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Bahasa Melayu| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/nl | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Nederlands| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/nl|Nederlands]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/no | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|norsk| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/no|norsk]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/oc | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|occitan| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/oc|occitan]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/pl | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|polski| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/pl|polski]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/pt | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|português| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/pt|português]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ro | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|română| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ro|română]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/ru | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|русский| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/ru|русский]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/si | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|සිංහල| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/si|සිංහල]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/sq | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|shqip| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/sq|shqip]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/sr | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|српски / srpski| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/sv | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|svenska| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/sv|svenska]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/th | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|ไทย| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/th|ไทย]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/tr | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Türkçe| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/tr|Türkçe]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/vi | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|Tiếng Việt| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/yue | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|粵語| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/yue|粵語]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/zh | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|中文| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/zh|中文]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/zh-hans | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|中文(简体)| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server | Quick HOWTO : Ch08 : Configuring the DHCP Server | {{#if: | :}}Quick HOWTO : Ch08 : Configuring the DHCP Server/zh}}/zh-hant | • {{#if: Quick HOWTO : Ch08 : Configuring the DHCP Server|中文(繁體)| [[::Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:Quick HOWTO : Ch08 : Configuring the DHCP Server|:Quick HOWTO : Ch08 : Configuring the DHCP Server/zh|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/zh | | {{#ifexist: Quick HOWTO : Ch08 : Configuring the DHCP Server/zh/zh | | {{#ifeq: {{#titleparts:Quick HOWTO : Ch08 : Configuring the DHCP Server/zh|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Quick HOWTO : Ch08 : Configuring the DHCP Server/zh|1|-1|}} | zh | | }}
简介
一般来讲,如果你有一个有线调制解调器或者数字用户线路,你就可以使用家里的电脑获取由你的服务提供商动态分配的IP地址。如果在调制解调器和本地网络之间安装了有线/数字用户线路的路由器,你的电脑很有可能是在启动过程中从路由器获取了IP地址。你也可以选择禁用本地路由器中DHCP服务器的功能,而设置一个Linux机器作为DHCP服务器。
这一章仅包含对一个可以提供IP地址的DHCP服务器的配置指南。关于Linux系统中,DHCP客户端从DHCP服务器端如何获取IP地址的配置可以参考第三章,“Linux Networking”中的Linux网络互联部分。
Download and Install the DHCP Package
Most RedHat and Fedora Linux software products are available in the RPM format. Downloading and installing RPMs aren't hard. If you need a refresher, Chapter 6, "Installing Linux Software", covers how to do this in detail.
When searching for the file, remember that the DHCP server RPM's filename usually starts with the word dhcp followed by a version number like this: dhcp-3.0.1rc14-1.i386.rpm.
Debian Note: With Debian / Ubuntu the package name may include a version number. Use the dpkg --list | grep dhcp
command to get a list of all your dhcp packages and use the output to infer what the DHCP server package name would be. In this case we can guess that the package name should be dhcp3-server
. If you need a DEB package installation refresher you can take a look at Chapter 6, "Installing Linux Software".
root@u-bigboy:/tmp# dpkg --list | grep dhcp ii dhcp3-client 3.0.3-6ubuntu7 DHCP Client ii dhcp3-common 3.0.3-6ubuntu7 Files used by all the dhcp3* packages root@u-bigboy:/tmp#
The /etc/dhcpd.conf File
When DHCP starts, it reads the file /etc/dhcpd.conf. It uses the commands here to configure your network. The standard DHCP RPM package doesn't automatically install a /etc/dhcpd.conf file, but you can find a sample copy of dhcpd.conf in the following directory which you can always use as a guide.
/usr/share/doc/dhcp-<version-number>/dhcpd.conf.sample
You have to copy the sample dhcpd.conf file to the /etc directory and then you'll have to edit it. Here is the command to do the copying for the version 3.0p11 RPM file:
[root@bigboy tmp]# cp /usr/share/doc/dhcp-3.0pl1/dhcpd.conf.sample /etc/dhcpd.conf
Debian Note: With Debian / Ubuntu the configuration file name is /etc/dhcp*/dhcpd.conf
and has the same syntax as that used by Redhat / Fedora.
Here is a quick explanation of the dhcpd.conf file: Most importantly, there must be a subnet section for each interface on your Linux box.
ddns-update-style interim ignore client-updates subnet 192.168.1.0 netmask 255.255.255.0 { # The range of IP addresses the server # will issue to DHCP enabled PC clients # booting up on the network range 192.168.1.201 192.168.1.220; # Set the amount of time in seconds that # a client may keep the IP address default-lease-time 86400; max-lease-time 86400; # Set the default gateway to be used by # the PC clients option routers 192.168.1.1; # Don't forward DHCP requests from this # NIC interface to any other NIC # interfaces option ip-forwarding off; # Set the broadcast address and subnet mask # to be used by the DHCP clients option broadcast-address 192.168.1.255; option subnet-mask 255.255.255.0; # Set the DNS server to be used by the # DHCP clients option domain-name-servers 192.168.1.100; # Set the NTP server to be used by the # DHCP clients option nntp-server 192.168.1.100; # If you specify a WINS server for your Windows clients, # you need to include the following option in the dhcpd.conf file: option netbios-name-servers 192.168.1.100; # You can also assign specific IP addresses based on the clients' # ethernet MAC address as follows (Host's name is "laser-printer": host laser-printer { hardware ethernet 08:00:2b:4c:59:23; fixed-address 192.168.1.222; } } # # List an unused interface here # subnet 192.168.2.0 netmask 255.255.255.0 { }
There are many more options statements you can use to configure DHCP. These include telling the DHCP clients where to go for services such as finger and IRC. Check the dhcp-options man page after you do your install:
[root@bigboy tmp]# man dhcp-options
Note: The host statement seen in the sample dhcpd.conf file can be very useful. Some devices such as network printers default to getting their IP addresses using DHCP, but users need to access them by a fixed IP address to print their documents. This statement can be used to always provide specific IP address to DHCP queries from a predefined a NIC MAC address. This can help to reduce systems administration overhead.
启动DHCP:
1) DHCP的一些旧版本的Fedora/RedHat将无法使用除非已有dhcpd.leases文件。如果没有的话可以用命令 touch /var/lib/dhcp/dhcpd.leases 去创建一个。
[root@bigboy tmp]# touch /var/lib/dhcp/dhcpd.leases
2) Use the chkconfig command to get DHCP configured to start at boot:
[root@bigboy tmp]# chkconfig dhcpd on
With Debian / Ubuntu the equivalent command for the dhcp3-server
package would be:
root@u-bigboy:/tmp# sysv-rc-conf dhcp3-server on
3) Use the service command to instruct the /etc/init.d/dhcpd script to start/stop/restart DHCP after
booting
[root@bigboy tmp]# service dhcpd start
[root@bigboy tmp]# service dhcpd stop [root@bigboy tmp]# service dhcpd restart
With Debian / Ubuntu the equivalent commands would be:
root@u-bigboy:/tmp# /etc/init.d/dhcp*-server start
root@u-bigboy:/tmp# /etc/init.d/dhcp*-server stop root@u-bigboy:/tmp# /etc/init.d/dhcp*-server restart
4) Remember to restart the DHCP process every time you make a change to the conf file for the changes to take effect on the running process. You also can test whether the DHCP process is running with the following command; you should get a response of plain old process ID numbers:
[root@bigboy tmp]# pgrep dhcpd
5) 最后,一定要记得设置你的电脑以使其可以通过DHCP来获得它的IP地址。
address via DHCP.
DHCP Servers with Multiple NICs
When a DHCP configured PC boots, it requests its IP address from the DHCP server. It does this by sending a standardized DHCP broadcast request packet to the DHCP server with a source IP address of 255.255.255.255.
If your DHCP server has more than one interface, you have to add a route for this 255.255.255.255 address so that it knows the interface on which to send the reply; if not, it sends it to the default gateway. (In both of the next two examples, we assume that DHCP requests will be coming in on interface eth0).
Note: More information on adding Linux routes and routing may be found in Chapter 3, "Linux Networking".
Note: You can't run your DHCP sever on multiple interfaces because you can only have one route to network 255.255.255.255. If you try to do it, you'll discover that DHCP serving working on only one interface.
Temporary Solution
You can temporarily add a route to 255.255.255.255 using the route add command as seen below.
[root@bigboy tmp]# route add -host 255.255.255.255 dev eth0
If you want this routing state to be maintained after a reboot, then use the permanent solution that's discussed next.
Permanent Solution
The new Fedora Linux method of adding static routes doesn't seem to support sending traffic out an interface that's not destined for a specific gateway IP address. The DHCP packet destined for address 255.255.255.255 isn't intended to be relayed to a gateway, but it should be sent using the MAC address of the DHCP client in the Ethernet frame.
You have one of two choices. Add the route add command to your /etc/rc.local script, or add an entry like this to your /etc/sysconfig/static-routes file.
# # File /etc/sysconfig/static-routes # eth0 host 255.255.255.255
Note: The /etc/sysconfig/static-routes file is a deprecated feature and Fedora support for it will eventually be removed.
Now that you have configured your server, it's time to take a look at the DHCP clients.
Configuring Linux Clients to Use DHCP
A Linux NIC interface can be configured to obtain its IP address using DHCP with the examples outlined in , "Linux Networking". Please refer to this chapter if you need a quick refresher on how to configure a Linux DHCP client.
Configuring Windows Clients to Use DHCP
Fortunately Windows defaults to using DHCP for all its NIC cards so you don't have to worry about doing any reconfiguration.
Using a Single DHCP Server to Serve Multiple Networks
As stated before, DHCP clients send their requests for IP addresses to a broadcast address which is limited to the local LAN. This would imply that a DHCP server is required on each subnet. Not so. It is possible to configure routers to forward DHCP requests to a DHCP server many hops away. This is done by inserting the IP address of the router's interface on the DHCP client's network into the forwarded packet. To the DHCP server, the non-blank router IP address field takes precedence over the broadcast address and it uses this value to provide a DHCP address that is meaningful to the client. The DHCP server replies with a broadcast packet, and the router, which has kept track of the initial forwarded request, forwards it back towards the client. You can configure this feature on Cisco devices by using the ip helper-address command on all the interfaces on which DHCP clients reside. Here is a configuration sample that points to a DHCP server with the IP address 192.168.36.25:
interface FastEthernet 2/1 ip address 192.168.1.30 255.255.255.0 ip helper-address 192.168.36.25
Simple DHCP Troubleshooting
The most common problems with DHCP usually aren't related to the server; after the server is configured correctly there is no need to change any settings and it therefore runs reliably. The problems usually occur at the DHCP client's end for a variety of reasons. The following sections present simple troubleshooting steps that you can go through to ensure that DHCP is working correctly on your network.
DHCP Clients Obtaining 169.254.0.0 Addresses
Whenever Microsoft DHCP clients are unable to contact their DHCP server they default to selecting their own IP address from the 169.254.0.0 network until the DHCP server becomes available again. This is frequently referred to as Automatic Private IP Addressing (APIPA). Here are some steps you can go through to resolve the problem:
- Ensure that your DHCP server is configured correctly and use the pgrep command discussed earlier to make sure the DHCP process is running. Pay special attention to your 255.255.255.255 route, especially if your DHCP server has multiple interfaces.
- Give your DHCP client a static IP address from the same range that the DHCP server is supposed to provide. See whether you can ping the DHCP server. If you cannot, double-check your cabling and your NIC cards.
- DHCP uses the BOOTP protocol for its communication between the client and server. Make sure there are no firewalls blocking this traffic. DHCP servers expect requests on UDP port 67 and the DHCP clients expect responses on UDP port 68. Use
tcpdump
on the server's NIC to verify the correct traffic flows.
== == ==
DHCP的其它错误
如果你的DHCP服务器无法启动,可以使用第四章所描述的查错纠错技术,“常见网络错误及其解决方法”,来帮助纠正错误。 Most problems with an initial setup are often due to:
- Incorrect settings in the /etc/dhcpd.conf file such as not defining the networks for which the DHCP server is responsible;
- Firewall rules that block the DHCP bootp protocol on UDP ports 67 and 68;
- Routers failing to forward the bootp packets to the DHCP server when the clients reside on a separate network.
经常地查看/var/logs/messages文件以确定是否有DHCP错误发生,同时记得当你升级操作系统的时候寄存在配置文件里的关键字可能改变。经常检阅版本发布通知以确保关键字没有改变。
总结
大多数的家庭网络,一个CHCP server 是没有必要的,因为
DSL router / firewall一般都有DHCP的功能,但是出于兴趣也可以尝试一下。务必确保一个网络的所有DHCP servers 发行的IP地址不要重复,否则将有可能导致不可预料的错误。 You might want to disable the router/firewall's DHCP server capabilities to experiment with your new Linux server.
A DHCP server may be invaluable in an office environment where the time and cost of getting a network engineer to get the work done may make it simpler for Linux systems administrators to do it by themselves.
Creating a Linux DHCP server is straightforward and touches all the major themes in the previous chapters. 现在是时候尝试一些比较有难度的操作了,不过在开始之前,我们将快速地
复习一下怎样创建将使用本书馀下部分介绍的许多功能的用户的方法。