manuales:servidor_dhcp
Diferencias
Muestra las diferencias entre dos versiones de la página.
Próxima revisión | Revisión previa | ||
manuales:servidor_dhcp [2010/03/22 14:49] – creado cayu | manuales:servidor_dhcp [2010/12/01 15:12] (actual) – cayu | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
====== Servicio DHCP ====== | ====== Servicio DHCP ====== | ||
+ | |||
+ | **DHCP** (sigla en inglés de **D**ynamic **H**ost **C**onfiguration **P**rotocol) 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/ | ||
+ | |||
Veremos como configurar un servidor DHCP con alta disponibilidad y configuracion replicada por medio de Cscync2 | Veremos como configurar un servidor DHCP con alta disponibilidad y configuracion replicada por medio de Cscync2 | ||
+ | |||
+ | |||
+ | |||
+ | Para el esquema distribuido de configuracion DHCP tuvieron que modificarse parámetros de configuración de dicho servicio. | ||
+ | |||
+ | En la directiva wpad: se utilizo un nombre para indicar la ubicación del archivo de autoconfiguración del proxy, y en cada red dicha entrada DNS puede variar. | ||
+ | |||
+ | La configuracion de subredes y de hosts fijos se separo en diferentes archivos para una mejor edición por parte de los administradores | ||
+ | |||
+ | ==== Configuracion DHCP ==== | ||
+ | |||
+ | |||
+ | Configuracion | ||
+ | |||
+ | |||
+ | == / | ||
+ | |||
+ | <code java> | ||
+ | authoritative; | ||
+ | option netbios-name-servers 10.1.203.32; | ||
+ | option wpad code 252 = text; | ||
+ | option wpad " | ||
+ | |||
+ | ddns-update-style none; | ||
+ | |||
+ | # | ||
+ | include "/ | ||
+ | |||
+ | include "/ | ||
+ | include "/ | ||
+ | </ | ||
+ | |||
+ | == / | ||
+ | |||
+ | <code java> | ||
+ | failover peer " | ||
+ | secondary; | ||
+ | address 10.1.100.10; | ||
+ | port 519; | ||
+ | peer address 10.1.100.11; | ||
+ | peer port 519; | ||
+ | max-response-delay 60; | ||
+ | max-unacked-updates 10; | ||
+ | load balance max seconds 3; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | == / | ||
+ | |||
+ | |||
+ | <code javascript> | ||
+ | function FindProxyForURL(url, | ||
+ | |||
+ | if(dnsDomainIs(host, | ||
+ | if(dnsDomainIs(host, | ||
+ | if(shExpMatch(host, | ||
+ | if(isInNet(host, | ||
+ | if(isInNet(host, | ||
+ | if(isInNet(host, | ||
+ | if(isInNet(host, | ||
+ | if(isInNet(host, | ||
+ | |||
+ | if(isInNet(myIpAddress(), | ||
+ | |||
+ | if(isInNet(myIpAddress(), | ||
+ | if(isInNet(myIpAddress(), | ||
+ | |||
+ | |||
+ | return "PROXY proxybuenosaires.cayu.com.ar: | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | Segun desde que red nos conectemos nos asigna un proxy diferente | ||
+ | |||
+ | |||
+ | |||
+ | **MENSAJES DE LOG** | ||
+ | |||
+ | ^^Mensaje^Quien lo envia^Descripcion^^ | ||
+ | |DHCPDISCOVER|Cliente|Envía un mensaje de difusión para localizar a los servidores DHCP activos| | ||
+ | |DHCPOFFER|Servidor|Responde con una oferta de parámetros de configuración conforme a la situación del cliente| | ||
+ | |DHCPREQUEST|Cliente|Solicita los parámetros ofrecidos, en caso de que el mensaje del servidor haya sido aceptado, \\ rechazando la oferta, si el mensaje del servidor ha sido desestimado o confirmando \\ la solicitud de una dirección IP obtenida anteriormente| | ||
+ | |DHCPACK|Servidor|Mensaje de confirmación y cierre, indicando los parámetros definitivos| | ||
+ | |DHCPNACK|Servidor|Informe de que la dirección IP que solicita no es válida para la subred en la que se encuentra \\ o ya no la puede asignar porque la tiene otro equipo. | | ||
+ | |DHCPDECLINE|Cliente|Informe de que la dirección está en uso, normalmente porque otro usuario ha asignado \\ esa dirección manualmente| | ||
+ | |DHCPRELEASE|Cliente|Informe de que ha finalizado el uso de la dirección IP| | ||
+ | |DHCPINFORM|Cliente|Consulta sobre la configuración local. El cliente ya está configurado cuando envía este mensaje| | ||
+ | |||
+ | |||
+ | ===== Software instalado ===== | ||
+ | |||
+ | ^^Nombre^Version^Descripcion^ | ||
+ | |Kernel|2.6.18-8.el5xen|Nucleo| | ||
+ | |RedHat|Red Hat Enterprise Linux Server release 5|Distribucion Linux| | ||
+ | |System Imager|4.0.2|Cliente de System Imager| | ||
+ | |Internet Systems Consortium DHCP|3.0.5|Servidor de DHCP| | ||
+ | |nss_ldap|253-3|Autenticacion LDAP para PAM| | ||
+ | |||
+ | ===== Archivo de configuración principal - dhcpd.conf ===== | ||
+ | |||
+ | * **authoritative** - Supone que la configuración correcta para la red es la definida en el servidor DHCP y tratará de reasignar datos a los clientes mal configurados. Este parámetro puede ser global o asigando a una declaración de subred. Los cambios realizados en en servidor marcado como authoritative tienen una rápida propagación en la subred ya que se reconfigura cualquier cliente con la antigua configuración | ||
+ | |||
+ | * **option netbios-name-servers 10.1.200.3** - Define la dirección del servidor WINS para NetBios | ||
+ | |||
+ | * Web Proxy Autodiscovery Protocol (WPAD)es un método usado por los navegadores, | ||
+ | * **option wpad code 252 = text** | ||
+ | * **option wpad " | ||
+ | |||
+ | * **ddns-update-style none** activa o desactiva la actualización DNS con los valores asignados mediante DHCP. | ||
+ | |||
+ | * Inclusión de los demás archivos de configuración generales | ||
+ | * **include "/ | ||
+ | * **include "/ | ||
+ | * **include "/ | ||
+ | | ||
+ | ==== Archivo de configuración de failover - dhcpd.peer ==== | ||
+ | |||
+ | Dentro de este archivo configuraremos la disponibilidad ante fallos | ||
+ | |||
+ | |||
+ | * **secondary - primary** Si nos encontramos en el servidor primario pondremos secondary, especificando que nos referimos al secundario y viceverza | ||
+ | |||
+ | * **address 10.1.1.11 - address 10.1.1.10** La dirección propia del servidor local desde el cual estamos ejecutando el servicio | ||
+ | |||
+ | * **port 519** Puerto de escucha del servicio | ||
+ | |||
+ | * **peer address 10.1.1.11 - peer address 10.1.1.10** Dirección propia del servidor local desde el cual estamos ejecutando el servicio | ||
+ | |||
+ | * **peer port 519** Puerto de escucha del servicio del servidor local desde el cual estamos ejecutando el servicio | ||
+ | |||
+ | * **max-response-delay 60** | ||
+ | |||
+ | * **max-unacked-updates 2592000** | ||
+ | |||
+ | * **mclt 2592000** | ||
+ | |||
+ | * **split 128** | ||
+ | |||
+ | * **load balance max seconds 3** | ||
+ | |||
+ | ===== Notas ===== | ||
+ | |||
+ | //Script para genera un archivo de configuracion con muchas subnets, del rango 10.216.64.0 al 10.216.98.0, | ||
+ | |||
+ | <code php> | ||
+ | authoritative; | ||
+ | ddns-update-style interim; | ||
+ | ignore client-updates; | ||
+ | <?php | ||
+ | for($i = 64; $i <= 98; $i++) { | ||
+ | print " | ||
+ | subnet 10.216." | ||
+ | option subnet-mask 255.255.255.0; | ||
+ | option domain-name-servers 10.1.200.10, | ||
+ | option routers 10.216." | ||
+ | option subnet-mask 255.255.255.0; | ||
+ | max-lease-time 86400; | ||
+ | default-lease-time 86400; | ||
+ | pool { | ||
+ | max-lease-time 86400; | ||
+ | default-lease-time 86400; | ||
+ | range 10.216." | ||
+ | deny dynamic bootp clients; | ||
+ | } | ||
+ | } | ||
+ | "; | ||
+ | } | ||
+ | ?> | ||
+ | |||
+ | </ | ||
+ | |||
+ | //Script para verificar la cantidad de leases activos expirados y abandonados// | ||
+ | |||
+ | <code perl> | ||
+ | # | ||
+ | # | ||
+ | # script to list active, expired and abandoned leases. | ||
+ | # | ||
+ | # Original script received by Ian Jones, ltjones@hawkeye.ualr.edu | ||
+ | # | ||
+ | # Current Version by Rainer Krienke, krienke@uni-koblenz.de | ||
+ | # Version 1.0 | ||
+ | # Added: - output in local timezone | ||
+ | # - output in HTML using -w option | ||
+ | # - eliminate double entries for same ip address | ||
+ | # | ||
+ | # TL: Rework for nslu2/ | ||
+ | # | ||
+ | # Break out clients & addresses. | ||
+ | # | ||
+ | # Add a script to copy to / | ||
+ | |||
+ | use Getopt:: | ||
+ | use Date:: | ||
+ | use CGI; | ||
+ | |||
+ | # Look for Options | ||
+ | $res=getopts(' | ||
+ | |||
+ | # Echo help message | ||
+ | if( $opt_h || $res =="" | ||
+ | die "$0 [-w] List active and expired DHCP leases \n", | ||
+ | " | ||
+ | "\t -w: output is not written in HTML format.\n\n"; | ||
+ | } | ||
+ | |||
+ | $abandonedc = 0; | ||
+ | $leasesc = 0; | ||
+ | $expiredc = 0; | ||
+ | |||
+ | # Find local host name -- from IP address if possible. | ||
+ | |||
+ | $ipName = `localhost`; | ||
+ | open(CFG, "/ | ||
+ | while ($line = < | ||
+ | next if ( $line =~ /^\s*#/o ); | ||
+ | $mline = $line; | ||
+ | chomp($mline); | ||
+ | @wds = split( ' | ||
+ | next if ( $wds[0] ne " | ||
+ | $ipAddr = $wds[1]; | ||
+ | @numbers = split(/\./, $ipAddr); | ||
+ | $ip_number = pack(" | ||
+ | ($ipName) = (gethostbyaddr($ip_number, | ||
+ | } | ||
+ | close(CFG); | ||
+ | chomp($localhost = $ipName); | ||
+ | |||
+ | # | ||
+ | # Format (see man date) in that the expiration date is echoed. | ||
+ | # Select the format of your choice. If you want the lease time to | ||
+ | # be printed in amarican style put a comment char ``#'' | ||
+ | # front of the first $outputDateFormat line and remove it from the | ||
+ | # second one. | ||
+ | # | ||
+ | # European Style date | ||
+ | # | ||
+ | |||
+ | # American style date | ||
+ | $outputDateFormat=" | ||
+ | |||
+ | # ### point this to your dhcpd.leases ### | ||
+ | # / | ||
+ | # will be seachred by default. | ||
+ | # | ||
+ | $LEASEFILE = "/ | ||
+ | if( ! -r $LEASEFILE ){ | ||
+ | if( -r "/ | ||
+ | $LEASEFILE="/ | ||
+ | }else{ | ||
+ | die " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # ### get universal date from system | ||
+ | # | ||
+ | $xTZ = & | ||
+ | $tz=& | ||
+ | $x=Date_ConvTZ($xTZ, | ||
+ | |||
+ | open(LEASES, | ||
+ | $inlease = 0; | ||
+ | |||
+ | while ($line = < | ||
+ | next if( $line =~ /^\s*#/o ); | ||
+ | $mline = $line; | ||
+ | chomp($mline); | ||
+ | $mline=~ s/ / /g; | ||
+ | |||
+ | @wds = split( ' ', | ||
+ | if( !$inlease ) { | ||
+ | # Look for a lease record | ||
+ | next if( $wds[0] ne " | ||
+ | $ipAddr = $wds[1]; | ||
+ | @numbers = split(/\./, $ipAddr); | ||
+ | $ip_number = pack(" | ||
+ | ($ipName) = (gethostbyaddr($ip_number, | ||
+ | if ($ipName) { | ||
+ | ; | ||
+ | } else { | ||
+ | | ||
+ | } | ||
+ | $startDt = "< | ||
+ | $endDt = "< | ||
+ | $endNever = 0; | ||
+ | $ddnsClient = "< | ||
+ | $ethAddr = "< | ||
+ | $hostName = "< | ||
+ | $leaseState = "< | ||
+ | $leaseAbandoned = 0; | ||
+ | $inlease = 1; | ||
+ | next; | ||
+ | } | ||
+ | # Parse each clause in lease | ||
+ | if( $wds[0] eq " | ||
+ | $startDt = join( ' ', $wds[2], $wds[3] ); | ||
+ | $startDt=~s/; | ||
+ | # Parse Date in Date::Manip internel format | ||
+ | $startDtUTC=ParseDate($startDt); | ||
+ | # | ||
+ | # Convert it to local timezone | ||
+ | $startDtTZ=Date_ConvTZ($startDtUTC," | ||
+ | # | ||
+ | # Finally make a human readable date string out of it | ||
+ | $startDt=UnixDate($startDtTZ, | ||
+ | next; | ||
+ | } | ||
+ | if( $wds[0] eq " | ||
+ | if( $wds[2] eq " | ||
+ | $endDt = " | ||
+ | $endNever = 1; | ||
+ | } else { | ||
+ | $endDt = join( ' ', $wds[2], $wds[3] ); | ||
+ | $endDt=~s/; | ||
+ | } | ||
+ | # Parse Date in Date::Manip internel format | ||
+ | $endDtUTC=ParseDate($endDt); | ||
+ | # | ||
+ | # Convert it to local timezone | ||
+ | $endDtTZ=Date_ConvTZ($endDtUTC," | ||
+ | # | ||
+ | # Finally make a human readable date string out of it | ||
+ | $endDt=UnixDate($endDtTZ, | ||
+ | next; | ||
+ | } | ||
+ | if( $wds[0] eq " | ||
+ | $ethAddr = $wds[2]; | ||
+ | $ethAddr=~s/; | ||
+ | next; | ||
+ | } | ||
+ | if( $wds[0] eq " | ||
+ | $hostName = $wds[1]; | ||
+ | $hostName=~s/; | ||
+ | $hostName=~ s/"// | ||
+ | next; | ||
+ | } | ||
+ | if( $wds[0] eq " | ||
+ | $leaseState = $wds[2]; | ||
+ | $leaseState=~s/; | ||
+ | next; | ||
+ | } | ||
+ | if( $wds[0] eq " | ||
+ | if( $wds[1] eq " | ||
+ | $ddnsClient = $wds[3]; | ||
+ | $ddnsClient=~s/"// | ||
+ | } | ||
+ | } | ||
+ | if( $wds[0] eq " | ||
+ | $leaseAbandoned = 1; | ||
+ | next; | ||
+ | } | ||
+ | if( $wds[0] ne " | ||
+ | next; | ||
+ | } | ||
+ | |||
+ | ## End of lease data, generate output | ||
+ | |||
+ | $inlease = 0; | ||
+ | |||
+ | if( $ipName eq "< | ||
+ | $ipName = $ddnsClient; | ||
+ | } | ||
+ | |||
+ | $endDt = " | ||
+ | $lease = sprintf "%-17s %-15s %-19s %-19s %-25s %s\n", | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | $ClientLeases{$ethAddr} = $lease; | ||
+ | $ClientLeaseTime{$ethAddr} = $endDtUTC; | ||
+ | $ClientLeaseState{$ethAddr} = $leaseState; | ||
+ | |||
+ | if( $leaseAbandoned ) { | ||
+ | # Unexpectedly found someone with this address | ||
+ | $AbandonedAddresses[$abandonedc++] = $lease; | ||
+ | next; | ||
+ | } | ||
+ | |||
+ | if( $leaseState eq " | ||
+ | $ActiveLeases{$ipAddr} = $lease; | ||
+ | } else { | ||
+ | $ExpiredLease{$ipAddr} = $lease; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | close(LEASES); | ||
+ | |||
+ | if( !$opt_w ){ | ||
+ | $|=1; | ||
+ | $q = new CGI; | ||
+ | print $q-> | ||
+ | print $q-> | ||
+ | -expires=>' | ||
+ | -status=>' | ||
+ | -BGCOLOR=>' | ||
+ | print "< | ||
+ | } | ||
+ | |||
+ | # Sort each hash & return the keys for in-order access | ||
+ | |||
+ | @ClientKeys = sort(keys(%ClientLeases)); | ||
+ | @ActiveKeys = sort(keys(%ActiveLeases)); | ||
+ | @ExpiredKeys = sort(keys(%ExpiredLeases)); | ||
+ | @abandoned = sort(@abandoned); | ||
+ | |||
+ | $xDate=UnixDate($xTZ, | ||
+ | print "DHCP leases issued by $localhost as of $xDate\n"; | ||
+ | |||
+ | $actc = 0; | ||
+ | print " | ||
+ | foreach $i ( @ClientKeys ) { | ||
+ | next if( $ClientLeaseState{$i} ne " | ||
+ | |||
+ | if( $actc++ == 0 ) { | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " ---------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------------"; | ||
+ | print " --------------------"; | ||
+ | print " | ||
+ | } | ||
+ | print $ClientLeases{$i}; | ||
+ | } | ||
+ | if( $actc == 0 ) { | ||
+ | printf " None\n"; | ||
+ | } else { | ||
+ | printf "Total active clients: %d\n", $actc; | ||
+ | } | ||
+ | |||
+ | $iactc = 0; | ||
+ | print " | ||
+ | foreach $i ( @ClientKeys ) { | ||
+ | next if( $ClientLeaseState{$i} eq " | ||
+ | |||
+ | if( $iactc++ == 0 ) { | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " ---------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------------"; | ||
+ | print " --------------------"; | ||
+ | print " | ||
+ | } | ||
+ | print $ClientLeases{$i}; | ||
+ | } | ||
+ | if( $iactc == 0 ) { | ||
+ | printf " None\n"; | ||
+ | } else { | ||
+ | printf "Total inactive clients: %d\n", $iactc; | ||
+ | } | ||
+ | |||
+ | $actn = 0; | ||
+ | print " | ||
+ | foreach $i ( @ActiveKeys ) { | ||
+ | if( $actn++ == 0 ) { | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " ---------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------------"; | ||
+ | print " --------------------"; | ||
+ | print " | ||
+ | } | ||
+ | print $ActiveLeases{$i}; | ||
+ | } | ||
+ | if( $actn == 0 ) { | ||
+ | printf " None\n"; | ||
+ | } else { | ||
+ | printf "Total Active: %d\n", $actn; | ||
+ | } | ||
+ | |||
+ | $expn = 0; | ||
+ | print " | ||
+ | foreach $i ( @ExpiredKeys ) { | ||
+ | @wds = split( ' ', $ExpiredLeases{$i}); | ||
+ | if( !defined($ActiveLeaseTime{$wds[1]}) ) { | ||
+ | if( $expn++ == 0 ) { | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " ---------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------------"; | ||
+ | print " --------------------"; | ||
+ | print " | ||
+ | } | ||
+ | print $ExpiredLeases{$i}; | ||
+ | } | ||
+ | } | ||
+ | if( $expn == 0 ) { | ||
+ | printf " None\n"; | ||
+ | } else { | ||
+ | printf "Total expired: %d\n", $expn; | ||
+ | } | ||
+ | |||
+ | $abdn = 0; | ||
+ | print " | ||
+ | foreach $i ( @abandoned ) { | ||
+ | if( $abdn++ == 0 ) { | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " ---------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------"; | ||
+ | print " -------------------------"; | ||
+ | print " --------------------"; | ||
+ | print " | ||
+ | } | ||
+ | print $i; | ||
+ | } | ||
+ | if( $abdn == 0 ) { | ||
+ | printf " None\n"; | ||
+ | } else { | ||
+ | printf "Total abandoned: %d\n", $abdn; | ||
+ | } | ||
+ | |||
+ | printf " | ||
+ | |||
+ | if( !$opt_w ){ | ||
+ | print "</ | ||
+ | $me = $q-> | ||
+ | print $q-> | ||
+ | print $q-> | ||
+ | print $q-> | ||
+ | print $q-> | ||
+ | } | ||
+ | # Last line of / | ||
+ | </ | ||
+ |
manuales/servidor_dhcp.1269269375.txt.gz · Última modificación: 2010/03/22 14:49 por cayu