Typo
[linux_from_scratch_hints.git] / OLD / dhcp_server.txt
blobef559d1377bc492550d1fda264252cddf17bbc2c
1 TITLE:          Creating a DHCP server from scratch
2 LFS VERSION:    Any
3 AUTHOR:         Thinus Pollard <12322741@puknet.puk.ac.za>
5 SYNOPSIS:
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.
12 HINT:
14 1. Introduction
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
26 be ;)
28 2. Packages to download
30     dhcp-3.0.tar.gz
31         ftp://ftp.isc.org/isc/dhcp/dhcp-latest.tar.gz
32     Web Page
33         http://www.isc.org
34         
35 3. Installation
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.
41     
42         1. Run the following in the top level directory to install to /usr
43            instead of /usr/local:
44        
45               sed 's%usr/local%usr%' Makefile.conf > Makefile.conf.temp
46     
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...
53        
54               sed 's%/var/state/dhcp%/var/cache/dhcp%' Makefile.conf \
55                   > Makefile.conf.temp
56           
57         4. The Makefile doesn't seem to know about linux-2.4, lets tell it ;)
58     
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
61           
62         5. It also has a high disregard for CFLAGS and CXXFLAGS
63     
64               sed 's%\$(BINDEF) \$(CC_OPTIONS)%\$(BINDEF) \$(CC_OPTIONS) \
65                   -O3 -march=i586%' Makefile.conf.temp > Makefile.conf
66           
67         That should fix up the Makefile.conf
68         
69         6. Edit the configure script and go to line no 82 change:
70         
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 ;;
75            to
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
83         
84               sed 's%/etc/dhcpd.conf%/etc/dhcp/dhcpd.conf%' dhcpd.h > tmp~ &&
85               mv tmp~ dhcpd.h
86                
87               sed 's%/etc/dhcpd.conf%/etc/dhcp/dhcpd.conf%' site.h > tmp~ &&
88               mv tmp~ site.h
89         
90         8. Change to the includes/cf directory and run the following
91         
92               sed 's%/var/state/dhcp%/var/cache/dhcp%' linux.h > linux.h.tmp
93               mv linux.h.tmp linux.h
95     3. Now do a
96            
97            ./configure &&
98            make &&
99            make install
101 4. Configuration
103     1. Do a 'touch /var/cache/dhcp/dhcpd.leases'
104     
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
107        
108        # Begin /etc/dhcp/dhcpd.conf
109        
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
114        
115        subnet 192.168.1.0 netmask 255.255.255.0 { # You need to change the ip
116                                                   # if you're using something
117                                                   # else
118        
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
124                                        # NAT ;)
125            option netbios-name-servers 192.168.1.1; # SMB Nameservers on your
126                                                     # network
127            
128            pool {
129                
130                range 192.168.1.240 192.168.1.254; # Range of available ip's
131                default-lease-time 300;
132                max-lease-time 300;
133                allow unknown clients;
134            }
135            
136            pool {
137            
138                range 192.168.1.11 192.168.1.239;
139                default-lease-time 86400;
140                max-lease-time 604800;
141                deny unknown clients;
142            }
143        }
144        
145        use-host-decl-names true;
146        
147        # For static addresses, use these host declariations.
148        
149        host legolas {
150            
151            hardware ethernet 00:80:AD:87:7F:59;
152            fixed-address 192.168.1.10;
153        }
154        
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
158        
159        host gimli {
160            
161            hardware ethernet 00:80:AD:87:7F:59;
162        }
164        # End /etc/dhcp/dhcpd.conf
166     3. And the init script...
168        #!/bin/sh
169        # Begin $rc_base/init.d/dhcpd
170        
171        # Based on sysklogd script from LFS-3.1 and earlier.
172        # Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org
173        
174        source /etc/sysconfig/rc
175        source $rc_functions
176        
177        case "$1" in
178            start)
179                echo -n "Starting DHCP daemon..."
180                loadproc /usr/sbin/dhcpd -q
181                ;;
182            stop)
183                echo -n "Stopping DHCP daemon..."
184                killproc dhcpd
185                ;;
186            restart)
187                $0 stop
188                sleep 5
189                $0 start
190                ;;
191            status)
192                statusproc /usr/sbin/dhcpd
193                ;;
194            *)
195                echo "Usage: $0 {start|stop|restart|status}"
196                exit 1
197                ;;
198        esac
199        
200        # End $rc_base/init.d/dhcpd
201        
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
204        stopping the network
205        
206 5. The End
208     1. You should be done now, give it a whirl. Now go read the man-pages and
209        start servin them ip's ;)
210     
211     2. Any comments, flames, suggestions etc is always welcome. Have a nice
212        day ;)