Dernière mise-à-jour : 2020/01/30 03:27
Weight: 2
Description: Candidates should be able to configure a DHCP server. This objective includes setting default and per client options, adding static hosts and BOOTP hosts. Also included is configuring a DHCP relay agent and maintaining the DHCP server.
Key Knowledge Areas:
Terms and Utilities:
Un serveur DHCP (Dynamic Host Configuration Protocol) est un ordinateur exécutant un logiciel serveur DHCP. L’avantage de la présence d’un serveur DHCP sur le réseau local est que celui-ci permet de spécifier à un niveau central les paramètres TCP/IP.
Pour installer le serveur DHCP, il convient d'utiliser yum.
D'abord déinstallez le paquet du client dhcp :
[root@centos6 ~]# yum remove dhclient ...
Ensuite installez le serveur dhcp :
[root@centos6 ~]# yum install dhcp ...
Vérifiez ensuite que le service dhcpd est activé au démarrage du serveur:
[root@centos6 ~]# chkconfig --list dhcpd dhcpd 0:arrêt 1:arrêt 2:arrêt 3:arrêt 4:arrêt 5:arrêt 6:arrêt
Activez donc le serveur dhcpd dans les niveaux d'exécution 3, 4 et 5 :
[root@centos6 ~]# chkconfig --level 345 dhcpd on [root@centos6 ~]# chkconfig --list dhcpd dhcpd 0:arrêt 1:arrêt 2:arrêt 3:marche 4:marche 5:marche 6:arrêt
Lors de l'installation du paquetage, un fichier dhcpd.conf.sample est installé dans /usr/share/doc/dhcp-4.1.1/. Ce fichier est un exemple du fichier de configuration du serveur DHCP, dhcpd.conf :
[root@centos6 ~]# cat /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample
# 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;
# Use this to enble / disable dynamic dns updates globally.
#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.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
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.fugue.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.fugue.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;
}
}
Créez un fichier dhcpd.conf dans le répertoire /etc/dhcp.
Editez-le ainsi :
#
# Section Globale
#
ddns-update-style none;
DHCPD_INTERFACE = "eth0";
#
# Section sous-réseau
#
subnet 10.0.2.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option routers 10.0.2.2;
option domain-name-servers 10.0.2.15;
option domain-name-servers 10.0.2.3;
option ntp-servers 10.0.2.15;
option domain-name "fenestros.loc";
default-lease-time 28800;
max-lease-time 86400;
not authoritative;
pool {
range 10.0.2.100 10.0.2.150;
}
}
Ce fichier doit commencer avec une section globale. Notez que chaque directive se termine par ;.
Cette ligne définit l'interface réseau pour le serveur DHCP
DHCPD_INTERFACE = "eth0";
Cette ligne définit le réseau pour lequel ce serveur est un serveur dhcp et déclare l'ouverture de la section de directives concernant ce réseau
subnet 10.0.2.0 netmask 255.255.255.0 {
Cette ligne définit le masque de sous-réseau
option subnet-mask 255.255.255.0;
Cette ligne définit la passerelle par défaut
option routers 10.0.2.2;
Cette ligne définit le serveur DNS de notre réseau :
option domain-name-servers 10.0.2.15;
Cette ligne définit le serveur DNS upstream :
option domain-name-servers 10.0.2.3;
Cette ligne définit le serveur d'horloge :
option ntp-servers 10.0.2.15;
Cette ligne nomme notre domaine :
option domain-name "fenestros.loc";
Cette ligne définit la valeur des baux par défaut :
default-lease-time 28800;
Cette ligne définit les valeur maximum des baux par défaut :
max-lease-time 86400;
Cette ligne stipule que le serveur ne tiendra pas compte d'une demande d'un client sur un segment de réseau autre que le sien :
not authoritative;
Cette ligne déclare la fermeture de la section spécifique au réseau 10.0.2.0 :
}
Cette ligne définit l'ouverture de la section de directives concernant la plage d'adresses disponibles pour les clients
pool {
Cette ligne définit la plage des adresses disponibles pour les clients
range 10.0.2.100 10.0.2.150;
Selon ce fichier de configuration, lorsque un client demande une adresse IP au serveur DHCP, le client reçois les informations suivantes :
Afin de suivre l'état des baux accordés, le serveur DHCP les inscrit dans le fichier /etc/dhcp.leases. Dans ce fichier, il faut noter que les heures indiquées sont en UTC (GMT).
<note tip> Pour plus d'information concernant les autres options du fichier dhcpd.conf, consultez la traduction en français du manuel de DHCPD qui se trouve à cette adresse. </note>
<html> <DIV ALIGN=“CENTER”> Copyright © 2004-2017 I2TCH LIMITED. </div> </html>