{"id":1498,"date":"2018-11-24T13:21:07","date_gmt":"2018-11-24T10:21:07","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1498"},"modified":"2024-03-11T21:30:39","modified_gmt":"2024-03-11T18:30:39","slug":"setup-dhcp-server-fedora-29-fedora-28-centos-7","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/setup-dhcp-server-fedora-29-fedora-28-centos-7\/","title":{"rendered":"How to Install and Setup DHCP Server on Fedora 29\/Fedora 28\/CentOS 7"},"content":{"rendered":"\n<p>This tutorial discusses how to install and setup DHCP server on Fedora29\/Fedora28\/CentOS 7. Hosts in in a TCP\/IP network utilizes the Dynamic Host Configuration Protocol (DHCP) to automatically learn their IPv4 settings. The DHCP server can allow both permanent and temporary lease of IP addresses to the hosts in a network. Most commonly, the hosts are assigned temporary IP addresses such that whenever they are no longer in a network, the IP addresses that were previously assigned to them will be reclaimed and made available for other hosts.<\/p>\n\n\n\n<div>Although <span class=\"highlight\">DHCP<\/span> works automatically for user hosts, it does require some preparation from<\/div>\n\n\n\n<div>the network, with some configurations on the server.<\/div>\n\n\n\n<div>&nbsp;<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installing DHCP Server<\/h2>\n\n\n\n<div>Install the dhcp server package by running the commands below;<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo dnf install dhcp    <strong>&lt; Fedora<\/strong>\nsudo yum install dhcp    <strong>&lt; <\/strong><strong>Fedora\/CentOS<\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Setup DHCP Server<\/h2>\n\n\n\n<div>The installation of dhcp package creates an empty configuration file under <code>\/etc\/dhcp\/dhcpd.conf<\/code>. The Sample configuration file is located under <code>\/usr\/share\/doc\/dhcp-server\/dhcpd.conf.example<\/code>. Therefore, you can optionally check this sample configuration to guide you on how to set up your dhcp configuration file or you can copy the sample configuration file to <code>\/etc\/dhcp\/dhcpd.conf<\/code> overwriting the existing one and make necessary changes that best suits your network.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo \\cp \/usr\/share\/doc\/dhcp-server\/dhcpd.conf.example \/etc\/dhcp\/dhcpd.conf<\/pre>\n\n\n\n<div>The backslash appended to cp command is ensures non-interactive overwrite.<\/div>\n\n\n\n<div>&nbsp;<\/div>\n\n\n\n<div>\n<div class=\"para\">There are two types of statements in the configuration file:<\/div>\n<div class=\"itemizedlist\">\n<ul>\n<li class=\"listitem\">\n<div class=\"para\"><code>Parameters<\/code> which state how to perform a task, whether to perform a task, or what network configuration options to send to the client.<\/div>\n<\/li>\n<li class=\"listitem\">\n<div class=\"para\"><code>Declarations<\/code> which describe the topology of the network, describe the clients, provide addresses for the clients, or apply a group of parameters to a group of declarations.<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n\n\n\n<div>Open the configuration file for editing and make adjustments as follows;<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vim \/etc\/dhcp\/dhcpd.conf<\/pre>\n\n\n\n<div>Set the domain name;<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"># option definitions common to all supported networks...\n# option domain-name \"example.org\"; <strong>&lt; Comment or edit accordingly<\/strong>\n<strong>option domain-name \"example.com\";<\/strong><\/pre>\n\n\n\n<div>Set the DNS server&#8217;s hostname or IP address;<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"># option domain-name-servers ns1.example.org, ns2.example.org;\n<strong>option domain-name-servers ns1.example.com, ns2.example.com;<\/strong><\/pre>\n\n\n\n<div>Define the default as well as the max lease time. In this case, I will go with the defaults.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>default-lease-time 600;<\/strong>\n<strong>max-lease-time 7200;<\/strong><\/pre>\n\n\n\n<div>Make your DHCP server the official DHCP server for the local network by uncommenting the line shown below.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"># If this DHCP server is the official DHCP server for the local\n# network, the authoritative directive should be uncommented.\n#authoritative;  <strong>&lt; uncomment this line<\/strong>\n<strong>authoritative;<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Subnet Declaration<\/h3>\n\n\n\n<p>In order for the DHCP server to understand the network topology, you need to define DHCP subnet. For example, to configure the DHCP for the <strong>192.168.10.0\/24<\/strong> LAN network, the declaration is defined as shown below;<\/p>\n\n\n\n<p>Note that you can only serve DHCP requests for a subnet for which there is an interface configured in that subnet on the host machine.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">subnet 192.168.43.0 netmask 255.255.255.0 {\n  range 192.168.43.100 192.168.43.200;\n  option domain-name-servers ns1.example.com, ns2.example.com;\n  option domain-name \"example.com\";\n  option routers 192.168.43.1;\n  option broadcast-address 192.168.43.255;\n  option time-offset              -18000;     # Eastern Standard Time\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Host Static IP address Assignment<\/h3>\n\n\n\n<div>To assign an IP address to a client based on the MAC address of the network interface card, use the <code class=\"command\">hardware ethernet<\/code> parameter within a <code class=\"command\">host<\/code> declaration.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">host test {\n   option host-name \"test.com\";\n   hardware ethernet 08:00:27:15:b4:72;\n   fixed-address 192.168.43.155;\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Shared Network Declaration.<\/h3>\n\n\n\n<div>All subnets that share the same physical network should be declared within a <code class=\"command\">shared-network<\/code> declaration. Parameters within the <code class=\"command\">shared-network<\/code>, but outside the enclosed subnet declarations, are considered to be global parameters.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">shared-network test {\n    # global parameters for shared network\n    option domain-search            \"example.com\";\n    option domain-name-servers      ns1.example.com, ns2.example.com;\n    option routers                  192.168.25.2;\n    subnet 192.168.30.0 netmask 255.255.255.0 {\n        #parameters for subnet 192.168.30.0\/24\n        range 192.168.30.1 192.168.30.254;\n    }\n    subnet 192.168.70.0 netmask 255.255.255.0 {\n        #parameters for subnet 192.168.70.0\/24\n        range 192.168.70.1 192.168.70.254;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Group Declaration<\/h3>\n\n\n\n<div>The <code class=\"command\">group<\/code> declaration is used to apply global parameters to a group of declarations.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">group {\n   option routers                  192.168.10.3;\n   option subnet-mask              255.255.255.0;\n   option domain-search              \"example.com\";\n   option domain-name-servers      192.168.10.1;\n   option time-offset              -18000;     # Eastern Standard Time\n   host server01 {\n      option host-name \"srv01.example.com\";\n      hardware ethernet 08:00:27:25:d4:72;\n      fixed-address 192.168.10.27;\n   }\n   host server02 {\n      option host-name \"svr02.example.com\";\n      hardware ethernet 08:00:27:05:b3:52;\n      fixed-address 192.168.10.30;\n   }\n}<\/pre>\n\n\n\n<div>Once you are done making your server configurations, start DHCP server and enable it to run on system boot.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl start dhcpd\nsudo systemctl enable dhcpd<\/pre>\n\n\n\n<div>If Firewalld is running, allow DHCP service. DHCP uses 67\/UDP.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sudofirewall-cmd --add-service=dhcp --permanent\nsudo firewall-cmd --reload<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">DHCP Client Configuration<\/h2>\n\n\n\n<p>Now that your DHCP server is ready to serve out dynamic IP addresses, you can set up the DHCP client to validate all this. In this case am going to test this using Ubuntu 18 for static IP assignment (192.168.43.155) and Fedora 29 server for dynamic IP assignment within the range 192.168.43.100 192.168.43.200 as defined above.<\/p>\n\n\n\n<!--nextpage-->\n\n\n\n<h3 class=\"wp-block-heading\">Ubuntu 18.04 Client<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vim \/etc\/netplan\/01-netcfg.yaml<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"># This file describes the network interfaces available on your system\n# For more information, see netplan(5).\nnetwork:\n  version: 2\n  renderer: networkd\n  ethernets:\n    enp0s3:\n      dhcp4: yes<\/pre>\n\n\n\n<div>Apply the changes and check the IP address.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo netplan apply<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">ip add\n<strong>...<\/strong>\n2: enp0s3: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000\n    link\/ether 08:00:27:15:b4:72 brd ff:ff:ff:ff:ff:ff\n    inet <strong>192.168.43.155\/24<\/strong> brd 192.168.43.255 scope global dynamic enp0s3\n       valid_lft 436sec preferred_lft 436sec\n    inet6 fe80::a00:27ff:fe15:b472\/64 scope link \n       valid_lft forever preferred_lft forever<\/pre>\n\n\n\n<div>&nbsp;<\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Fedora 29 Client<\/h3>\n\n\n\n<div>Set the interface to obtain IP address automatically.<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">nmcli connection modify enp0s8 ipv4.method auto\nnmcli connection down enp0s8\nnmcli connection up enp0s8<\/pre>\n\n\n\n<div>Check the IP address<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">ip add\n<strong>...<\/strong>\n3: enp0s8: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000\n    link\/ether 08:00:27:df:3b:07 brd ff:ff:ff:ff:ff:ff\n    inet <strong>192.168.43.100<\/strong>\/24 brd 192.168.43.255 scope global dynamic noprefixroute enp0s8\n       valid_lft 514sec preferred_lft 514sec\n    inet6 fe80::3725:59fe:44a3:c665\/64 scope link noprefixroute \n       valid_lft forever preferred_lft forever<\/pre>\n\n\n\n<div>Huraay!! You have successfully set up your DHCP server on.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial discusses how to install and setup DHCP server on Fedora29\/Fedora28\/CentOS 7. Hosts in in a TCP\/IP network utilizes the Dynamic Host Configuration Protocol<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,258],"tags":[260,259],"class_list":["post-1498","post","type-post","status-publish","format-standard","hentry","category-howtos","category-dhcp-server","tag-dhclient","tag-dhcp-server","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1498"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1498"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1498\/revisions"}],"predecessor-version":[{"id":21053,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1498\/revisions\/21053"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}