Introduction

From Wikipedia:

The Dynamic Host Configuration Protocol (DHCP) is an auto configuration protocol used on IP networks. Computers that are connected to IP networks must be configured before they can communicate with other computers on the network. DHCP allows a computer to be configured automatically, eliminating the need for intervention by a network administrator. It also provides a central database for keeping track of computers that have been connected to the network. This prevents two computers from accidentally being configured with the same IP address.

It is really easy to install and configure a DHCP server:

We will cover here the installation and configuration for Slackware, Arch Linux and Debian / Ubuntu

Install the software

You should be able to install it using your package manager:

For Debian

apt-get install dhcp3-server

For CentOS

yum install dhcp

For Slackware

slackpkg install dhcp

For Arch Linux

pacman -Sy dhcp

Configure DHCP server

Now that you have DHCP installed, you need to be sure it is going to run every time you boot up your server.

Debian / Ubuntu

sysv-rc-conf dhcp3-server on

CentOS / Fedora

chkconfig dhcpd on

Slackware Linux

chmod +x /etc/rc.d/rc.dhcpd

If that file does not exists in your Slackware server, you will have to create one:

Just use your favorite text editor, to create the file /etc/rc.d/rc.dhcpd with this contents.

#!/bin/sh
#
# /etc/rc.d/rc.dhcpd
#      This shell script takes care of starting and stopping
#      the ISC DHCPD service
#

# Put the command line options here that you want to pass to dhcpd:
DHCPD_OPTIONS="-q eth0"

[ -x /usr/sbin/dhcpd ] || exit 0

[ -f /etc/dhcpd.conf ] || exit 0

start() {
      # Start daemons.
      echo -n "Starting dhcpd:  /usr/sbin/dhcpd $DHCPD_OPTIONS "
      /usr/sbin/dhcpd $DHCPD_OPTIONS
      echo
}
stop() {
      # Stop daemons.
      echo -n "Shutting down dhcpd: "
      killall -TERM dhcpd
      echo
}
status() {
  PIDS=$(pidof dhcpd)
  if [ "$PIDS" == "" ]; then
    echo "dhcpd is not running!"
  else
    echo "dhcpd is running at pid(s) ${PIDS}."
  fi
}
restart() {
      stop
      start
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  status)
        status
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        ;;
esac
exit 0

Then apply appropriate permissions

chmod 755 /etc/rc.d/rc.dhcpd

For Arch Linux

Here you just need to add it to the Daemons list in the /etc/rc.conf file.

Configure DHCP server

The configuration file is dhcpd.conf

Here is an example of the file I use in my office.

ddns-update-style none;
ignore client-updates;
authoritative;
option  local-wpad      code    252     =       text;

subnet  10.1.1.0 netmask 255.255.255.0 {

# --- default gateway
      option routers                  10.1.1.1;
# --- Netmask
      option subnet-mask              255.255.255.0;
# --- Broadcast Address
      option broadcast-address        10.1.1.255;
# --- Domain Name, set the domain name for DHCP clients
      option domain-name              "alketech.com";
# --- Domain name servers, tells the clients which DNS servers to use.
      option domain-name-servers      200.87.61.83, 8.8.8.8, 8.8.4.4, 4.2.2.2;
      option time-offset              0;      # Eastern Standard Time
# --- Proxy auto configuration file, tells client browsers which Proxy to use -- See proxy.pac examble below
      option  local-wpad      "http://10.1.1.1/proxy.pac\n";
# --- Sets the ntp server
      option ntp-servers              10.1.1.1:
# --- If you need netbios name server, set it here
#     option netbios-name-servers     10.1.1.1;
# --- Set the range of IPs available for the DHCP to give to clients
      range 10.1.1.100 10.1.1.200;
# --- Set the default lease time, how much time the client is permited to use the given IP. After that the client tries to renew the use of the IP it is already using. Actually before that time has passed.
      default-lease-time 1209600;
# --- Set the maximum lease time, after that time has passed, the client will have to ask for a new IP.
      max-lease-time 1814400;
# If you need any PC to have a fixed IP, let's say the printer server.
       host printer {
           next-server printer.alketech.com;
           hardware ethernet 00:08:a1:82:00:11;
           fixed-address 10.1.1.51;
    }
}

proxy.pac example

   function FindProxyForURL(url, host) {
      // our local URLs from the domains below example.com don't need a proxy:
      if (shExpMatch(url,"*.example.com/*"))                  {return "DIRECT";}
      if (shExpMatch(url, "*.example.com:*/*"))               {return "DIRECT";}

      // URLs within this network are accessed through
      // port 8080 on fastproxy.example.com:
      if (isInNet(host, "10.0.0.0",  "255.255.248.0"))    {
         return "PROXY fastproxy.example.com:8080";
      }

      // All other requests go through port 8080 of proxy.example.com.
      // should that fail to respond, go directly to the WWW:
      return "PROXY proxy.example.com:8080; DIRECT";
   }

Conclusion

DHCP is almost a must in any network configuration, usually your DSL or cable modem has a DHCP server running inside, or your WiFi router may also have one, if you prefer to have your Linux server in charge of this, disable any other DHCP server before starting the Linux one, or you may have IP address conflicts.

There are a lot of other options you can configure, you can haver a backup DHCP server, and you can have your DHCP server working together with a DNS server, so you can assign a name in your domain to any computer connected.

Check, dhcp-options man page and dhcpd.conf man page