DHCP configuration in Linux

FOXY🦊KNIGHT
3 min readJul 14, 2023

--

Dynamic Host Control Protocol. DHCP is a networking protocol used to assign IP addresses to networked devices.

There are two ways on how any given host on your network can obtain an IP address.

One way is to manually configure the network interface and assign an IP address by hand. The manual network configuration is called static configuration.

Another way to assign your network hosts with a proper IP address regardless of the actual network size is to assign an IP address to each host automatically. To perform an automatic host’s IP configuration DHCP ( Dynamic Host Configuration Protocol ) is used.

The DHCP protocol lets a DHCP client, that is your network host to lease network configuration parameters such as an IP address. In fact, lease parameters are not limited to IP addresses only as they may also include the following configuration settings:

  • IP addresses and network masks
  • Domain Names servers ( DNS )
  • Default Gateways
  • WINS servers
  • Syslog hosts
  • Proxy servers
  • NTP servers
  • X Font servers

Each network host configured to obtain an IP address dynamically via DHCP will upon boot send a DHCP request over the network ( by definition this is a broadcast of all 1’s ) to discover whether there is a DHCP server available somewhere on the network and consequently ask for a network configuration. DHCP client is then obligated to maintain communication with DHCP server and renew its IP address regularly as dictated by IP address’s lease time expiry. In case that DHCP client fails to renew its IP address ( disconnection, a host is turned off, etc. ) its IP address expires and DHCP server is free to lease this IP address to another DHCP client.

DHCP server keeps a record of all leased IP addresses and stores them in a file called dhcpd.leases within /var/lib/dhcp directory ( location of this file may vary depending on Linux system in use ). Having such a file allows DHCP server to keep track of all IP address leases even after the reboot or power failure.

DHCP Server configuration:

Pre- Configuration

  • DHCP Server
  • DHCP Client machine

DHCP Server Setup:

yum -y install dhcp

Open the /etc/sysconfig/dhcpd file and add the ethernet name argument which configured in your server.

nano /etc/sysconfig/dhcpd

DHCPDARGS=eth0

Configuring DHCP Server in CentOS

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

Open the dhcp configuration file

nano /etc/dhcp/dhcpd.conf

option domain-name “foxy.com”;

option domain-name-servers server1.besant.com, server2.foxy.com;

default-lease-time 3600;

max-lease-time 7200;

authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {

option routers 192.168.1.2;

option subnet-mask 255.255.255.0;

option domain-search “foxy.com”;

option domain-name-servers 192.168.1.1;

range 192.168.1.10 192.168.1.100;

range 192.168.1.120 192.168.1.200;

}

Add the MAC address restriction in specific ip

host new-centos {

hardware ethernet 00:f0:m4:6y:89:0g;

fixed-address 192.168.1.105;

}

save and close

DHCP Client setup:

nano /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=dhcp

TYPE=Ethernet

ONBOOT=yes

save and close the file

NFS and Samba configuration for share the volume

--

--

FOXY🦊KNIGHT
FOXY🦊KNIGHT

Written by FOXY🦊KNIGHT

Developer ➕ Operations = DevOps

No responses yet