How to Make your Linux Box a DHCP Server

Home > Blogs > Cisco > How to Make your Linux Box a DHCP Server

How to Make your Linux Box a DHCP Server

Like This Blog 0Mark Jacob
Added by March 16, 2015

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.

001-make-your-Linux-box-into-a-DHCP-server

Figure 1

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:

You may also like:  How to Configure your Network Location in Windows 7

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:

002-sud-nano-make-your-Linux-box-into-a-DHCP-server

Figure 2

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:

003-ifconfig-make-your-Linux-box-into-a-DHCP-server

Figure 3

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:

You may also like:  How to OpenWRT and Cucumber your Meraki Access Point

004-modified-ifconfig-make-your-Linux-box-into-a-DHCP-server

Figure 4

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:

005-ifconfig-make-your-Linux-box-into-a-DHCP-server

Figure 5

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.

006-cmnd-prompt-make-your-Linux-box-into-a-DHCP-server

Figure 6

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…

Mark Jacob
Cisco and CompTIA Network + Instructor – Interface Technical Training
Phoenix, AZ

Videos You May Like

Creating Users and Managing Passwords in Microsoft Office 365

0 30 1

In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365.

Detailed Forensic Investigation of Malware Infections – April 21, 2015

1 80 1

In this IT Security training video, Security expert Mike Danseglio (CISSP / CEH) will perform several malware investigations including rootkits, botnets, viruses, and browser toolbars.

Understanding C# Interfaces and Polymorphic Behavior by Dan Wahlin

0 129 0

In this video, I'm going to walk through one of the cool features of C# Interfaces, which is Polymorphic Behavior. It will future-proof your apps.

Write a Comment

Share your thoughts...

Please fill out the comment form below to post a reply.