Set up a simple DHCP server for a small network - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Server Administration (https://www.linux-noob.com/forums/forum-8.html) +--- Forum: DNS and DHCP (https://www.linux-noob.com/forums/forum-84.html) +--- Thread: Set up a simple DHCP server for a small network (/thread-510.html) |
Set up a simple DHCP server for a small network - hybrid - 2010-02-23 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: Code: 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 192.168.1.64 through 192.168.1.250 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 192.168.1.1. Open the /etc/dhcpd.conf file in your favourite editor, while running as root. Make your file look something like this: Code: # 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: Code: /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: Code: /etc/init.d/dhcpd stop 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: Code: 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. Set up a simple DHCP server for a small network - anyweb - 2010-02-24 great stuff Peter, thanks for sharing :) |