pavement

DHCP

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (copied over from one of the XDM pages)
 
(10 intermediate revisions by 3 users not shown)
Line 9: Line 9:
 
The most common unix implementation of the DHCP service is the [[ISC]]'s [[DHCP]]; Microsoft has their own implementation, as does Sun Microsystems.
 
The most common unix implementation of the DHCP service is the [[ISC]]'s [[DHCP]]; Microsoft has their own implementation, as does Sun Microsystems.
  
== Configuration ==
+
Configuring DHCP, like [[BIND]], is not horribly difficult but it can be a pain; consider using [[Webmin]] to help configure the software.
  
(placeholder...needs info on hosts, networks, shared-networks and the different options)
+
There are a few other configuration UIs for ISC's DHCP, see
  
==DHCP - Install and setup==
+
1. http://webdhcp.sourceforge.net/
  
===Installation===
+
2. http://freshmeat.net/projects/maintain/
install through package:
+
# pkg_add -r isc-dhcp3-server
+
  
or ports:
+
3. http://sourceforge.net/projects/dixie/
# cd /usr/ports/nets/isc-dhcp3-server && make install clean
+
  
===Setup===
+
4. http://webmin.com
  
copy /usr/local/etc/dhcpd.conf.sample to /usr/local/etc/dhcpd.conf
+
5. http://sauron.jyu.fi/
  
edit /usr/local/etc/dhcpd.conf aas apropriate:.
+
== Configuration ==
<pre>
+
# dhcpd.conf
+
#
+
# Sample configuration file for ISC dhcpd
+
#
+
  
# option definitions common to all supported networks...
+
The /etc/dhcpd.conf (or /usr/local/etc/dhcpd.conf) file sets the configuration that will be handed to your clients. Things you need to know:
#option domain-name "example.org";
+
- the interface that will be receiving the DHCP requests must also be on the same network that it will be handing out. If you're handing out 192.168.1.0/24 addresses on your hme0 interface, your hme0 interface must have an address in that /24 network.
#option domain-name-servers ns1.example.org, ns2.example.org;
+
- any general statements / config options can be made globally and limited to a specific network; the network-specific options will trump the general options usually.
# lease times are measured in seconds:
+
default-lease-time 3600;
+
max-lease-time 86400;
+
  
# If this DHCP server is the official DHCP server for the local
+
You will need to define the following sections:
# network, the authoritative directive should be uncommented.
+
authoritative;
+
  
# ad-hoc DNS update scheme - set to "none" to disable dynamic DNS updates.
+
general config
ddns-update-style none;
+
  
# Use this to send dhcp log messages to a different log file (you also
+
options
# have to hack syslog.conf to complete the redirection).
+
log-facility local7;
+
  
# No service will be given on this subnet, but declaring it helps the
+
subnets
# DHCP server to understand the network topology.
+
  
# This is a very basic subnet declaration.
+
- pools
 +
 
 +
shared-networks
 +
 
 +
 
 +
from the FAQ:
 +
<pre>
 +
# Sample /etc/dhcpd.conf
 +
# (add your comments here)
 +
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.254;
 +
option domain-name-servers 192.168.1.1, 192.168.1.2;
 +
option domain-name "mydomain.org";
  
 
subnet 192.168.1.0 netmask 255.255.255.0 {
 
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.10 192.168.1.20;
+
  range 192.168.1.10 192.168.1.100;
 +
  range 192.168.1.150 192.168.1.200;
 
}
 
}
 
</pre>
 
</pre>
  
===Create the leases file===
+
This will result in DHCP server giving a client an IP address from the range 192.168.1.10-192.168.1.100 or 192.168.1.150-192.168.1.200. It will lease an IP address for 600 seconds if the client doesn't ask for specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also "advise" the client that it should use 255.255.255.0 as its subnet mask, 192.168.1.255 as its broadcast address, 192.168.1.254 as the router/gateway and 192.168.1.1 and 192.168.1.2 as its DNS servers.
 +
 
 +
If you need to specify a WINS server for your Windows clients you will need to include the netbios-name-servers option e.g.
 
<pre>
 
<pre>
# touch /var/db/dhcpd.leases
+
option netbios-name-servers 192.168.1.1;
 
</pre>
 
</pre>
 
+
You can also assign specific IP addresses based on clients ethernet address e.g.
 
+
===Restart the daemon===
+
 
<pre>
 
<pre>
# killall dhcpd
+
host haagen {
# dhcpd
+
  hardware ethernet 08:00:2b:4c:59:23;
 +
  fixed-address 192.168.1.222;
 +
}
 
</pre>
 
</pre>
  
  
===Setup to run on reboot===
+
====Installation====
 +
install through package:
 +
# pkg_add -r isc-dhcp3-server
 +
 
 +
or ports:
 +
# cd /usr/ports/nets/isc-dhcp3-server && make install clean
 +
 
 +
====Setup====
 +
 
 +
copy /usr/local/etc/dhcpd.conf.sample to /usr/local/etc/dhcpd.conf
 +
 
 +
edit /usr/local/etc/dhcpd.conf as apropriate:.
 +
# dhcpd.conf
 +
#
 +
# Sample configuration file for ISC dhcpd
 +
#
 +
 +
# option definitions common to all supported networks...
 +
#option domain-name "example.org";
 +
#option domain-name-servers ns1.example.org, ns2.example.org;
 +
# lease times are measured in seconds:
 +
default-lease-time 3600;
 +
max-lease-time 86400;
 +
 +
# If this DHCP server is the official DHCP server for the local
 +
# network, the authoritative directive should be uncommented.
 +
authoritative;
 +
 +
# ad-hoc DNS update scheme - set to "none" to disable dynamic DNS updates.
 +
ddns-update-style none;
 +
 +
# 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;
 +
 +
# No service will be given on this subnet, but declaring it helps the
 +
# DHCP server to understand the network topology.
 +
 +
# This is a very basic subnet declaration.
 +
 +
subnet 192.168.1.0 netmask 255.255.255.0 {
 +
  range 192.168.1.10 192.168.1.20;
 +
}
 +
 
 +
====Create the leases file====
 +
# touch /var/db/dhcpd.leases
 +
 
 +
 
 +
====Restart the daemon====
 +
# killall dhcpd
 +
# dhcpd
 +
 
 +
 
 +
====Setup to run on reboot====
 
Add to /etc/rc.conf
 
Add to /etc/rc.conf
<pre>
+
dhcpd_enable="YES"
dhcpd_enable="YES"
+
</pre>
+
  
 
== Problems starting dhcpd ==
 
== Problems starting dhcpd ==
Line 120: Line 172:
 
  Starting dhcpd.
 
  Starting dhcpd.
 
  dhcp-1#
 
  dhcp-1#
 +
 +
== See Also ==
 +
 +
The DHCP service can be configured to supply hosts with the network addresses of local [[WINS]] service servers, which are used to resolve NetBIOS names to IP addresses.
  
 
[[Category:FreeBSD for Servers]]
 
[[Category:FreeBSD for Servers]]

Latest revision as of 09:49, 13 October 2007

Contents

[edit] DHCP

Dynamic Host Configuration Protocol. DHCP allows you to place machines on a network and configure many of their settings (network-wise) via a server that your host machine queries. Usually this is limited to what IP and DNS client information a host uses on the network, and this greatly increases an administrator's ability to configure a large number of hosts to use a network with minimal effort (as opposed to configuring each host individually.)

The service daemon on most *nix platforms is called dhcpd, the client application (if your *nix box is set up to use DHCP,) is usually dhclient.

[edit] Software

The most common unix implementation of the DHCP service is the ISC's DHCP; Microsoft has their own implementation, as does Sun Microsystems.

Configuring DHCP, like BIND, is not horribly difficult but it can be a pain; consider using Webmin to help configure the software.

There are a few other configuration UIs for ISC's DHCP, see

1. http://webdhcp.sourceforge.net/

2. http://freshmeat.net/projects/maintain/

3. http://sourceforge.net/projects/dixie/

4. http://webmin.com

5. http://sauron.jyu.fi/

[edit] Configuration

The /etc/dhcpd.conf (or /usr/local/etc/dhcpd.conf) file sets the configuration that will be handed to your clients. Things you need to know: - the interface that will be receiving the DHCP requests must also be on the same network that it will be handing out. If you're handing out 192.168.1.0/24 addresses on your hme0 interface, your hme0 interface must have an address in that /24 network. - any general statements / config options can be made globally and limited to a specific network; the network-specific options will trump the general options usually.

You will need to define the following sections:

general config

options

subnets

- pools

shared-networks


from the FAQ:

# Sample /etc/dhcpd.conf
# (add your comments here) 
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.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name "mydomain.org";

subnet 192.168.1.0 netmask 255.255.255.0 {
   range 192.168.1.10 192.168.1.100;
   range 192.168.1.150 192.168.1.200;
}

This will result in DHCP server giving a client an IP address from the range 192.168.1.10-192.168.1.100 or 192.168.1.150-192.168.1.200. It will lease an IP address for 600 seconds if the client doesn't ask for specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also "advise" the client that it should use 255.255.255.0 as its subnet mask, 192.168.1.255 as its broadcast address, 192.168.1.254 as the router/gateway and 192.168.1.1 and 192.168.1.2 as its DNS servers.

If you need to specify a WINS server for your Windows clients you will need to include the netbios-name-servers option e.g.

option netbios-name-servers 192.168.1.1;

You can also assign specific IP addresses based on clients ethernet address e.g.

host haagen {
   hardware ethernet 08:00:2b:4c:59:23;
   fixed-address 192.168.1.222;
}


[edit] Installation

install through package:

# pkg_add -r isc-dhcp3-server

or ports:

# cd /usr/ports/nets/isc-dhcp3-server && make install clean

[edit] Setup

copy /usr/local/etc/dhcpd.conf.sample to /usr/local/etc/dhcpd.conf

edit /usr/local/etc/dhcpd.conf as apropriate:.

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
# lease times are measured in seconds: 
default-lease-time 3600;
max-lease-time 86400;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# ad-hoc DNS update scheme - set to "none" to disable dynamic DNS updates.
ddns-update-style none;

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

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

# This is a very basic subnet declaration.

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.10 192.168.1.20;
}

[edit] Create the leases file

# touch /var/db/dhcpd.leases


[edit] Restart the daemon

# killall dhcpd
# dhcpd


[edit] Setup to run on reboot

Add to /etc/rc.conf

dhcpd_enable="YES"

[edit] Problems starting dhcpd

[edit] Errors when trying to start

NOTE: This problem was found on this architecture, but may apply to others.

dhcp-1# uname -a
FreeBSD dhcp-1.one.example.com 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Thu Nov  3 09:36:13 UTC 2005   
root@x64.samsco.home:/usr/obj/usr/src/sys/GENERIC  i386
dhcp-1#
dhcp-1# /usr/local/etc/rc.d/isc-dhcpd.sh start
chown: dhcpd: Invalid argument
/usr/local/etc/rc.d/isc-dhcpd.sh: WARNING: unable to change permissions of /var/run/dhcpd
/usr/local/etc/rc.d/isc-dhcpd.sh: WARNING: safe_run: chown dhcpd:dhcpd /var/db/dhcpd
/usr/local/etc/rc.d/isc-dhcpd.sh: WARNING: unable to change permissions of /var/db/dhcpd
chown: dhcpd: Invalid argument
/usr/local/etc/rc.d/isc-dhcpd.sh: WARNING: unable to change permissions of /var/db/dhcpd/dhcpd.leases
Starting dhcpd.
dhcp-1#

[edit] Find out if dhcpd is running

dhcp-1# ps -auwx | grep dhcp
root     94818  0.0  0.6  2188  1536  ??  Is   15Jan07   0:00.05 /usr/local/sbin/dhcpd
root     24289  0.0  1.1  3892  2612  p0  RV    6:22AM   0:00.00 grep dhcp (csh)

[edit] Stop dhcpd (if running)

dhcp-1# kill -9 94818

[edit] Verify that dhcpd has been stopped

dhcp-1# ps -auwx | grep dhcp
root     24293  0.0  0.1   348   208  p0  R+    6:22AM   0:00.00 grep dhcp

[edit] Fix the problem

dhcp-1# /usr/local/etc/rc.d/isc-dhcpd.sh install
Added group "dhcpd".
Added user "dhcpd".
dhcp-1# 

[edit] Start dhcpd normally

dhcp-1# /usr/local/etc/rc.d/isc-dhcpd.sh start
Starting dhcpd.
dhcp-1#

[edit] See Also

The DHCP service can be configured to supply hosts with the network addresses of local WINS service servers, which are used to resolve NetBIOS names to IP addresses.

Personal tools