{"id":4152,"date":"2015-10-20T08:39:53","date_gmt":"2015-10-20T13:39:53","guid":{"rendered":"http:\/\/www.poweradmin.com\/blog\/?p=4152"},"modified":"2015-09-29T08:53:58","modified_gmt":"2015-09-29T13:53:58","slug":"how-to-install-and-configure-a-dhcp-server-on-a-linux-machine-part-1","status":"publish","type":"post","link":"https:\/\/www.poweradmin.com\/blog\/how-to-install-and-configure-a-dhcp-server-on-a-linux-machine-part-1\/","title":{"rendered":"How to install and configure a DHCP Server on a Linux machine -Part 1-"},"content":{"rendered":"<p><span style=\"font-family: verdana, geneva, sans-serif;\">Hello dear readers,<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">In today\u2019s article I will show you how to create your Linux DHCP server. <i>DHCP or Dynamic Host Control Protocol <\/i>is a service that provides automatic IP addressing to your network devices. The difference between assigning static IPs and using a DHCP server is that the IP assignment is done without the interference of System Administrators. By using such service you also have a centralized administration point to your whole infrastructure offering an easy way to <i>add\/change or remove an IP address<\/i> from your hosts. Every network parameters can be automatically configured by the DHCP server: <i>IP address, network mask, gateway, DNS servers, WINS server address, etc<\/i>. This service works using the <i>client-server <\/i>model: the server sends messages using 67 (source) and 68 (destination) UDP port numbers while the client uses port 68 as source and port 67 as destination.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">One of the main principles behind this technology is the use of <i>\u201cleased\u201d addresses<\/i>. This means that each client will be able to use a certain IP address only in the allotted time frame. Once an IP address has been assigned to a DHCP client, a <i>lease-time duration is set<\/i>. The client will contact the DHCP server periodically to <i>\u201crenew\u201d<\/i> its IP address. If for whatever reason, the DHCP server does not respond in time, the client will try to contact other DHCP servers by broadcasting a message throughout the network.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Before an IP is assigned to a workstation, several messages are exchanged between the DHCP client and the server. The following picture displays a typical DHCP process:<\/span><\/p>\n<p><a href=\"http:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/dhcp-protocol.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4153 aligncenter\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/dhcp-protocol.jpg\" alt=\"dhcp protocol steps\" width=\"862\" height=\"457\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/dhcp-protocol.jpg 862w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/dhcp-protocol-300x159.jpg 300w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\"><\/a><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">1. The client sends a <b>DISCOVER<\/b> message in which he tries to contact any DHCP server available on the network. This is a broadcast message that uses the UDP port 67 as destination. Unless there is <i>DHCP-Relay<\/i> configured on the network, this message will be blocked from any edge device (a router). This message can contain a desired IP address, the last used IP address and\/or the lease time duration.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">2. The server will respond with an <b>OFFER<\/b> message that contains all the network parameters. This is also a broadcast message that uses the UDP port 68 as destination.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">3. When the client chooses a certain IP configuration, it will send a<b> REQUEST<\/b> message to the DHCP server to inform that the specified IP address has been chosen. This message is received by all DHCP servers and thus, all will know that the client has received its reservation.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">4. The server will then respond with an <b>ACK (Acknowledge)<\/b> message and the network parameters will be sent to the client.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Below you will find other types of DHCP messages that can be exchanged between the client and the server:<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>Decline<\/i><\/b> \u2013 the client will refuse to accept the IP allocation because this network address is used by another workstation<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>NACK<\/i> <\/b>\u2013 this type of message is sent when the server refuses to lease an IP address<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>Inform<\/i><\/b>\u2013 when certain network parameters must be changed, the client will send an inform message to the server<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>Release<\/i> <\/b>\u2013 the client will inform the server that he doesn\u2019t need the reservation anymore<\/span><\/p>\n<h2><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>BASIC NETWORK SETUP<\/i><\/b><\/span><\/h2>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">For this example, I will install the DHCP server on a <i>CentOS machine<\/i>, you can choose whatever distribution you like because the configuration procedure is similar. You\u2019ll need an active Internet connection if you choose to install the DHCP service using the<i> yum<\/i> utility. You can also choose to install the packet from sources, but I will not cover this part right now<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">To configure the network parameters, use either<b><i>ifconfig<\/i><\/b> or<b> <i>ip<\/i><\/b> command, as follows:<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>ifconfig eth0 10.10.10.50 network 255.255.255.0<\/i><\/b><\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>ip address add 10.10.10.50\/24 dev eth0<\/i><\/b><\/span><\/p>\n<p><a href=\"http:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4154 aligncenter\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig.png\" alt=\"ifconfig command\" width=\"717\" height=\"172\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig.png 717w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig-300x72.png 300w\" sizes=\"auto, (max-width: 717px) 100vw, 717px\"><\/a><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">If you need to remove an IP address type<b> <i>ip address del 10.10.10.50\/24 dev eth0<\/i><\/b>or <b><i>ifconfig eth0 delete 10.10.10.50.<\/i><\/b><\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">The default <i>route\/gateway <\/i>address can be configured by typing the following command:<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>route add default gw 10.10.10.1<\/i> o<\/b>r <b><i>ip route add default via 10.10.10.1<\/i><\/b><\/span><\/p>\n<p><a href=\"http:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/route-add.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4155 aligncenter\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/route-add.png\" alt=\"route add default gw\" width=\"704\" height=\"114\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/route-add.png 704w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/route-add-300x49.png 300w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\"><\/a><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Once the network parameters have been configured, we\u2019ll need to<i> enable<\/i> the network interface by typing <b><i>ifconfig eth0 up<\/i><\/b><\/span><\/p>\n<p><a href=\"http:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig-eth-up.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4156 aligncenter\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig-eth-up.png\" alt=\"ifconfig eth0 up\" width=\"621\" height=\"343\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig-eth-up.png 621w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ifconfig-eth-up-300x166.png 300w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\"><\/a><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">To <i>disable<\/i> a network interface, type <b><i>ifconfig eth 0 down<\/i><\/b><\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">We\u2019ll need to add the <i>DNS servers<\/i> used by our DHCP machine. Navigate to <i>\/etc\/resolv.conf <\/i>and edit this file using your favorite editor. Once you\u2019ve opened the file, type in the following:<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>nameserver DNS_SERVER_IP_ADDRESS<\/i> <\/b><\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Add one entry per line for each DNS server\u2019s IP address<\/span><\/p>\n<p><a href=\"http:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/etc-resolv-conf.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4157 aligncenter\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/etc-resolv-conf.png\" alt=\"\/etc\/resolve.conf\" width=\"729\" height=\"415\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/etc-resolv-conf.png 729w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/etc-resolv-conf-300x171.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\"><\/a><\/p>\n<h2><span style=\"font-family: verdana, geneva, sans-serif;\"><b><i>SERVER CONFIGURATION<\/i><\/b><\/span><\/h2>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Now you should be able to ping any website and we are ready to install the DHCP service. There are several things that you\u2019ll need to know before we can proceed with the installation:<\/span><\/p>\n<ul>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">The DHCP service is called <i>dhcpd (DHCP Daemon) <\/i>and once we\u2019ve configured it, we will see this process running on our machine. You can verify if dhcpd is already running on a machine by typing <i>ps \u2013el | grep dhcpd.<\/i><\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">In CentOS distributions, the configuration file is stored under <i>\/etc\/dhcp\/dhcpd.conf<\/i>. We\u2019ll need to modify this file to successfully configure our server. Note that if the installation is made from sources, this file will have to be created manually:<\/span><\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ls-al-grep-dhcp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4158 aligncenter\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ls-al-grep-dhcp.png\" alt=\"ls -al | grep dhcp\" width=\"567\" height=\"208\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ls-al-grep-dhcp.png 567w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/ls-al-grep-dhcp-300x110.png 300w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\"><\/a><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">As you can see from the output, in CentOS, the <i>conf.file<\/i> is empty so we have to enter all the configuration entries manually. An example can be seen in <i>\/usr\/share\/doc\/dhcp*\/dhcpd.conf.sample. <\/i>Once the configuration is finished, we can validate it by using the<b> <i>dhcpd -t<\/i><\/b> command.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">To install the DHCP service, type in<i> <b>yum install dhcp<\/b> <\/i>and wait for the installation to finish. If you don\u2019t know whether your server has this service installed, try to execute the yum install command and you\u2019ll receive the following message:<\/span><\/p>\n<p><a href=\"http:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/yum-install-dhcp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4159 aligncenter\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/yum-install-dhcp.png\" alt=\"yum install dhcp\" width=\"750\" height=\"186\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/yum-install-dhcp.png 750w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2015\/09\/yum-install-dhcp-300x74.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\"><\/a><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">You can also use the <b><i>rpm \u2013qa | grep dhcp<\/i><\/b> command to verify if the rpm package exists on the server.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">After the installation has been successfully completed, it\u2019s time to configure our DHCP server by editing the configuration file. Simply copy the content from <i>\/usr\/share\/doc\/dhcp*\/dhcpd.conf.sample <\/i>to <i>\/etc\/dhcp\/dhcpd.conf<\/i>. To achieve this result, type in <b><i>cat \/usr\/share\/doc\/dhcp*\/dhcpd.conf.sample &gt; \/etc\/dhcp\/dhcpd.conf<\/i><\/b><\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">\u00a0<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">In the next article we\u2019ll customize our DHCP installation and configure our machine to allow IP address lease to our DHCP clients. By now you should have a CentOS server with all the network parameters configured to allow communication with the whole network. Also you should have installed the DHCP package with a sample configuration file. Hope you\u2019ve managed to cover all these steps because they are crucial for our final DHCP deployment. Don\u2019t hesitate to post any questions on this subject and I\u2019ll try to respond as soon as possible. Wish you all the best and stay tuned for the following article!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello dear readers, In today\u2019s article I will show you how to create your Linux DHCP server. DHCP or Dynamic Host Control Protocol is a service that provides automatic IP addressing to your network devices. The difference between assigning static IPs and using a DHCP server is that the IP assignment is done without the [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":4153,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-4152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","category-tech"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/4152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/comments?post=4152"}],"version-history":[{"count":2,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/4152\/revisions"}],"predecessor-version":[{"id":4161,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/4152\/revisions\/4161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media\/4153"}],"wp:attachment":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media?parent=4152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/categories?post=4152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/tags?post=4152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}