Qué vas a conseguir
Los dos servicios que dan red a un equipo sin que nadie lo note: DHCP le da IP, puerta de enlace y DNS; DNS le dice dónde está cada servidor. Montados en Windows Server en un dominio, con dos servidores para que la caída de uno no deje sin red a la oficina, y el método para el ticket más típico: un equipo con una dirección 169.254.
Antes de empezar
- Los roles DNS Server y DHCP Server instalados (en un dominio, DNS suele vivir en los controladores de dominio) y la consola o los módulos
DnsServeryDhcpServerde PowerShell. - El plan de direccionamiento: qué subred es cada VLAN, cuál es su puerta de enlace y qué rango queda para IP fijas (servidores, impresoras, equipos de red).
1. DNS: zonas y registros
En un dominio, la zona es integrada en Active Directory: se replica con AD a todos los controladores de dominio, admite actualizaciones dinámicas seguras y no hay un servidor primario único que pueda caerse.
Get-DnsServerZone | Select-Object ZoneName, ZoneType, IsDsIntegrated, ReplicationScopeAdd-DnsServerPrimaryZone -NetworkId "10.20.0.0/16" -ReplicationScope DomainAdd-DnsServerResourceRecordA -ZoneName contoso.local -Name srv-app-01 -IPv4Address 10.20.5.40 -CreatePtrAdd-DnsServerResourceRecordCName -ZoneName contoso.local -Name intranet -HostNameAlias srv-app-01.contoso.localResolve-DnsName intranet.contoso.local -Server DC-01intranet.contoso.local CNAME 3600 Answer srv-app-01.contoso.localName : srv-app-01.contoso.localIPAddress : 10.20.5.40- A: nombre a IP. PTR: IP a nombre, en la zona inversa (
-CreatePtrlo crea a la vez). CNAME: un alias que apunta a otro nombre; útil para queintranetsobreviva a un cambio de servidor.
2. Reenviadores y limpieza
Lo que no es de tu dominio, el DNS interno lo pregunta fuera. Los reenviadores dicen a quién:
Get-DnsServerForwarderSet-DnsServerForwarder -IPAddress 10.0.0.53, 10.0.1.53La limpieza (scavenging) borra registros dinámicos de equipos que ya no existen. Sin ella, un nombre antiguo apunta a una IP que ahora tiene otro equipo.
- Se activa en la zona (Propiedades › General › Caducidad) y en un solo servidor (
Set-DnsServerScavenging -ScavengingState $true -ScavengingInterval 7.00:00:00). - Con los valores por defecto (7 días sin actualizar + 7 días de actualización), un registro que nadie renueva se borra pasados unos 14 días más el intervalo de limpieza.
- Los registros estáticos no tienen marca de tiempo y no se limpian.
3. DHCP: ámbito, exclusiones y opciones
Add-DhcpServerInDC -DnsName dhcp-01.contoso.local -IPAddress 10.20.1.10Add-DhcpServerv4Scope -Name "VLAN20 Usuarios P1" -StartRange 10.20.20.1 -EndRange 10.20.20.254 -SubnetMask 255.255.255.0 -LeaseDuration 8.00:00:00 -State ActiveAdd-DhcpServerv4ExclusionRange -ScopeId 10.20.20.0 -StartRange 10.20.20.1 -EndRange 10.20.20.20Set-DhcpServerv4OptionValue -ScopeId 10.20.20.0 -Router 10.20.20.1 -DnsServer 10.20.1.11, 10.20.1.12 -DnsDomain contoso.localAdd-DhcpServerv4Reservation -ScopeId 10.20.20.0 -IPAddress 10.20.20.30 -ClientId "00-1B-A9-3C-44-10" -Description "Impresora P1 Finanzas"- En un dominio, el servidor DHCP tiene que estar autorizado en AD (
Add-DhcpServerInDC); si no, no reparte. - La exclusión reserva el principio del rango para IP fijas, para que DHCP no las entregue.
- Las tres opciones que necesita cualquier equipo: 003 puerta de enlace (
-Router), 006 servidores DNS (-DnsServer) y 015 sufijo DNS (-DnsDomain). Un puesto con IP que no navega suele fallar en una de estas tres. - La reserva da siempre la misma IP a un equipo por su MAC: impresoras, terminales.
4. Conmutación por error entre dos servidores
Con DHCP failover, dos servidores comparten los ámbitos y sus concesiones. Si uno cae, el otro sigue repartiendo.
Add-DhcpServerv4Failover -ComputerName dhcp-01 -PartnerServer dhcp-02 -Name "DHCP01-DHCP02" -ScopeId 10.20.20.0 -LoadBalancePercent 50 -SharedSecret (Read-Host -AsSecureString "Secreto compartido")Get-DhcpServerv4Failover -ComputerName dhcp-01Invoke-DhcpServerv4FailoverReplication -ComputerName dhcp-01 -Name "DHCP01-DHCP02"- Equilibrio de carga (50/50) para dos servidores en la misma sede; espera activa (hot standby) cuando el segundo está en otro sitio y solo debe responder si cae el primero.
- Las concesiones se sincronizan solas, pero los cambios de configuración no: una reserva o una opción nueva se hace en un servidor y luego se replica (
Invoke-DhcpServerv4FailoverReplicationo Replicar ámbito en la consola).
5. El ticket: "el equipo tiene una IP 169.254 y no tiene red"
Una dirección 169.254.x.x (APIPA) significa que el equipo pidió IP por DHCP y nadie le contestó. El problema está entre el equipo y el servidor DHCP, no en el equipo.
ipconfig /all Autoconfiguration IPv4 Address. . : 169.254.81.12(Preferred) DHCP Enabled. . . . . . . . . . . : Yes Physical Address. . . . . . . . . : 3C-52-82-A1-0F-44Get-DhcpServerv4ScopeStatistics -ComputerName dhcp-01 | Select-Object ScopeId, Free, InUse, Reserved, PercentageInUseScopeId Free InUse Reserved PercentageInUse------- ---- ----- -------- ---------------10.20.20.0 0 234 1 10010.20.30.0 61 173 2 73,93Get-DhcpServerv4Lease -ComputerName dhcp-01 -ScopeId 10.20.20.0 | Sort-Object LeaseExpiryTime | Select-Object -First 5 IPAddress, HostName, ClientId, LeaseExpiryTimeSe descarta en este orden:
- El ámbito está lleno.
Free 0y 100 %. El servidor también deja el evento 1020 (el ámbito está al X por ciento) en el registro de DHCP Server. Si hay muchas concesiones de equipos que ya no están, reduce su duración; si el ámbito se ha quedado pequeño, ampliarlo es un cambio de red. - Una reserva mal hecha. Si el equipo tiene reserva, comprueba que la MAC coincide con la de
ipconfig /ally que la IP reservada no está ya usada por otro. - El relay. El servidor DHCP está en otra VLAN: las peticiones llegan gracias al ip helper-address en la interfaz de esa VLAN del switch o del router. Si es una VLAN nueva y nadie lo configuró, todos los equipos de esa VLAN salen con 169.254.
- El puerto del switch, en la VLAN equivocada o en err-disabled.
- Conflictos. Si alguien puso a mano una IP del rango, el equipo detecta el duplicado y rechaza la dirección; en la consola aparece como BAD_ADDRESS. Se excluye esa IP del ámbito y, si se repite,
Set-DhcpServerv4Setting -ConflictDetectionAttempts 1hace que el servidor haga ping antes de entregar.
Cuando la causa está corregida, en el equipo ipconfig /release y ipconfig /renew, y Resolve-DnsName srv-app-01 para confirmar que también resuelve.
Siguientes pasos
- La guía de Cisco: primeros comandos en un switch cubre el puerto en err-disabled y la VLAN del puesto, los dos puntos de red de la lista anterior.
- La guía de Windows Server de este mismo nivel explica cómo parchear los servidores DNS y DHCP sin cortar el servicio.
- El repositorio 19-ad-infra-health-check de mi GitHub reúne comprobaciones de salud de la infraestructura de AD.
¿Falta algo o en tu entorno es distinto? Escríbeme y lo corrijo.
What you'll get
The two services that give a device a network without anyone noticing: DHCP gives it an IP, gateway and DNS; DNS tells it where every server is. Set up on Windows Server in a domain, with two servers so losing one does not leave the office without a network, and the method for the most typical ticket: a device with a 169.254 address.
Before you start
- The DNS Server and DHCP Server roles installed (in a domain, DNS usually lives on the domain controllers) and the console or the
DnsServerandDhcpServerPowerShell modules. - The addressing plan: which subnet each VLAN is, its gateway, and which range is kept for fixed IPs (servers, printers, network equipment).
1. DNS: zones and records
In a domain, the zone is Active Directory-integrated: it replicates with AD to every domain controller, supports secure dynamic updates, and there is no single primary server that can go down.
Get-DnsServerZone | Select-Object ZoneName, ZoneType, IsDsIntegrated, ReplicationScopeAdd-DnsServerPrimaryZone -NetworkId "10.20.0.0/16" -ReplicationScope DomainAdd-DnsServerResourceRecordA -ZoneName contoso.local -Name srv-app-01 -IPv4Address 10.20.5.40 -CreatePtrAdd-DnsServerResourceRecordCName -ZoneName contoso.local -Name intranet -HostNameAlias srv-app-01.contoso.localResolve-DnsName intranet.contoso.local -Server DC-01intranet.contoso.local CNAME 3600 Answer srv-app-01.contoso.localName : srv-app-01.contoso.localIPAddress : 10.20.5.40- A: name to IP. PTR: IP to name, in the reverse zone (
-CreatePtrcreates it at the same time). CNAME: an alias pointing to another name; handy so thatintranetsurvives a server change.
2. Forwarders and scavenging
Whatever is not in your domain, internal DNS asks outside. Forwarders say who to ask:
Get-DnsServerForwarderSet-DnsServerForwarder -IPAddress 10.0.0.53, 10.0.1.53Scavenging deletes dynamic records of devices that no longer exist. Without it, an old name points at an IP another device now has.
- It is enabled on the zone (Properties › General › Aging) and on a single server (
Set-DnsServerScavenging -ScavengingState $true -ScavengingInterval 7.00:00:00). - With the default values (7 days no-refresh + 7 days refresh), a record nobody renews is deleted after about 14 days plus the scavenging interval.
- Static records have no timestamp and are not scavenged.
3. DHCP: scope, exclusions and options
Add-DhcpServerInDC -DnsName dhcp-01.contoso.local -IPAddress 10.20.1.10Add-DhcpServerv4Scope -Name "VLAN20 Users F1" -StartRange 10.20.20.1 -EndRange 10.20.20.254 -SubnetMask 255.255.255.0 -LeaseDuration 8.00:00:00 -State ActiveAdd-DhcpServerv4ExclusionRange -ScopeId 10.20.20.0 -StartRange 10.20.20.1 -EndRange 10.20.20.20Set-DhcpServerv4OptionValue -ScopeId 10.20.20.0 -Router 10.20.20.1 -DnsServer 10.20.1.11, 10.20.1.12 -DnsDomain contoso.localAdd-DhcpServerv4Reservation -ScopeId 10.20.20.0 -IPAddress 10.20.20.30 -ClientId "00-1B-A9-3C-44-10" -Description "Printer F1 Finance"- In a domain, the DHCP server has to be authorised in AD (
Add-DhcpServerInDC); otherwise it hands out nothing. - The exclusion keeps the start of the range for fixed IPs, so DHCP doesn't hand them out.
- The three options every device needs: 003 gateway (
-Router), 006 DNS servers (-DnsServer) and 015 DNS suffix (-DnsDomain). A desktop with an IP that can't browse usually fails on one of these three. - A reservation always gives the same IP to a device by its MAC: printers, terminals.
4. Failover between two servers
With DHCP failover, two servers share the scopes and their leases. If one goes down, the other keeps handing out addresses.
Add-DhcpServerv4Failover -ComputerName dhcp-01 -PartnerServer dhcp-02 -Name "DHCP01-DHCP02" -ScopeId 10.20.20.0 -LoadBalancePercent 50 -SharedSecret (Read-Host -AsSecureString "Shared secret")Get-DhcpServerv4Failover -ComputerName dhcp-01Invoke-DhcpServerv4FailoverReplication -ComputerName dhcp-01 -Name "DHCP01-DHCP02"- Load balance (50/50) for two servers on the same site; hot standby when the second one is elsewhere and should only answer if the first one fails.
- Leases sync by themselves, but configuration changes don't: a new reservation or option is made on one server and then replicated (
Invoke-DhcpServerv4FailoverReplicationor Replicate Scope in the console).
5. The ticket: "the device has a 169.254 IP and no network"
A 169.254.x.x address (APIPA) means the device asked for an IP over DHCP and nobody answered. The problem lies between the device and the DHCP server, not on the device.
ipconfig /all Autoconfiguration IPv4 Address. . : 169.254.81.12(Preferred) DHCP Enabled. . . . . . . . . . . : Yes Physical Address. . . . . . . . . : 3C-52-82-A1-0F-44Get-DhcpServerv4ScopeStatistics -ComputerName dhcp-01 | Select-Object ScopeId, Free, InUse, Reserved, PercentageInUseScopeId Free InUse Reserved PercentageInUse------- ---- ----- -------- ---------------10.20.20.0 0 234 1 10010.20.30.0 61 173 2 73.93Get-DhcpServerv4Lease -ComputerName dhcp-01 -ScopeId 10.20.20.0 | Sort-Object LeaseExpiryTime | Select-Object -First 5 IPAddress, HostName, ClientId, LeaseExpiryTimeRule things out in this order:
- The scope is full.
Free 0and 100 %. The server also logs event 1020 (scope is X percent full) in the DHCP Server log. If many leases belong to devices no longer around, shorten the lease duration; if the scope has become too small, enlarging it is a network change. - A wrong reservation. If the device has a reservation, check the MAC matches the one in
ipconfig /alland that the reserved IP is not already used by something else. - The relay. The DHCP server is in another VLAN: requests reach it thanks to the ip helper-address on that VLAN's interface on the switch or router. If it is a new VLAN and nobody configured it, every device in that VLAN gets 169.254.
- The switch port, in the wrong VLAN or in err-disabled.
- Conflicts. If someone set an IP from the range by hand, the device detects the duplicate and declines the address; in the console it shows as BAD_ADDRESS. Exclude that IP from the scope and, if it keeps happening,
Set-DhcpServerv4Setting -ConflictDetectionAttempts 1makes the server ping before handing an address out.
Once the cause is fixed, run ipconfig /release and ipconfig /renew on the device, and Resolve-DnsName srv-app-01 to confirm it also resolves.
Next steps
- The guide Cisco: first commands on a switch covers the port in err-disabled and the desk's VLAN, the two network points in the list above.
- The Windows Server guide at this same level explains how to patch DNS and DHCP servers without cutting the service.
- The 19-ad-infra-health-check repository on my GitHub brings together AD infrastructure health checks.
Is something missing, or different in your environment? Get in touch and I'll fix it.
Tech Career Lab · newsletter
¿Te ha servido? Cada dos semanas envío una idea práctica para perfiles IT: LinkedIn, proyectos, networking y procesos de selección.Found this useful? Every two weeks I send one practical idea for IT professionals: LinkedIn, projects, networking and hiring processes.
Apúntate y llévate las 33 ideasSign up and get the 33 ideas →