IPv4/DHCP/Server

Aus Foxwiki

DHCP (Dynamic Host Configuration Protocol)

Allgemein

  • ist Erweiterung des Bootstrap-Protokolls (BOOTP)
  • ist ein Hintergrundprozess (Dienst/Daemon)
  • definiert in RFC 2131
  • Transport durch UDP
  • Standard-Ports:
    • IPv4: 67 (Server od. Relay-Agent) 68 (Client)
    • IPv6: 547 (Server od. Relay-Agent) 546 (Client)

Aufgabe

  • angeschlossene Clients ohne manuelle Konfiguration der Schnittstelle in ein bestehendes Netz einbinden,
  • das heißt die Konfigurationsparameter...
    • IP-Adresse, die Adresse eines Gerätes im Netzwerk,
    • Netzmaske, Adressierung des Netz- und Hostteils einer IP-Adresse,
    • Gateway, die Brücke von einem ins andere Netz,
    • Rechnername,
    • Broadcast-Adresse,
    • Boot-Image für plattenlose Workstations,
    • NetBIOS Nameserver und Name Server (DNS)
    • Time- und NTP-Server, die für die Synchronisierung der Uhrzeit zuständig sind,
  • ...können automatisch vergeben werden

Betriebsmodi

  • manuelle Zuordnung (statisches DHCP):
  • IP-Adressen werden bestimmte MAC-Adressen fest zugeordnet; z.B. wichtig bei Port-Weiterleitungen oder wenn DHCP-Client Server-Dienste zur Verfügung stellt
Nachteil: kein „einfaches“ Einbinden von neuen Clients
  • automatische Zuordnung:
  • am DHCP-Server wird ein Bereich (range) von IP-Adressen definiert IP-Adressen werden automatisch an die MAC-Adressen von neuen DHCP-Clients zugewiesen und keinem anderen Host mehr zugewiesen
  • Zuweisungen sind permanent, werden nicht entfernt und in einer Tabelle eingetragen (/var/lib/dhcpd.leases)
Nachteil: neue Clients erhalten keine IP-Adresse, wenn der gesamte Adressbereich vergeben ist, auch wenn die bereits vergebenen IP-Adressen nicht aktiv genutzt werden
  • dynamische Zuordnung:
  • automatische Zuordnung mit Lease-Time
  • in Konfigurationdatei (/etc/dhcp/dhcpd.conf) wird festgelegt, wie lange eine IP-Adresse an Client „verliehen“ wird, bevor Client beim Server eine „Verlängerung“ beantragen muss
Vorteil: bei „Nicht-Verlängerung“ durch Client wird IP-Adresse frei und neu vergeben

Ablauf

  1. DHCP-DISCOVER: Client sucht per Broadcast nach DHCP-Server
  2. DHCP-OFFER: DHCP-Server bietet Client per Unicast Konfigurationsparameter der Schnittstelle an
  3. DHCP-REQUEST: Client fordert angebotene Konfigurationsparameter bei DHCP-Server an (z.B. Mietanfrage)
  4. DHCP-ACK: DHCP-Server sendet Konfigurationsparameter an Client
  5. DHCP-NAK: Ablehnung einer DHCPREQUEST-Anforderung durch den DHCP-Server.
  6. DHCP-DECLINE: Ablehnung durch den Client, da die IP-Adresse schon verwendet wird.
  7. DHCP-RELEASE: Der Client gibt die eigene Konfiguration frei, damit die Parameter wieder für andere Clients zur Verfügung stehen.
  8. DHCP-INFORM: Anfrage eines Clients nach weiteren Konfigurationsparametern, z. B. weil der Client eine statische IP-Adresse besitzt.


DHCP Ablauf

Einrichtung unter Linux/Debian am Beispiel "isc-dhcp-server"

Installation

Server

root@router0230:~# apt install isc-dhcp-server

Konfiguration

wichtige Dateien:

  • "/etc/default/isc-dhcp-server"
  • "/etc/dhcp/dhcpd.conf"

/etc/default/isc-dhcp-server

Hier muss festgelegt werden, an welches Netzwerkgerät der DHCP-Server gebunden werden soll. Hier soll das Netzwerkgerät "enp5s1" an den DHCP-Server gebunden werden.

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

/etc/dhcp/dhcpd.conf

Festlegung von ...

  • Authoritative-Statement
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
  • Lease-Time in Sekunden
default-lease-time 600;
max-lease-time 7200;
  • Subnet-Blöcke
  • Range
  • Options - z.B. Router, Domain-Name-Server
# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
#  range 10.254.239.10 10.254.239.20;
#  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 {
#  range dynamic-bootp 10.254.239.40 10.254.239.60;
#  option broadcast-address 10.254.239.31;
#  option routers rtr-239-32-1.example.org;
#}

# A slightly different configuration for an internal subnet.
subnet 10.30.30.0 netmask 255.255.255.0
       range 10.30.30.10 10.30.30.99;
       option subnet-mask 255.255.255.0;
       option domain-name-servers 10.0.0.3, 10.0.0.4;
       option domain-name "raum102.itw";
       option domain-search "raum102.itw";
       option routers 10.30.30.1;
       option broadcast-address 10.30.30.255;
       default-lease-time 600;
       max-lease-time 7200;
host user {
  hardware ethernet 00:1d:7d:c8:de:bd;
  fixed-address 10.30.30.5;
  option host-name "user";
}
host robert {
  hardware ethernet 74:27:ea:e1:b2:b4;
  fixed-address 10.30.30.6;
  option host-name "robert";
}
host meik {
  hardware ethernet 74:27:ea:cc:fe:a0;
  fixed-address 10.30.30.7;
  option host-name "meik";
}
host ufuk {
  hardware ethernet 74:27:ea:e1:ba:b1;
  fixed-address 10.30.30.8;
  option host-name "ufuk";
}
host tanja {
  hardware ethernet 74:27:ea:e1:b1:e4;
  fixed-address 10.30.30.9;
  option host-name "tanja";
}
}


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

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

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

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

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

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
#  range 10.254.239.10 10.254.239.20;
#  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 {
#  range dynamic-bootp 10.254.239.40 10.254.239.60;
#  option broadcast-address 10.254.239.31;
#  option routers rtr-239-32-1.example.org;
#}

# A slightly different configuration for an internal subnet.
subnet 10.30.30.0 netmask 255.255.255.0
       range 10.30.30.10 10.30.30.99;
       option subnet-mask 255.255.255.0;
       option domain-name-servers 10.0.0.3, 10.0.0.4;
       option domain-name "raum102.itw";
       option domain-search "raum102.itw";
       option routers 10.30.30.1;
       option broadcast-address 10.30.30.255;
       default-lease-time 600;
       max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.
#host passacaglia {
#  hardware ethernet 0:0:c0:5d:bd:95;
#  filename "vmunix.passacaglia";
#  server-name "toccata.example.com";
#}

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
#  hardware ethernet 08:00:07:26:c0:a5;
#  fixed-address fantasia.example.com;
#}

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
#  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}

#shared-network 224-29 {
#  subnet 10.17.224.0 netmask 255.255.255.0 {
#    option routers rtr-224.example.org;
#  }
#  subnet 10.0.29.0 netmask 255.255.255.0 {
#    option routers rtr-29.example.org;
#  }
#  pool {
#    allow members of "foo";
#    range 10.17.224.10 10.17.224.250;
#  }
#  pool {
#    deny members of "foo";
#    range 10.0.29.10 10.0.29.230;
#  }
#}

Nach der Änderung der Konfiguration muss die dhcpd.conf erneut eingelesen werden.

root@router0230:~# systemctl restart isc-dhcp-server.service

Client

/etc/dhcp/dhclient.conf

# Configuration file for /sbin/dhclient.
#
# This is a sample configuration file for dhclient. See dhclient.conf's 
#       man page for more information about the syntax of this file 
#       and a more comprehensive list of the parameters understood by 
#       dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
#       not leave anything out (like the domain name, for example), then
#       few changes must be made to this file, if any.
#

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;

#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
#prepend domain-name-servers 127.0.0.1;
#require subnet-mask, domain-name-servers;
#timeout 60;
#retry 60;
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/sbin/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;

#alias {
#  interface "eth0";
#  fixed-address 192.5.5.213;
#  option subnet-mask 255.255.255.255;
#}

#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andare.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}

Fehlerbehebung

/var/log/syslog

Can't open lease database /var/lib/dhcpd/dhcpd.leases: No such file or directory --
check for failed database rewrite attempt!

=> Datei /var/lib/dhcpd erzeugen

Danach kann die Datei dhcpd.leases erzeugt und beschrieben werden...

root@router0230:~# touch /var/lib/dhcpd/dhcpd.leases

...und im Anschluss dann ausgelesen werden.