DNS and DHCP explained: set them up on Windows Server, and fix ‘can’t join the domain’

DHCP hands every device on your network an address; DNS turns names into addresses. In a Windows domain, both usually run on the domain controller, and when either is set up wrong, things fail in confusing ways: PCs that can’t join the domain, slow sign-ins, printers that vanish. This guide explains how both work and sets them up on Windows Server with PowerShell, then gives a test for failed domain joins.

1. How DHCP gives a PC its address (DORA)

  1. Discover: the PC, with no address yet, broadcasts “is there a DHCP server?”
  2. Offer: a server offers a free address, e.g. 192.168.10.105.
  3. Request: the PC asks for that address (and any other server that answered sees it wasn’t chosen).
  4. Acknowledge: the server confirms. The address is the PC’s for the lease time (8 days by default on Windows Server); the PC renews at half-time.

DHCP uses broadcasts on UDP ports 67 and 68. If a Windows PC gets no answer at all, it gives itself an address in 169.254.x.x: that always means “no DHCP server answered”, not a DNS problem.

2. What a lease contains

  • IP address and subnet mask
  • Option 003, Router: the default gateway
  • Option 006, DNS Servers: in a domain, only your domain controllers. Never the router or a public DNS server.
  • Option 015, DNS Domain Name: e.g. howitwork.local

3. Set up DHCP on Windows Server

Example network: 192.168.10.0/24, router 192.168.10.1, domain controller DC01 at 192.168.10.10. Addresses 1 to 99 are kept for servers, printers and switches.

# Install the role
Install-WindowsFeature DHCP -IncludeManagementTools

# Authorise the server in Active Directory (needs Enterprise Admin rights)
Add-DhcpServerInDC -DnsName dc01.howitwork.local -IPAddress 192.168.10.10

# The scope: addresses to lend, and the lease time
Add-DhcpServerv4Scope -Name "Office LAN" -StartRange 192.168.10.100 -EndRange 192.168.10.200 -SubnetMask 255.255.255.0 -LeaseDuration 8.00:00:00

# Options 003, 006 and 015
Set-DhcpServerv4OptionValue -ScopeId 192.168.10.0 -Router 192.168.10.1 -DnsServer 192.168.10.10 -DnsDomain howitwork.local

# A reservation: the printer always gets .50 (use its real MAC address)
Add-DhcpServerv4Reservation -ScopeId 192.168.10.0 -IPAddress 192.168.10.50 -ClientId "00-11-22-33-44-55" -Description "Reception printer"

Never type a static address on a device inside the scope (here 100 to 200): DHCP will eventually lend the same address to another device. Use a reservation, keep statics outside the range, or add an exclusion range with Add-DhcpServerv4ExclusionRange.

4. How a DNS lookup works

  1. The PC checks its own DNS cache (entries from the hosts file are loaded into it too).
  2. It asks the DNS server it got from DHCP: your domain controller.
  3. The DC answers names in howitwork.local itself, from its zone.
  4. For internet names, the DC asks its forwarders (or the root servers).
  5. Both the server and the PC cache the answer for the record’s TTL. ipconfig /flushdns clears the PC’s cache.

5. Records you’ll see in the zone

  • A: name to IPv4 address (dc01 → 192.168.10.10).
  • CNAME: an alias (intranet → web01).
  • MX: where email for a domain is delivered.
  • PTR: address to name, in a reverse zone.
  • SRV: where a service runs. The _msdcs, _sites, _tcp and _udp folders hold the records PCs use to find domain controllers. The Netlogon service on each DC registers them. Don’t delete them.

6. Why Active Directory needs DNS

To join the domain, sign a user in, or download Group Policy, a PC must find a domain controller. It asks DNS for the SRV record _ldap._tcp.dc._msdcs.howitwork.local. Only your own DNS server knows that record. A PC that uses the router or 8.8.8.8 for DNS gets no answer, and you see “An Active Directory Domain Controller (AD DC) for the domain could not be contacted”.

7. Set up DNS on the domain controller

# Reverse zone for the office subnet, stored in AD
Add-DnsServerPrimaryZone -NetworkId "192.168.10.0/24" -ReplicationScope Forest

# A record (and PTR) for a server with a fixed address
Add-DnsServerResourceRecordA -ZoneName howitwork.local -Name web01 -IPv4Address 192.168.10.20 -CreatePtr

# Forwarders: the right place for public DNS servers
Add-DnsServerForwarder -IPAddress 1.1.1.1, 8.8.8.8

# Test: can DNS find the domain controllers?
Resolve-DnsName -Type SRV _ldap._tcp.dc._msdcs.howitwork.local

Windows PCs register their own A records. You only add records by hand for servers and devices that don’t.

8. The 60-second test: a PC can’t join the domain

  1. ipconfig /all: the address must not be 169.254.x.x, and the DNS server must be your DC (and only your DCs).
  2. nslookup howitwork.local: should return your domain controllers. “Non-existent domain” means the PC is asking the wrong DNS server.
  3. nslookup -type=SRV _ldap._tcp.dc._msdcs.howitwork.local: the lookup the join really does. If the DCs are listed, DNS is fine; check the firewall and the clock next.
  4. Fix DNS (in the DHCP scope options, not by hand on each PC), then ipconfig /flushdns and join again: Add-Computer -DomainName howitwork.local -Restart

9. Four mistakes in small office networks

  • Public DNS on PCs or on the DC’s network card, even as the second DNS server. Public DNS belongs in forwarders only.
  • Two DHCP servers: Windows and the internet router both handing out addresses. Turn DHCP off on the router.
  • Static addresses inside the DHCP range. Use reservations.
  • One domain controller for everything. Add a second DC with DNS, list it as the second DNS server in option 006, and set up DHCP failover (Add-DhcpServerv4Failover) between the two.

Practise it free

Install the Windows Server evaluation in a virtual machine, promote it to a domain controller, build the scope, reverse zone and forwarders above, then set a client’s DNS to 8.8.8.8 on purpose and watch the domain join fail. Fix it with the 60-second test.

Related guides: Active Directory explained · Group Policy basics

More IT guides · howITwork on YouTube