DHCP解释:安装和配置免费的DHCP服务器[Linux]

However there is nothing stopping you using such a free DHCP server setup on your home network as well. Another advantage is that all the settings are stored in one place so any changes can be done easily without having to reconfigure all of your computers.


Installing free DHCP server is easy, it is the configuration that takes some time and thought. That said, once you have installed and configured a DHCP server you are saved from all the chores like rotating IP addresses, keeping track of what IPs have been assigned and configuring each computer/device separately etc.

We will be looking at how you can configure a free DHCP server on your Linux computer. As always I will be demonstrating this using my Ubuntu Machine, but you can very well adapt it to be used with any other distribution. First and foremost you need to install a DHCP server on your computer. Doing so is simple, all you need to do is to issue the following command:

sudo apt-get install dhcp3-server

或者,您也可以通过突触包管理器来实现。请记住,您可能必须启用Universe和多版本存储库。 (为此,请在系统>管理>软件源中选中相应的复选框。)

安装完成后,您需要进行配置。配置DHCP服务器需要编辑配置文件,并且具有良好的网络知识也不会受到损害。也就是说,我将尝试引导您完成配置文件以及基本设置所需的全部更改,因此请遵循以下步骤:

  • There are a couple of files we are concerned with. Most of the work will be done with /etc/dhcp3/dhcpd.conf. However first we need to configure which interface the server should monitor for DHCP requests. Open up the file /etc/defaults/dhcp3-server and add the required interface to the INTERFACES=”” line. e.g for eth0, the line will look like INTERFACES=”eth0″.
  • 现在备份 / etc / dhcp3 / dhcpd。 conf (创建副本),以防万一出错。
  • 接下来,在您喜欢的文本编辑器中打开文件。您可能需要提升的权限才能编辑文件,所以不要忘记使用sudo(如果使用GUI文本编辑器,则请使用gksudo)。
  • 文件的开头看起来是这样的:
  • 我们将更改几行。我将要显示的设置对于家庭网络已经足够了。 DHCP的优点在于它可以很好地扩展,因此,如果使用它来管理更大的网络,则需要对我要介绍的设置进行一些编辑。该文件的注释很好,因此,如果不确定选项的作用,请确保已阅读将要编辑的行上方的注释。
  • Go through the file line by line and comment out any line that is not required in your setup. In the first part of the file you can specify domain name, domain name servers and parameters like default and max lease time. The settings you configure in this part of the file will be used for all the sections of the file that don’t mention them explicitly.
  • If instead you are configuring only a single network interface, I recommend you comment out these first lines and configure the domain name and domain name servers in the individual sections.
  • 现在搜索文件并查找一行读取“ 内部子网的配置稍有不同"。在这里您可以指定内部子网的设置。虽然该文件仅列出了一个这样的部分,但是如果您要创建多个子网,则可以创建更多部分。
  • 找到该部分后,请取消注释该部分。现在,您需要更改设置以适合您正在配置的网络。以下是每行的简要说明:
  • 子网10.5.5.0网络掩码255.255.255.224 –指定所有主机将属于的子网。例如,如果您要分配子网掩码为255.255.255.0的子网192.168.0.0的IP地址,则应将该行更改为子网192.168.0.0子网掩码255.255.255.0

    < em> range 10.5.5.26 10.5.5.30 指定子网内的IP地址范围,该范围将分配给请求地址的任何计算机。在我们的情况下,我们可以将其更改为合适的范围192.168.0.10 192.168.0.50

    The other lines are used to configure optional parameters like router address, DNS servers etc. You can specify them here to override the default ones you provided at the start of the file.

    With a little configuration, the DHCP server is ready for work. All you need to do now is to start the server and configure the clients to request IP via DHCP from this server that you configured. As an option you can also use Webmin to configure your DHCP server using a web browser. If you have a router, it can do most things that you want to do with a DHCP server, in such a case you can access the router’s settings panel to specify things like how IP addresses are assigned, DNS servers and the likes.

    Have you ever configured a DHCP server for your home network? Or do you use static IPs? Feel free to contribute your tips in the comments section.

    标签: