Cómo montar un servidor DHCP

Esta es una forma sencilla de instalar y configurar un servidor DHCP en una máquina Linux (Red-Hat, CentOS, Fedora). Voy a mostraros los pasos para hacerlo y una configuración básica para hacer funcionar el equipo como servidor DHCP.

DHCP (sigla en inglés de Dynamic Host Configuration Protocol – Protocolo Configuración Dinámica de Servidor) es un protocolo de red que permite a los nodos de una red IP obtener sus parámetros de configuración automáticamente. Se trata de un protocolo de tipo cliente/servidor en el que generalmente un servidor posee una lista de direcciones IP dinámicas y las va asignando a los clientes conforme éstas van estando libres, sabiendo en todo momento quién ha estado en posesión de esa IP, cuánto tiempo la ha tenido y a quién se la ha asignado después. (Wikipedia)

En primera instancia, instalamos el paquete necesario vía yum:

yum install dhcp.i586

Una vez instalado, podemos utilizar como base para el fichero de configuración el que nos ofrecen con la instalación. Incorpora comentarios sobre cada una de las opciones y configuraciones para hacer más sencilla la puesta en marcha del servicio:

cp /usr/share/doc/dhcp-4.1.0p1/dhcpd.conf.sample /etc/dhcp/dhcp.conf

El fichero de ejemplo es el siguiente:


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

Veréis que es un fichero con muchísimas opciones, os dejo un ejemplo más sencillo. En el siguiente dhcp.conf utilizamos la interfaz de red eth0 para las tareas de DHCP, esta interfaz tiene configurada la red 192.168.0.0/24 (subnet), sobre la cual vamos a reservar las IPs desde la 192.168.0.200 a la 192.168.0.220 para las asignaciones DHCP (range).

Esto es lo más básico, respecto a las distintas opciones añadidas en el fichero sample de configuración véis especificado lo que es cada cosa:

ddns-update-style none;
ddns-updates off;
deny client-updates;
one-lease-per-client false;
allow bootp;
option T150 code 150 = string;

subnet 192.168.0.0 netmask 255.255.255.0 {
interface eth0;
range 192.168.0.200 192.168.0.220;
option subnet-mask 255.255.255.0;
default-lease-time 6000;
max-lease-time 7200;
option time-offset -3600;
}

Finalmente, arrancamos el servicio:

/etc/init.d/dhcp start

Y el log (en mi caso vuelca a messages):

Oct 23 19:35:37 sylv1006 dhcpd: Internet Systems Consortium DHCP Server 4.1.0p1
Oct 23 19:35:37 sylv1006 dhcpd: Copyright 2004-2009 Internet Systems Consortium.
Oct 23 19:35:37 sylv1006 dhcpd: All rights reserved.
Oct 23 19:35:37 sylv1006 dhcpd: For info, please visit http://www.isc.org/sw/dhcp/
Oct 23 19:35:37 sylv1006 dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Oct 23 19:35:47 sylv1006 dhcpd: Internet Systems Consortium DHCP Server 4.1.0p1
Oct 23 19:35:47 sylv1006 dhcpd: Copyright 2004-2009 Internet Systems Consortium.
Oct 23 19:35:47 sylv1006 dhcpd: All rights reserved.
Oct 23 19:35:47 sylv1006 dhcpd: For info, please visit http://www.isc.org/sw/dhcp/
Oct 23 19:35:47 sylv1006 dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Oct 23 19:35:47 sylv1006 dhcpd: Wrote 0 leases to leases file.
Oct 23 19:35:47 sylv1006 dhcpd: Listening on LPF/eth0/00:16:3e:1d:36:42/192.168.0.0/24
Oct 23 19:35:47 sylv1006 dhcpd: Sending on   LPF/eth0/00:16:3e:1d:36:42/192.168.0./24
Oct 23 19:35:47 sylv1006 dhcpd: Sending on   Socket/fallback/fallback-net

Ahora que todo funciona correctamente, podemos configurar DHCP para que arranque automáticamente:

chkconfig dhcpd on

9 comentarios en “Cómo montar un servidor DHCP

  1. hola, muy exelente solo que hy una duda, ya manejando linux ya no es necesario meter otro servidor como proxy para las salidas al exterior en el caso de una empresa?
    2-.como bloqueo los puertos como las de pornografia y mensajeros en linux?

    agradezco tu ayuda que me puedas ofrecer. mi correo es gabrielj_f@hotmail.com

  2. Hola Gabriel,

    no hay puertos específicos para la pornografía, entiendo que lo que quieres es filtrar el contenido, para ello supongo que lo más adecuado es utilizar un proxy, de este modo controlas lo que quieres que se pueda accede y lo que no. Revise Squid a ver si te sirve:

    http://www.gulix.cl/wiki/Proxy_squid

  3. Hola tengo todo el archivo de dhcp.conf y bien configurado.

    El problema que estoy teniendo es:

    Conectado a mi tarjeta de red eth0 es el modem de TelMex que está con DHCP de .1.x y la otra tarjeta estaría con mi dhcp (eth1), el cual está asignando IP de .30.x.
    De hecho en los nodos el servidor DHCP me está asignando los IPs pero sin salida de internet. He estado revisando la tabla de ruteo pero aun asi, sigo son mala suerte. Los nodos de la red .30.x no tiene acesso a la web. Me podría decir desde que punto voy mal por favor, gracias?

  4. Hola Alex, asi es. de hecho aquí esta mi confoguración:

    server-identifier servidor.red-cyo.net;
    ddns-update-style interim;
    ignore client-updates;
    authoritative;
    default-lease-time 900;
    max-lease-time 7200;
    option ip-forwarding off;
    option domain-name «red-cyo.net»;

    # Copiar tan cual contenido del fichero /etc/rndc.key
    # Ésto se utiliza para posteriormente, poder comunicar el servidor DHCP con el
    # servidor DNS, y poder gestionar zonas dinámicas desde el servidor DHCP.
    # Jamás utilizar la clave ejemplificada a continuación para producción.
    key «rndckey» {
    algorithm hmac-md5;
    secret «Ab7M6BqFi94hb3cHVhlLkJlFcXwy4gra6Vusw2fI7ebQh25hFln7Oz87wpbC»;
    };

    shared-network miredcyo {
    subnet 192.168.30.0 netmask 255.255.255.0 {
    option routers 192.168.30.1;
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.30.18;
    option domain-name-servers 8.8.8.8, 8.8.4.4;
    option netbios-name-servers 192.168.30.1;
    option ntp-servers 200.23.51.205, 132.248.81.29, 148.234.7.30;
    range 192.168.30.2 192.168.30.11;
    }
    host cyo {
    option host-name «cyo.red-cyo.net»;
    hardware ethernet 00:xx:xx:xx:xx:xx;
    fixed-address 192.168.30.12;
    }
    host comproom {
    option host-name «comproom.red-cyo.net»;
    hardware ethernet 00:xx:xx:xx:xx:xx;
    fixed-address 192.168.30.13;
    }
    host teacher {
    option host-name «teacher.red-cyo.net»;
    hardware ethernet 00:xx:xx:xx:xx:xx;
    fixed-address 172.16.30.14;
    }
    host nemax {
    option host-name «nemax.red-cyo.net»;
    hardware ethernet 00:xx:xx:xx:xx:xx;
    fixed-address 192.168.30.15;
    }
    host apeng {
    option host-name «apeng.red-cyo.net»;
    hardware ethernet 00:xx:xx:xx:xx:xx;
    fixed-address 192.168.30.16;
    }
    host repeatereng {
    option host-name «repeatereng.red-cyo.net»;
    hardware ethernet 00:xx:xx:xx:xx:xx;
    fixed-address 192.168.30.17;
    }
    }

    Es lo que tengo en mi archivo, dhcpd.conf.

    Por favor ayudame. gracias

Comments are closed.