Diferencia entre revisiones de «DHCP»

De CURE - Informática
Ir a la navegación Ir a la búsqueda
Línea 1: Línea 1:
== DHCP ==
+
==Servidor DHCP==
Configuración de DHCP en router con firmware OPENWRT
 
  
Network->DHCP
+
===Borrador===
  
Ahí agregamos una entrada nueva por cada zona distinta donde queremos dar el servicio de DHCP
+
===Objetivos===
Elejimos:
+
Objetivos:
 +
* instalar un servidor DHCP para asignar direcciones IP dinámicamente a una red.
 +
* verificar el funcionamiento.
  
* Interfaz: la interfaz por donde queremos que se de el servicio de DHCP, ejemplo: wlan
+
===Software===
* Start: a partir de que ip empieza a entregar (sólo el último octeto), ej: 2 (empieza a entregar a partir de la xxx.xxx.xxx.2)
+
Instalar el paquete dhcp3-server, con Synaptic, aptitude o apt-get install.
* Limit: última ip que entrega no incluida (sólo el último octeto), ej: 100 (última a entregar xxx.xxx.xxx.99)
 
* Leasetime: tiempo que recervará la ip entregada para la misma mac, ej: 5h (5 horas) ó 20m (20 minutos)
 
* Dynamic DHCP: si no está marcado, solo entregará ips a las mac que tengan recervada una ip, Static Leases (se muestra en el siguiente punto).
 
* DHCP-Options:
 
**3,xxx.xxx.xxx.xxx -> para asignar un gateway distinto al de por defecto
 
**6,xxx.xxx.xxx.xxx -> para asignar un DNS distinto al de por defecto
 
**15,dominio -> para asignar un nombre de dominio
 
**Static Leases: se puede hacer que el servidor DHCP siempre entregue la misma ip a la misma mac, esto se hace agregando un nombre, la dirección mac y la ip a asignar.
 
  
 +
===Conceptos, comandos, archivos===
 +
Configuración.
 +
* Directorio de configuración: /etc/dhcpd/
 +
* Archivo principal de configuración: /etc/dhcpd/dhcpd.conf
  
Para reinicar el servicio de dhcp:
+
Arrancar, ver estado, detener el servidor DHCP:
/etc/init.d/dnsmasq stop
+
  sudo service dhcp3-server start | status | stop
/etc/init.d/dnsmasq start
 
  
Agrego una muestra del archivo /etc/config/dhcp:
+
===Procedimiento===
  
config 'dnsmasq'
+
Ejemplo de una configuración simple:
option 'domainneeded' '1'
+
* Red: 192.168.3.0/24.
option 'boguspriv' '1'
+
* Servidor DHCP: 192.168.3.13.
option 'filterwin2k' '0'
+
* Cliente: máquina con dhcp3-client instalado, verificar con <br><code>dpkg -s dhcp3-client</code>.
option 'localise_queries' '1'
 
option 'rebind_protection' '1'
 
option 'rebind_localhost' '1'
 
option 'local' '/lan/'
 
option 'domain' 'lan'
 
option 'expandhosts' '1'
 
option 'nonegcache' '0'
 
option 'authoritative' '1'
 
option 'readethers' '1'
 
option 'leasefile' '/tmp/dhcp.leases'
 
option 'resolvfile' '/tmp/resolv.conf.auto'
 
 
config 'dhcp' 'wan'
 
option 'interface' 'wan'
 
option 'ignore' '1'
 
option 'dynamicdhcp' '0'
 
 
config 'dhcp' 'lan1'
 
option 'start' '2'
 
option 'limit' '250'
 
option 'leasetime' '5h'
 
option 'dynamicdhcp' '1'
 
option 'interface' 'lan1'
 
list 'dhcp_option' '3,10.5.1.1' # de esta forma se puede asignar la gateway, sino se asigna por defecto
 
list 'dhcp_option' '6,200.40.30.245' # de esta forma se puede asignar el DNS, sino se asigna por defecto, si son mas de uno, agregar una coma y la IP del otro servidor DNS (6,200.40.30.245,200.40.220.245).
 
 
config 'host'
 
option 'name' 'Equipo8'
 
option 'mac' '00:22:68:58:b4:66'
 
option 'ip' '10.5.1.8'
 
 
config 'dhcp' 'wlan'
 
option 'interface' 'wlan'
 
option 'start' '2'
 
option 'limit' '100'
 
option 'leasetime' '1h'
 
  
Aclaración: toda la configuración de DHCP va en este archivo y NO en /etc/config/dnsmasq y tampoco en /etc/ethers. NO es recomendable tocar estos archivos y tampoco editar /etc/dhcp, usar la interfaz web. Siempre hacer un respado de la configuración del router antes de cambiar algo, System->Backup y restore opción Create backup
+
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:
  
==Referencia:==
+
  #/etc/dhcpd/dhcpd.conf
http://element.edoceo.com/howto/dnsmasq
+
  ...
 +
  # 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;
 +
  }
 +
  ...
  
http://www.networksorcery.com/enp/protocol/bootp/options.htm
+
Arrancar el servicio DHCP:
 +
  sudo service dhcp3-server start
 +
No debe dar errores. El archivo de log es /var/log/syslog.
  
== Verificación ==
+
===Verificación===
Desde una pc conectada a la red:
 
* dando click con el botón derecho sobre el icono [[Archivo:lan_icon.png]] de (en Ubuntu) Network Manager-> Información de la conexión obtener la siguiente información:
 
[[Archivo:informacion de conexion lan.png]]
 
  
**dirección ip: 10.5.AAA.BBB (donde AAA y BBB son un número entre 2 y 254)
+
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".
**dirección de difusión: 10.5.AAA.255
+
 
**mascara de subred: 255.255.255.0
+
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.
**ruta predeterminada: 10.5.AAA.1
+
 
**DNS primario: 10.5.2.2
+
  # /etc/network/interfaces
* los valores de AAA serán:
+
  ...
**1: si pertenecen a la red de Laboratorio
+
  allow-hotplug eth0
**3: si pertenecen a la red Wi-Fi
+
  iface eth0 inet dhcp
**4: si pertenecen a la red de Secretaría
+
  ...
**5: si pertenecen a la red de Docentes, delegados, públicas
+
 
 +
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:~$
 +
 
 +
===Notas adicionales===
 +
 
 +
===Referencias===
 +
* Linux Server How To - Install DHCPD Using Apt-get,<br>http://www.linuxserverhowto.com/linux-dhcp-server/install-dhcpd-linux-dhcp-server-using-apt-get.html
 +
* Debian Reference, Capítulo 5, Network setup,<br>http://www.debian.org/doc/manuals/debian-reference/ch05.en.html
 +
 
 +
----
 +
Créditos: notas de Víctor González Barbone.

Revisión del 13:20 20 nov 2011

Servidor DHCP

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".

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:~$ 

Notas adicionales

Referencias


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