BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


Configuring a DHCP Server
Pages: 1, 2

A Sample Network

Now that we've had a chance to look through the default configuration file, let's configure a DHCP server for a simple network scenario. This sample network includes the following:



  • A network ID of 192.168.10.0 255.255.255.0
  • A domain name of mynetwork.com
  • 10 DHCP clients on one network segment
  • One default gateway with the address 192.168.10.1
  • One DHCP server with the address 192.168.10.2
  • Two DNS servers: 192.168.10.3 and 192.168.10.4

Note that the default gateway, DHCP server, and two DNS servers each have their own statically assigned address. It is important that the DHCP server is configured not to assign any of those addresses to the DHCP clients.

I'll now create the following file:

# vi /usr/local/etc/dhcpd.conf
#my dhcp server configuration file
#first, the global options

option domain-name "mynetwork.com";
option domain-name-servers 192.168.10.3, 192.168.10.4;

default-lease-time 86400;
max-lease-time 86400;

authoritative;
ddns-update-style none;

#next, my one and only subnet

subnet 192.168.10.0 netmask 255.255.255.0 {
    range 192.168.10.5 192.168.10.20;
    option routers 192.168.10.1;
}

You'll note that I changed the lease time to 86400 seconds, or 24 hours. I kept the default logging facility and disabled DDNS. I also defined a range of addresses: 5-20. This bypasses the statically assigned addresses (1-4) and leaves room for another five computers, should this network segment ever experience growth. When you make your own configuration file, remember to place a ; at the end of each statement and to enclose your subnet declaration between opening and closing curly braces.

Now, let's see if the configuration file works. First, I'll start the daemon and watch for any error messages:

# dhcpd
Internet Software Consortium DHCP Server V3.0.1rc11
Copyright 1995-2003 Internet Software Consortium.
All rights reserved.
For info, please visit http://http://www.isc.org/products/DHCP
Wrote 0 leases to leases file.

Listening on BPF/de0/00:80:c8:3a:b8:46/192.168.10.0/24
Sending on   BPF/de0/00:80:c8:3a:b8:46/192.168.10.0/24
Sending on   Socket/fallback/fallback-net

While I'm at it, I should also rename the sample startup script and check its permissions; this way, the DHCP server will restart, should I ever reboot:

# mv /usr/local/etc/rc.d/isc-dhcpd.sh.sample /usr/local/etc/rc.d/isc-dhcpd.sh

# ls -l /usr/local/etc/rc.d/isc-dhcpd.sh
-r-xr-xr-x  1 root  wheel  1662 Apr 13 10:32 /usr/local/etc/rc.d/isc-dhcpd.sh

Good. The script is executable, so it's ready to do its thing. You can also run this script manually if you give it one of the following options: start, stop, restart, or status. For example:

# /usr/local/etc/rc.d/isc-dhcpd.sh status
root    1830  0.0  0.5  1784 1392  ??  Is  5:00PM  0:00.00 dhcpd

The restart option is very handy if you make a change to your configuration file. DHCP is one service that won't change its configuration if you simply send it a "signal one." Instead, you have to actually determine the PID of the process, send a signal 15 to terminate the process, then restart the process. Running the above script with restart will do all of that for you.

Okay, let's see if the DHCP server is actually handing out leases. I'll boot one of the machines on the network which has already been pre-configured as a DHCP client. Once it finishes booting, I'll check its lease file:

# more /var/db/client.leases

lease {
  interface "ed0";
  fixed-address 192.168.10.20;
  option subnet-mask 255.255.255.0;
  option routers 192.168.10.1;
  option dhcp-lease-time 86400;
  option dhcp-message-type 5;
  option domain-name-servers 192.168.10.3,192.168.10.4;
  option dhcp-server-identifier 192.168.10.1;
  option domain-name "mynetwork.com";
  renew 1 2003/4/21 08:50:05;
  rebind 1 2003/4/21 18:38:59;
  expire 1 2003/4/21 21:38:59;
}

Excellent. It looks like this DHCP client successfully received a lease from the server. I'll also take a look at the leases file on the DHCP server to see which addresses it has leased out:

# more /var/db/dhcpd.leases

# All times in this file are in UTC (GMT), not your local timezone.   This is
# not a bug, so please don't ask about it.   There is no portable way to
# store leases in the local timezone, so please don't request this as a
# feature.   If this is inconvenient or confusing to you, we sincerely
# apologize.   Seriously, though - don't ask.
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-V3.0.1rc11

lease 192.168.10.20 {
  starts 0 2003/04/20 21:49:28;
  ends 1 2003/04/21 21:49:28;
  binding state active;
  next binding state free;
  hardware ethernet 00:50:ba:de:36:33;
}

Changing the Logging File

The last configuration I would like to demonstrate today is changing the default logging file. First, I'll change the logging line in /usr/local/etc/dhcpd.conf so that it looks like this:

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

Next, I'll create an empty log file called dhcpd.log:

# touch /var/log/dhcpd.log

Then, I'll create an entry for this logfile in /etc/syslog.conf by adding this line:

local7.*                   /var/log/dhcpd.log

Let's take a look at that entry for a moment. By default, you're given eight logging "facilities" to use for local applications; these are called local0 to local7. You can use whichever local facility you wish, as long as it isn't being used by another application. I've decided to use local7, which is why I also referred to it by that name in the DHCP server configuration file.

Once you've chosen a facility, you follow it by a period and a logging level. I've chosen the logging level of *, which will log all events, regardless of their level. I then gave the location of the log file to which to write events.

Once I've saved the changes to /etc/syslog.conf, I need to send syslogd a signal one so it is aware of the changes:

# killall -1 syslogd

I also need to make the DHCP server aware of the change. Remember, a signal one won't do it, so I'll use the restart option to the startup script:

# /usr/local/etc/rc.d/isc-dhcpd.sh restart

Finally, I'll see if it worked:

# more /var/log/dhcpd.log
Apr 20 19:32:22 fubar dhcpd: Internet Software Consortium DHCP Server V3.0.1rc11
Apr 20 19:32:22 fubar dhcpd: Copyright 1995-2003 Internet Software Consortium.
Apr 20 19:32:22 fubar dhcpd: All rights reserved.
Apr 20 19:32:22 fubar dhcpd: For info, please 
        visit http://http://www.isc.org/products/DHCP
Apr 20 19:32:22 fubar dhcpd: Wrote 1 leases to leases file. 
<snip>

In the next article, I'll continue by demonstrating a more complex network scenario involving multiple subnets and bootp relay agents.

Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.


Read more FreeBSD Basics columns.

Return to the BSD DevCenter.





Sponsored by: