Linux Server How To

How To Setup, Configure, Manage and Secure a Linux Server


Linux Server How To - How to Configure DHCPD


A Basic dhcpd.conf

Configuring your Linux DHCP server can be achieved in just a few minutes for most networks with the aid of our example dhcpd.conf files. Lets start by having a look at our example dhcpd.conf included with the tutorials on installing DHCPD using apt-get and compiling DHCPD from source. For brevity each option is explained by the comment above it.

# The Dynamic DNS update style must be defined to avoid errors. Seeing as we dont use it
# because we can make our own DNS server the value is set to none.
ddns-update-style none;

# The next four options are common to all the networks we provide DHCP services to...


# Set the domain name for all clients to example.org
option domain-name "example.org";

# Provide two DNS servers for our clients to use
option domain-name-servers 192.168.10.100, 192.168.10.110;

# Set the default lease time to 600 seconds, after this time the client will
# need to renew its dhcp lease and receive fresh configuration details
default-lease-time 600;

# The maximum lease time, after this all clients must renew their lease.
max-lease-time 7200;

# 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;

# This is a very basic subnet declaration.
# The network is 192.168.10.0/24
# Clients will be issued IP addresses between 192.168.10.150 and 192.168.10.200 inclusive
# The default gateway is 192.168.10.1
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.150 192.168.10.200;
option routers 192.168.10.1;
}

Another Quick Configuration

Here is another quick and easy example dhcpd.conf that you can copy and amend with addresses suitable for your network. Once again the commented sections provide guidance for what everything does.

# The Dynamic DNS update style must be defined to avoid errors. Seeing as we dont use it
# because we can make our own Linux DNS server the value is set to none.
ddns-update-style none;

# The following stanza is a reasonably complete example that would serve most networks well.
# The network is 192.168.1.0/24
# DHCP clients are assigned IP addresses between 192.168.1.10 and 192.168.1.250 inclusive
# Default lease time is 600 seconds and maximum lease time is 7200 seconds
# The subnet mask is 255.255.255.0
# The broadcast address is 192.168.1.255
# The default gateway is 192.168.1.1
# DNS servers assigned to clients on this networks belong to an ISP, 203.26.230.21 and 203.134.64.66
# The domain name provided to clients is linuxserverhowto.com


subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.250;
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
option domain-name-servers 203.26.230.21, 203.134.64.66;
option domain-name "linuxserverhowto.com";
}

Running Your DHCP server on a Different Network to its Clients

If you elect for whatever reasons to assign addresses to your DHCP clients that are on a different network to your DHCP server you will need to make the DHCP server aware of its own network so that DHCPD can understand the network topology better. If our Linux DHCP server was running on 192.168.10.100 but the DHCP clients were assigned addresses from the 192.168.1.0/24 address range you would need to add the following line to dhcpd.conf so that it was aware of the 192.168.10.0/24 network.

subnet 192.168.10.0 netmask 255.255.255.0 {
}

Assigning a Fixed IP Address

DHCPD is quite capable of assigning a static IP address to one of its clients based on its MAC address. This can be useful for servers etc that provide services that require a fixed IP or perhaps one of your users is misbehaving and you want to investigate the nature of their traffic a bit more closely. Regardless of your objectives giving a DHCP client a fixed IP address is easy.

# host is a recognisable name of your choosing
# The hardware ethernet statement must be completed by supplying the clients MAC address
# Finally, specify the fixed IP address you would like assigned to the client using fixed-address

host fredspc {
hardware ethernet 0b:00:07:26:c0:ac;
fixed-address 192.168.1.9;
}