Diferencia entre revisiones de «DHCP»

De CURE - Informática
Ir a la navegación Ir a la búsqueda
m
 
(No se muestran 9 ediciones intermedias de 2 usuarios)
Línea 1: Línea 1:
−
DHCP
+
===Borrador===
−
Configuración de DHCP en router con firmware OPENWRT
 
  
−
Network->DHCP
+
===Objetivos===
−
Ahí agregamos una entrada nueva por cada zona distinta donde queremos dar el servicio de DHCP
+
Objetivos:
−
Elejimos:
+
* 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
+
  ...
−
http://www.networksorcery.com/enp/protocol/bootp/options.htm
+
  # 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===
 +
* 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.
 +
 
 +
[[Category:Descontinuadas]]

Revisión actual - 16:40 14 ene 2022

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.