Translation(s): Deutsch - English - Français - Italiano - 简体中文 - Português (Brasil) - Русский

(!) ?Discussion

/!\ ToDo: Note that this page is out of date. ISC has deprecated the ISC DHCP suite and suggests using Kea as a replacement. This page should be updated to reflect that.

Introduction

When you set up a Local Area Network (LAN), a client needs to have certain information, such as the IP-address of its interface, the IP-address of at least one domain name server, and the IP-address of a server in the LAN that serves as a router to the internet. In the manual setup you have to type in this information for each client anew. With the Dynamic Host Configuration Protocol (DHCP) the computers can do that automatically for you. This is particularly convenient for connecting laptops to the network.

For a simple configuration of your network you can set up one computer (e.g. the one connected to the internet) as a DHCP server and each of the other computers as a DHCP_Client.

Installation

Install the isc-dhcp-server package.

Configuration

First you should edit or create the file /etc/default/isc-dhcp-server with root permissions, either by running dpkg-reconfigure isc-dhcp-server or enter something like this into the file /etc/default/isc-dhcp-server:

INTERFACES="eth0"

The main configuration file for a dhcp-server is /etc/dhcp/dhcpd.conf. Remember to make a backup copy of it before you edit the file.

Basic configuration

For a basic configuration, you have to add/edit the following lines in /etc/dhcp/dhcpd.conf. I would leave all other lines as they are.

option domain-name "spices.org";

This entry provides the name of the domain, spices.org in this case (I am not sure whether and for what this is necessary. I guess it is needed if you want to refer to computers in the LAN by name without domain name, i.e. if you want to refer to computer pepper.spices.org just with pepper.).

option domain-name-servers 213.191.92.86, 213.191.74.18;

This entry provides the IP-addresses of two domain name servers (DNS), but one would be sufficient, too. You have to list here the DNS that work for your internet provider, the addresses given here will most likely not work for you.

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.1 192.168.1.10;
  option routers pepper.spices.org;
}

This entry defines the LAN and the router of the LAN. The IP-addresses 192.168.1.1 to 192.168.1.255 are typical for an intranet. Here only the range 192.168.1.1 to 192.168.1.10 are permitted. pepper.spices.org is in this case the server connected to the internet that serves as a router.

To make your changes effective you have to restart the DHCP daemon. Run as root

root# service isc-dhcp-server restart

Advanced configuration

Assign fixed addresses

To assign a fixed address, e.g. 192.168.1.5, to a particular machine, e.g. cinnamon, add a statement like the following to the configuration file.

host cinnamon {
  hardware ethernet 00:0D:87:B3:AE:A6;
  fixed-address 192.168.1.5;
}

The cryptic number 00:0D:87:B3:AE:A6 is the hardware address of the interface of cinnamon. It identifies the client to the server. You can get it by running the ifconfig command on the client if the interface is up.

The name (cinnamon) given here is pretty arbitrary at this point and not used for anything yet, as far as I can tell.

More information

Consult the manual pages for advanced options.

user> man dhcpd.conf 

Starting the DHCP server

You can test your DHCP server without rebooting:

sudo service isc-dhcp-server stop
sudo service isc-dhcp-server start
sudo ifdown eth0
sudo ifup eth0

To see your DHCP server error messages, or see when a device has grabbed an IP from this DHCP server:

sudo tail /var/log/syslog

To see if your DHCP server daemon is running:

ps ax | grep dhcpd

Example of a simple DHCP server

If you want your computer to be the DHCP server of an ethernet network, using the IP address 192.168.1.100 for your computer and 192.168.1.101 or higher for the other computers, you can use these configuration settings:

Contents of "/etc/network/interfaces":

# The loopback network interface (always required)
auto lo
iface lo inet loopback

# Assign a static IP for this DHCP server through eth0:
auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    broadcast 192.168.1.255
    gateway 192.168.1.1

Contents of "/etc/resolv.conf":

# Use Google public DNS server:
nameserver 8.8.8.8
nameserver 8.8.4.4
# (or use faster values that your internet provider gave you!)

Contents of "/etc/dhcp/dhcpd.conf:

option domain-name "mydebian";
# Use Google public DNS server (or use faster values that your internet provider gave you!):
option domain-name-servers 8.8.8.8, 8.8.4.4;
# Set up our desired subnet:
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.101 192.168.1.254;
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.1.255;
    option routers 192.168.1.100;
    option domain-name-servers home;
}
default-lease-time 600;
max-lease-time 7200;
# Show that we want to be the only DHCP server in this network:
authoritative;

After running the DHCP server (as mentioned above, or by rebooting), you should be able to attach your other devices to the network and they should automatically be assigned DHCP addresses. To make sure a computer is configured to get its IP address using DHCP, put this into "/etc/network/interfaces":

# The loopback network interface (always required)
auto lo
iface lo inet loopback

# Get our IP address from any DHCP server
auto eth0
iface eth0 inet dhcp

(Or do the equivalent using Network Manager or whatever that device is using to configure its network)


CategoryNetwork CategorySoftware CategorySystemAdministration