This topic is of interest to readers who are desiring their Network Plus certification, or those who just like to tinker with network settings (in a safe and approved environment) and observe the results. In this blog, I will delve into configuring your Linux box as a DHCP server, and then I will show a client obtaining its information from this DHCP server. Let’s get rolling…
First off, I will be working with a machine running the Ubuntu distribution of Linux. I have a client box which is running Windows XP (yes, XP, I just can’t let it go) but the client can be any IP endpoint that supports obtaining its network information via DHCP. Keep in mind that I am not covering every subtle nuance of fine-tuning DHCP on a Linux box, I will just show a basic configuration which will allow DHCP clients to be served. I want to verify that my client is running DHCP and at least attempting to talk to a DHCP server.
This is actually expected behavior, since I haven’t yet configured the Linux box to answer the client requests. But it does verify that the client machine is in the correct state because it tries in vain to contact a DHCP server. So on to the server.
The first thing I want to do on my server box is to configure a static IP address on the interface with which DHCP will be associated. This may already be done on your box, but if not, here is what needs to be done. Type this command:
sudo nano /etc/network/interfaces (sudo allows me to execute this command with elevated privileges.) If you have not executed a command using sudo within the last five minutes (by default) you will be prompted for a password which entitles you to execute the command. I have entered the password, and here is the resulting output:
As you can see, I have set a static IP address of 172.16.1.1 /24 on interface Ethernet 0 (eth0). I placed the ‘#’ symbol in front of the line referencing dhcp, because my interface cannot be both statically set and a dynamic client itself. I saved these changes and exited the editor. However, to get my system to adjust to this change, I must execute this command:
sudo /etc/init.d/networking restart
Once this is done, I can use ifconfig to check status:
So far so good. Now to execute the commands to enable DHCP. Many of my readers are quite likely Cisco people and as such may already be quite comfortable with configuring DHCP on a Cisco router. I have blogged on this topic in the past, and if you want a refresher, go here. While the concept is the same, the commands (and how and where to type them) are different. The first thing that must be done is to tell the box on which interface DHCP will be active. Type the following:
sudo nano /etc/default/dhcp3-server
In my case, I want it all to happen on eth0, so notice the output once I have entered this:
Before I entered eth0, it looked like this INTERFACES=””
Now I save these changes and exit. The next step is to configure the configuration file that dhcp will use to hand out client information. That is done by typing the following command:
sudo nano /etc/dhcp3/dhcpd.conf
Once inside the editor, there is a sequence of commands to type. I scrolled down until the entries ended and then added the needed commands to the end. Here is what that looked like:
Now I save and exit the editor. To force to system to acknowledge the change, execute this command:
sudo /etc/init.d/dhcp3-server restart
Now we go to the XP client, release and renew its IP information, and see if it receives and IP address from the pool we just created.
And there it is! Client has been served. This is a pretty handy config to keep around, especially for building home lab scenarios where you are using Linux machines to practice your networking skills. If you have any suggestions or comments, I would love to hear them!
Until next time…