DHCP Explained: Installing & Configuring A Free DHCP Server [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
Alternatively you can also achieve this via the synaptic package manager. Keep in mind that you might have to enable the universe and mulitverse repositories. (To do so, check the appropriate checkbox inside System > Administration > Software Sources).
Once installed you need to get configuring. Configuring the DHCP server requires editing configuration files and having a decent knowledge of networking won’t hurt either. That said, I will try to walk you through the configuration file and what all you need to change for a basic setup, so follow along:
- 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″.
- Now back up /etc/dhcp3/dhcpd.conf (create a copy) just in case things go wrong.
- Next up, open the file in your favorite text editor. You may require elevated privileges to edit the file so don’t forget to use sudo (or gksudo if using a GUI text editor).
- This is how the file looks like at first:
- We will change a couple of lines. The settings I am about to show you are good enough for a home network. The great thing about DHCP is that it scales very well, so if you are using this to manage a larger network you would need to make some edits to the setup that I am presenting. The file is nicely commented so if you are unsure about what an option does, make sure you read the comment above the line that you are going to edit.
- 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.
- Now search the file and look for a line that reads “A slightly different configuration for an internal subnet“. This is where you specify the settings of your internal subnet. While the file lists only one such section, you can create more if you want to create more than one subnet.
- Uncomment the section once you find it. You now need to change the settings to suit the network that you are configuring. Here is a brief description of what each line does:
subnet 10.5.5.0 netmask 255.255.255.224 – Specifies the subnet all the hosts will belong to. eg if you want to assign IP addresses from the subnet 192.168.0.0 with a mask of 255.255.255.0 you will change the line to subnet 192.168.0.0 netmask 255.255.255.0
range 10.5.5.26 10.5.5.30 specifies a range of IP addresses within the subnet that will be assigned to any machine requesting an address. In our case we can change it to a suitable range 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.