1 TITLE: Creating a DHCP server from scratch
3 AUTHOR: Thinus Pollard <12322741@puknet.puk.ac.za>
6 This hint handles the installation of the ISC DHCP daemon. The daemon is
7 used to automatically hand out ip addresses to client pc's on your
8 network. Obviously this is a much smarter way of doing things than to
9 physically go to each of the 150+ pc's on your network and setup the
10 network on all of them.
16 The idea behind dhcp is indeed very simple, yet it's an elegant solution to a
17 majorish problem. When a client PC on the network comes up, it sends a
18 DHCPDISCOVER packet. The dhcp server receives this packet, check the database
19 for the client's ip address, and sends a DHCPACK packet, informing the client of
20 an ip address it should use, or confirmation that the client should continue to
21 use the current ip. The ip address allocation can either be dynamic, or static
22 in which the dhcp server matches the client's MAC address to an ip address in
23 the database. This way you can ensure a certain network card always gets the
24 same ip on the network, and now you can start thinking about all kinds of
25 interesting routing tricks you can pull to make your network a good place to
28 2. Packages to download
31 ftp://ftp.isc.org/isc/dhcp/dhcp-latest.tar.gz
37 1. Unpack the dhcp package anywhere you like as long as it's in /usr/src.
39 2. The people at ISC sometimes have some funny ideas about the location of
40 certain files. We're gonna fix this.
42 1. Run the following in the top level directory to install to /usr
43 instead of /usr/local:
45 sed 's%usr/local%usr%' Makefile.conf > Makefile.conf.temp
47 2. You may just as well fix the manpaths in the file by:
49 sed 's%usr/man%usr/share/man%' Makefile.conf.temp > Makefile.conf
51 3. The server wants the database file in /var/state/dhcp. Not me, I
52 want it in /var/cache/dhcp, so...
54 sed 's%/var/state/dhcp%/var/cache/dhcp%' Makefile.conf \
57 4. The Makefile doesn't seem to know about linux-2.4, lets tell it ;)
59 sed 's/Linux 2.2/Linux 2.4/' Makefile.conf.temp > Makefile.conf
60 sed 's/linux-2.2/linux-2.4/' Makefile.conf > Makefile.conf.temp
62 5. It also has a high disregard for CFLAGS and CXXFLAGS
64 sed 's%\$(BINDEF) \$(CC_OPTIONS)%\$(BINDEF) \$(CC_OPTIONS) \
65 -O3 -march=i586%' Makefile.conf.temp > Makefile.conf
67 That should fix up the Makefile.conf
69 6. Edit the configure script and go to line no 82 change:
71 0) sysname=linux=linux-2.0 ;;
72 1) sysname=linux=linux-2.1 ;;
73 2) sysname=linux=linux-2.2 ;;
74 *) sysname=linux=linux-2.2 ;;
76 0) sysname=linux=linux-2.0 ;;
77 1) sysname=linux=linux-2.1 ;;
78 2) sysname=linux=linux-2.2 ;;
79 4) sysname=linux=linux-2.4 ;;
80 *) sysname=linux=linux-2.2 ;;
82 7. Change to the includes directory and run
84 sed 's%/etc/dhcpd.conf%/etc/dhcp/dhcpd.conf%' dhcpd.h > tmp~ &&
87 sed 's%/etc/dhcpd.conf%/etc/dhcp/dhcpd.conf%' site.h > tmp~ &&
90 8. Change to the includes/cf directory and run the following
92 sed 's%/var/state/dhcp%/var/cache/dhcp%' linux.h > linux.h.tmp
93 mv linux.h.tmp linux.h
103 1. Do a 'touch /var/cache/dhcp/dhcpd.leases'
105 2. Here is my config file. Read the man-pages and the DHCP mini howto for
106 more information. The config file goes into /etc/dhcp/dhcpd.conf
108 # Begin /etc/dhcp/dhcpd.conf
110 authorative; # For the subnets it's configured for
111 ddns-update-style none; # Lotsa trouble here... rtfm
112 deny bootp; # we're not using it, so why allow it?
113 one-lease-per-client true; # Should make sense
115 subnet 192.168.1.0 netmask 255.255.255.0 { # You need to change the ip
116 # if you're using something
119 option broadcast-address 192.168.1.255; # Self explanitory
120 option routers 192.168.1.1; # Available routers
121 option domain-name-servers 192.168.1.1; # Available DNS
122 option domain-name "rivendell.org.za"; # Domain name
123 option ip-forwarding false; # You don't really want clients doing
125 option netbios-name-servers 192.168.1.1; # SMB Nameservers on your
130 range 192.168.1.240 192.168.1.254; # Range of available ip's
131 default-lease-time 300;
133 allow unknown clients;
138 range 192.168.1.11 192.168.1.239;
139 default-lease-time 86400;
140 max-lease-time 604800;
141 deny unknown clients;
145 use-host-decl-names true;
147 # For static addresses, use these host declariations.
151 hardware ethernet 00:80:AD:87:7F:59;
152 fixed-address 192.168.1.10;
155 # For dynamic addresses, use these host declariations. Without the
156 # "fixed address" part the host is still known, it's just allowed to
157 # get any ip from the pool
161 hardware ethernet 00:80:AD:87:7F:59;
164 # End /etc/dhcp/dhcpd.conf
166 3. And the init script...
169 # Begin $rc_base/init.d/dhcpd
171 # Based on sysklogd script from LFS-3.1 and earlier.
172 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
174 source /etc/sysconfig/rc
179 echo -n "Starting DHCP daemon..."
180 loadproc /usr/sbin/dhcpd -q
183 echo -n "Stopping DHCP daemon..."
192 statusproc /usr/sbin/dhcpd
195 echo "Usage: $0 {start|stop|restart|status}"
200 # End $rc_base/init.d/dhcpd
202 4. Add a symlink in rc[345].d to start the dhcpd server just after starting
203 the network and a symlink in rc[0126].d to stop the server just before
208 1. You should be done now, give it a whirl. Now go read the man-pages and
209 start servin them ip's ;)
211 2. Any comments, flames, suggestions etc is always welcome. Have a nice