DHCP-Server

Will man seinen Clients im Netzwerk automatisch eine IP, DNS-Einstellungen und vieles mehr zuweisen. Benötigt man einen DHCP-Server. Viele werden sich fragen warum einen DHCP zu Hause extra auf dem Server laufen lassen und nicht einfach den DHCP am Router nutzen. Das Problem bei den meisten Routern ist das man diesen DHCP nicht konfigurieren kann. Man kann meist einen Adressbreich festlegen. Aber einen anderen DNS an die Clients verteilen, die richtige Domain weitergeben, die IP des WINS verteilen … kann man mit den wenigsten SOHO-Routern. Einen eignen DHCP am Server kann man genau nach seinen Vorstellungen und Anforderungen konfigurieren. Mein favorisierter DHCP-Server ist der vom ISC.

http://www.isc.org/software/dhcp

Installation

Der ISC DHCP Server ist einer der Pakete die sich in Debian 6.0 etwas verändert haben (die Verzeichnisse haben sich verändert). Die Konfigurationdateien finfet man nicht wie unter Debian 5.0 in /etc/dhcp3 sondern in /etc/dhcp

apt-get install dhcp3-server

Konfiguration

Auf welchen Interfaces der DHCP lauschen soll kann man hier festlegen. Soll dieser auf allen Interfaces zur Verfügung stehen. Kann man die INTERFACES Variable leer lassen. Mein Server besitzt zwei Netzwerkkarten darum gebe ich dieses Interface an.

# Defaults for dhcp initscript
# sourced by /etc/init.d/dhcp
# installed at /etc/default/isc-dhcp-server by the maintainer scripts

#
# This is a POSIX shell fragment
#

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#	Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"

Die eigentliche Konfigurationsdatei ist die Datei /etc/dhcp/dhcpd.conf. Die optionalen Einstellungen können weg gelassen werden wenn die entsprechenden Dienste nicht vorhanden sind. Wie man einen DNS einrichtet wie es hier im Beispiel angegeben ist findet man im Artikel lokaler DNS Server

# Sample configuration file for ISC dhcpd for Debian
#
# $Id: dhcpd.conf,v 1.1.1.1 2002/05/21 00:07:44 peloy Exp $
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# option definitions common to all supported networks...
option domain-name "trabauer.local";
option domain-name-servers 192.168.0.2, 192.168.0.1; 

default-lease-time 600;
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;


## Defninition des ersten Subnets
subnet 192.168.0.0 netmask 255.255.255.0 
{
	range 192.168.0.3 192.168.0.127;
	option subnet-mask 255.255.255.0;
	option routers 192.168.0.1;

	default-lease-time 600;
	max-lease-time 7200;

	# DNS-Server Einstelungen
	option domain-name-servers 192.168.0.2;

	# WINS-Server (OPTIONAL: Falls ein Samba mit wins support vorhanden ist)
	option netbios-name-servers 192.168.0.2;
	option netbios-node-type 2;
	
	# PXE boot (OPTIONAL: Falls ein TFTP mit PXE-Linux vorhanden ist um Rechner im LAN über das Netzwerk zu booten
	next-server 192.168.0.2;
	filename "/pxelinux.0";
	
	# Statiche DHCP-Einträge
	host asterix {
		hardware ethernet 00:22:15:90:fa:17;
		fixed-address 192.168.0.8;
	}
}

Ist die Konfiguration fertig kann der DHCP Server auch gestartet werden.

root@majestix /etc/dhcp # /etc/init.d/isc-dhcp-server restart
Starting ISC DHCP server: dhcpd.
root@majestix /etc/dhcp # /etc/init.d/isc-dhcp-server status
Status of ISC DHCP server: dhcpd is running.

Ob IPs vergeben werden kann man, natürlich in den Logs kontrollieren.

root@majestix /etc/dhcp # tail -f /var/log/syslog
Feb 20 14:13:54 majestix dhcpd: WARNING: Host declarations are global.  They are not limited to the scope you declared them in.
Feb 20 14:13:54 majestix dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
Feb 20 14:13:54 majestix dhcpd: Copyright 2004-2010 Internet Systems Consortium.
Feb 20 14:13:54 majestix dhcpd: All rights reserved.
Feb 20 14:13:54 majestix dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Feb 20 14:13:54 majestix dhcpd: Wrote 0 deleted host decls to leases file.
Feb 20 14:13:54 majestix dhcpd: Wrote 0 new dynamic host decls to leases file.
Feb 20 14:13:54 majestix dhcpd: Wrote 0 leases to leases file.
Feb 20 14:15:23 majestix dhcpd: DHCPREQUEST for 192.168.0.21 from 90:27:e4:ea:52:b4 via eth0
Feb 20 14:15:23 majestix dhcpd: DHCPACK on 192.168.0.21 to 90:27:e4:ea:52:b4 via eth0
Feb 20 14:16:22 majestix dhcpd: DHCPREQUEST for 192.168.0.29 from c4:2c:03:2a:47:0d via eth0
Feb 20 14:16:22 majestix dhcpd: DHCPACK on 192.168.0.29 to c4:2c:03:2a:47:0d via eth0
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'b._dns-sd._udp.0.2.168.192.in-addr.arpa/PTR/IN': 2001:503:ba3e::2:30#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'db._dns-sd._udp.0.2.168.192.in-addr.arpa/PTR/IN': 2001:500:2f::f#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'lb._dns-sd._udp.0.2.168.192.in-addr.arpa/PTR/IN': 2001:503:c27::2:30#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'db._dns-sd._udp.0.58.168.192.in-addr.arpa/PTR/IN': 2001:7fe::53#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'cf._dns-sd._udp.0.58.168.192.in-addr.arpa/TXT/IN': 2001:500:3::42#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'v.arin.net/AAAA/IN': 2001:7fd::1#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'x.arin.net/A/IN': 2001:503:a83e::2:30#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'x.arin.net/A/IN': 2001:503:231d::2:30#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'z.arin.net/A/IN': 2001:500:13::108#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'z.arin.net/A/IN': 2001:500:31::108#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'd3.nstld.com/A/IN': 2001:503:a83e::2:31#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'd3.nstld.com/A/IN': 2001:503:83eb::2:31#53
Feb 20 14:16:24 majestix named[22826]: error (network unreachable) resolving 'blackhole-1.iana.org/AAAA/IN': 2001:500:1::803f:235#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'blackhole-1.iana.org/A/IN': 2001:500:b::1#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'blackhole-2.iana.org/AAAA/IN': 2001:500:e::1#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'blackhole-1.iana.org/AAAA/IN': 2001:500:40::1#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'blackhole-2.iana.org/A/IN': 2001:500:f::1#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'a.iana-servers.net/AAAA/IN': 2001:500:8c::53#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'a.iana-servers.net/AAAA/IN': 2001:648:2c30::1:10#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'a.iana-servers.net/AAAA/IN': 2001:500:89::53#53
Feb 20 14:16:25 majestix named[22826]: error (network unreachable) resolving 'a.iana-servers.net/AAAA/IN': 2620:0:2ee0:2::153#53
Feb 20 14:16:36 majestix dhcpd: DHCPINFORM from 192.168.0.30 via eth0
Feb 20 14:16:36 majestix dhcpd: DHCPACK to 192.168.0.30 (00:24:d6:22:a3:e2) via eth0




^C
130 root@majestix /etc/dhcp #                                                                                                                 🙁 

Die vergebenen Leases kann man in der Datei /var/lib/dhcp/dhcpd.leases nachsehen.

root@majestix /home/flo # cat /var/lib/dhcp/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1

lease 192.168.0.5 {
  starts 1 2011/02/21 18:10:53;
  ends 1 2011/02/21 18:20:53;
  tstp 1 2011/02/21 18:20:53;
  cltt 1 2011/02/21 18:10:53;
  binding state free;
  hardware ethernet 00:d0:55:04:cb:d1;
  uid "\001\000\320U\004\313\321";
}
lease 192.168.0.3 {
  starts 1 2011/02/21 20:29:50;
  ends 1 2011/02/21 20:39:50;
  tstp 1 2011/02/21 20:39:50;
  cltt 1 2011/02/21 20:29:50;
  binding state free;
  hardware ethernet 00:23:32:2c:75:dd;
  uid "\001\000#2,u\335";
}

About Florian