DHCP

De CURE - Informática
Saltar a: navegación, buscar

Borrador

Objetivos

Objetivos:

  • instalar un servidor DHCP para asignar direcciones IP dinámicamente a una red.
  • verificar el funcionamiento.

Software

Instalar el paquete dhcp3-server, con Synaptic, aptitude o apt-get install.

Conceptos, comandos, archivos

Configuración.

  • Directorio de configuración: /etc/dhcpd/
  • Archivo principal de configuración: /etc/dhcpd/dhcpd.conf

Arrancar, ver estado, detener el servidor DHCP:

 sudo service dhcp3-server start | status | stop

Procedimiento

Ejemplo de una configuración simple:

  • Red: 192.168.3.0/24.
  • Servidor DHCP: 192.168.3.13.
  • Cliente: máquina con dhcp3-client instalado, verificar con
    dpkg -s dhcp3-client.

Una configuración elemental suficiente para muchas situaciones puede obtenerse agregando algunas líneas en /etc/dhcp3/dhcpd.conf de la máquina que actuará como servidor DHCP:

 #/etc/dhcpd/dhcpd.conf
 ...
 # have support for DDNS.)
 ddns-update-style none;
 
 # option definitions common to all supported networks...
 option domain-name "salatres.nsk.com.uy";
 option domain-name-servers localhost, ns3.salatres.nsk.com.uy ;
 
 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;
 
 # No service will be given on this subnet, but declaring it helps the 
 # DHCP server to understand the network topology.
 subnet 192.168.3.0 netmask 255.255.255.0 {
 }
   
 # This is a very basic subnet declaration.
 subnet 192.168.3.0 netmask 255.255.255.0 {
 range 192.168.3.150 192.168.3.200;
 option routers 192.168.3.13;
 }
 ...

Arrancar el servicio DHCP:

 sudo service dhcp3-server start

No debe dar errores. El archivo de log es /var/log/syslog.

Verificación

ADVERTENCIA: la configuración tradicional choca con la configuración moderna a través de NetworkManager; si NetworkManager está corriendo se debe deshabilitar: en la barra de menú, clic derecho en ícono de red, desmarcar "Activar red".

net-tools

Crear una entrada para la interfaz eth0 en /etc/network/interfaces, declarando DHCP como modo de obtener una IP. Opcional: allow-hotplug hace que la interfaz levante en el momento en que se conecte un cable.

 # /etc/network/interfaces
 ...
 allow-hotplug eth0
 iface eth0 inet dhcp
 ...

Levantar la interfaz eth0 configurada, comando ifup:

 victor@mya-arenaria:~$ sudo ifup eth0 
 Internet Systems Consortium DHCP Client V3.1.3
 Copyright 2004-2009 Internet Systems Consortium.
 All rights reserved.
 For info, please visit https://www.isc.org/software/dhcp/
 
 Listening on LPF/eth0/6c:62:6d:2e:16:53
 Sending on   LPF/eth0/6c:62:6d:2e:16:53
 Sending on   Socket/fallback
 DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
 DHCPOFFER of 192.168.3.150 from 192.168.3.13
 DHCPREQUEST of 192.168.3.150 on eth0 to 255.255.255.255 port 67
 DHCPACK of 192.168.3.150 from 192.168.3.13
 bound to 192.168.3.150 -- renewal in 283 seconds.
 ssh stop/waiting
 ssh start/running, process 2711
 victor@mya-arenaria:~$ 

Verificar conectividad al servidor DHCP:

 victor@mya-arenaria:~$ ping -c3 192.168.3.13
 PING 192.168.3.13 (192.168.3.13) 56(84) bytes of data.
 64 bytes from 192.168.3.13: icmp_seq=1 ttl=64 time=0.363 ms
 64 bytes from 192.168.3.13: icmp_seq=2 ttl=64 time=0.304 ms
 64 bytes from 192.168.3.13: icmp_seq=3 ttl=64 time=0.268 ms
 --- 192.168.3.13 ping statistics ---
 3 packets transmitted, 3 received, 0% packet loss, time 1998ms
 rtt min/avg/max/mdev = 0.268/0.311/0.363/0.044 ms

Bajar la interfaz eth0 configurada, comando ifdown:

 victor@mya-arenaria:~$ sudo ifdown eth0 
 There is already a pid file /var/run/dhclient.eth0.pid with pid 2675
 killed old client process, removed PID file
 Internet Systems Consortium DHCP Client V3.1.3
 Copyright 2004-2009 Internet Systems Consortium.
 All rights reserved.
 For info, please visit https://www.isc.org/software/dhcp/
 Listening on LPF/eth0/6c:62:6d:2e:16:53
 Sending on   LPF/eth0/6c:62:6d:2e:16:53
 Sending on   Socket/fallback
 DHCPRELEASE on eth0 to 192.168.3.13 port 67
 victor@mya-arenaria:~$

NetworkManager

Crear una conexión de red para la tarjeta Ethernet en NetworkManager, indicando DHCP.

Notas adicionales

Referencias


Créditos: notas de Víctor González Barbone.