Linux Services Organization

Our goal, introduce Linux services to the enterprise world.
Contact us in contact@linuxsv.org

Linux Services Organization : Linux DHCP Linux Server

DHCP Dynamic Host Configuration Protocol allows network settings configuration for all clients from a central dhcp server. The dhcp clients request an IP address and other network settings to all dhcp servers listening on the local LAN where the client is connected. The dhcp server leases to the client one IP address based on the client MAC or just from a IP range, then the client accepts the configuration served by the dhcp server and notify it to the dhcp server.

DHCP server

In order to configure a server as dhcp server, the dhcp RPM package must be installed.

# yum install dhcp

The copy the sample configuration file from shared/doc to /etc/dhcpd/dhcpd.conf file.

# cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcpd/dhcpd.conf

Edit the sample config file with your LAN (192.168.1.0/24 in this case) network parameters configuration.

# cat /etc/dhcpd.conf

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

subnet 192.168.1.0 netmask 255.255.255.0 {
     range 192.168.1.100 192.168.1.110;
     option domain-name-servers 192.168.1.1;
     option domain-name "192.168.1.1";
     option routers 192.168.1.1;
     option broadcast-address 192.168.1.255;
     default-lease-time 600;
     max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.

host fantasia {
     hardware ethernet 08:00:07:26:c0:a5;
     fixed-address 192.168.1.200;
}


From this file can be seen that the dhcp server will serve the network configuration for 192.168.1.0/24 LAN providing IPs from the range 192.168.1.100-192.168.1.110. It also will configure the DNS server 192.168.1.1 on /etc/resolv.conf and default gateway on 192.168.1.1 for all clients. It will also reserve the IP 192.168.1.200 to the node with MAC 08:00:07:26:c0:a5 and it will call it fantasia.

Once the dhcp server has been configured the next step is start the service and make sure that it will be started on boot. It will start the dhcp service on the port 67/UDP.

# /etc/init.d/dhcpd start
# chkconfig dhcpd on

DHCP Security

In order to allow dhcp service through a firewall the port 67/UDP must be open on the dhcp server.

-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 67 -j ACCEPT

And the port 68/UDP must be open on the dhcp client.

-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 68 -j ACCEPT

If SElinux is interfering on the dhcpd service on the server, the dhcpd service will be disabled from SElinux protection.

# setsebool -P dhcpd_disable_trans 1

DHCP Client

The dhcp client configuration can be configured at the network device configuration file, /etc/sysconfig/network-script/ifcfg-eth0 for eth0. The following parameters must be used :

BOOTPROTO='dhcp'

The dhcp configuration for a network device as /dev/eth0 can be executed by hand with the dhclient command.

# dhclient eth0

In both cases using ifcfg-eth0 file or through 'dhclient' command the client node broadcast the LAN searching for dhcp configuration from a dhcp server.

Questions

1.- The dhcpd service can be started selectively on each interface using '/etc/init.d/dhcpd start ethx' where ethx is the network interface (true/false).

2.- The dhcpd service can server different network parameters for different LANs (true/false).

3.- The ip leased by the dhcp server are written on /var/lib/dhcpd/dhcpd.leases (true/false).

4.- Which command can be used in order to get an IPv6 address for the eth1 network interface.

5.- Which parameter must be used on the ifcfg-ethx file in order to not actualize the DNS on /etc/resolv.conf on the dhcp client.

Labs

1.- Configure rhel6 as dhcp server for your LAN 192.168.1.0/24 using the IP Range 192.168.1.20-192.168.1.29 . Configure rhel6 (192.168.1.10) as default gateway and DNS server and reserve the IP 192.168.1.30 for node01 with MAC 00:0C:29:E9:F1:75. Configure node01 the network interface with MAC 00:0C:29:E9:F1:75 to obtain the IP via dhcp at boot, verify the booked ip 192.168.1.30 is assigned from rhel6 dhcp server. Obtain a IP from dhcp range for interface eth1.

-- This page is part of Linux Server online tutorial --