Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set up a simple DHCP server for a small network

A while back, an upgrade to the firmware of the router on my local network (which I wanted to apply to enable WPA2 encryption for the wireless connection) starting causing some strange issues with clients connecting to the network with DHCP. They would get addresses which would work, but when the addresses were attempted to be renewed, the DHCP server in the router would refuse and the client would effectively be booted off the network and unable to access anything.


So I decided to set up a DHCP server on my web server machine and switch off the built-in DHCP server on the router. My server would now handle the assignment of addresses, and hopefully not suffer from this annoying bug!


So, here's how to configure a basic DHCP server for a local network with dhcpd on CentOS 5.3. This guide should work for pretty much any distribution, though, just the way you install the dhcpd package may be different and start and stop the server may differ somewhat.


Install dhcpd


First, you need to install the DHCP server package. As root, run:


yum install dhcp


Just one more thing before we get cracking -- make sure that the server where you are installing this DHCP server uses a static IP address. It obviously doesn't make any sense for it to get its IP address from itself. I'm assuming you have a machine here that is designated as a server that is already set up manually to connect to your local network with a static IP address.


Set up the configuration file


You will need to know the local IP address range of your local network and which addresses you want to be assigned via DHCP. If you have some machines that are assigned static IP addresses, make sure these addresses fall outside the scope of your DHCP address range, or you could create conflicts.


In this example, I am going to assign IP addresses from through as DHCP addresses. When a machine comes on to the network, it will be assigned an address in this range by my new DHCP server. The router IP address on this network is


Open the /etc/dhcpd.conf file in your favourite editor, while running as root. Make your file look something like this:


# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample

ddns-update-style none;
ignore client-updates;
# these two options are for allowing clients to tell
# update a DNS server when DHCP clients want a DNS hostname.
# I'm switching this off -- I don't need it and it's out of
# the scope of this tutorial!

option domain-name-servers,;
# place your DNS servers here -- you will probably want to retrieve
# the addresses of the DNS servers you currently use from your router.
# Here I'm using the public DNS servers of the Dyn Internet Guide public
# DNS service. You may prefer your ISP's servers, or OpenDNS or Google Public
# DNS or another service.

default-lease-time 172800; # one day
max-lease-time 604800; # seven days
# you should be fine with these, unless you specifically want to change them!


subnet netmask {
# place your network's IP information here, you should be able to retrieve from
# your router.

range          ;
# the range of addresses to be used by DHCP clients
option routers ;
# the IP of your router, in order to get traffic out to the internet!
option subnet-mask
# again, retrieve from your current settings
option broadcast-address
# usually the last address on your network, again look at your current settings



You will obviously need to substitute into that example file the IP addresses on your network, including the subnet, your desired IP address range for DHCP users, the router and your preferred DNS servers. As the comments say, you should be able to retrieve most of this information from your current network setup; so it will probably be on the pages of your router's configuration web page.


When you have customised that file with your information, save the file and quit your editor. The DHCP server should now be ready for action.


Start the DHCP server and set to run on reboot


Now, stop any existing DHCP server you might have enabled on your router. You will probably have to go to the configuration web page of your router and disable the DHCP server option. Two DHCP servers on the same network will likely conflict unless set up properly to coexist!


Note that while there is no DHCP server on your network, any machine that joins won't be able to get an IP address and therefore will have trouble doing anything. Best do this at a quiet time when no-one is likely to be switching on or restarting their computer or otherwise reconnecting to your network.


Now switch on your new DHCP server if it isn't already. As root:


/etc/init.d/dhcpd start


You may want to use something 'Repair Connection' or a forced network refresh on one of your client computers to test that the new DHCP server is giving out addresses properly. Check the network properties on that machine and you should notice it has an address in the right range. To make sure that your router and DNS server addresses are right, connect to the internet and verify you can access your favourite websites.


If something goes wrong, use:


/etc/init.d/dhcpd stop
chkconfig dhcpd off


to turn off your DHCP server (and prevent it from running again on reboot) and then you can re-enable the router's DHCP server option and be back at square one.


If all seems good and your new DHCP server is giving out the right addresses, you can set dhcpd to run at startup:


chkconfig dhcpd on


From now on, your new DHCP server on Linux will be responsible for dishing out network addresses to clients.


Just remember that this machine where the DHCP server is installed must be switched on in order for the network to function properly. This machine ideally should be left on all the time (or at least all the time that your router is switched on), so that computers on the network can get access to the network properly.


It is also a good idea to know how to configure one of your machines with a static IP address, so that if all else fails, you can log back into the router and switch on its DHCP server option again.

great stuff Peter, thanks for sharing :)

Forum Jump:

Users browsing this thread: 1 Guest(s)