nltest and klist
nltest and klist are the two key tools for troubleshooting a Windows domain: nltest talks to the Netlogon service (find a DC, check the computer's secure channel, sites, trusts), and klist shows and manages the Kerberos tickets of your logon session. Use them when a laptop logs in slowly, cannot reach the domain, or gets access denied on a share.
199.1 Why is it used?
- Find out which DC a PC uses and why (site, flags), and force rediscovery.
- Check and repair the secure channel behind 'trust relationship failed'.
- See, request and purge Kerberos tickets after group changes or SPN issues.
- klist is built into every Windows; nltest ships with Windows Server, RSAT and Windows 11.
- On the office PC only help was run (output scanned for host/user/domain/IP: zero hits); other outputs are Microsoft docs examples and a Linux lab.
199.2 How it works
- Step 1
1.At login Netlogon calls DsGetDcName (what nltest /DSGETDC shows)
- Step 2
2.PC asks DNS for _ldap._tcp.<domain> SRV (site-specific _sites records if the site is known)
- Step 3
3.DNS returns DC01 and port 389
- Step 4
4.PC sends a small UDP LDAP ping to the candidate DCs
- Step 5
5.First DC to reply is used and cached by Netlogon
- Step 1
1.At login the PC gets a TGT from the KDC on the DC (server krbtgt)
- Step 2
2.User opens a share on the file server
- Step 3
3.PC requests a service ticket for the SPN cifs/fileserver
- Step 4
4.PC shows that ticket to the file server
- Step 5
5.File server grants access using the groups inside the ticket
nltest /?klist -?199.3 nltest: Netlogon and secure channel
- /SERVER:dc01 runs the query on another machine; /QUERY shows Netlogon status.
- /REPL, /SYNC, /PDC_REPL are NT4 BDC replication: practically unused in today's AD.
- Secure channel: built at domain join with the computer account password between PC and DC.
nltest /sc_query:corp.example.comnltest /sc_verify:corp.example.comnltest /sc_reset:corp.example.com\dc02nltest /server:PC042 /sc_query:corp.example.comnltest.exe /server:fourthcoffee-dc-01 /sc_query:fourthcoffeeFlags: 30 HAS_IP HAS_TIMESERVTrusted DC Name \\fourthcoffee-dc-01.forthcoffee.comTrusted DC Connection Status Status = 0 0x0 NERR_SuccessThe command completed successfully| Option | Meaning |
|---|---|
| /SC_QUERY:domain | status and the DC in use (Status 0 = NERR_Success = healthy) |
| /SC_VERIFY:domain | verify the channel (resets if broken) |
| /SC_RESET:domain[\dc] | rebuild the channel, optionally to a specific DC |
| /SC_CHANGE_PWD:domain | change the computer account password |
199.4 nltest: locating domain controllers
nltest /dsgetdc:contoso.comnltest /dsgetdc:<domain_name> /forcenltest /dclist:fourthcoffeenltest /dsgetsitenltest /domain_trustsnltest /dsgetdc:<domain_name> /force DC: \\<dc_address> Address: \\<dc_address> Dc Site name: Default-First-site-NameOur Site Name: Default-First-site-Name Flags: PDC GC DS LDAP KDC TIMESERV WRITABLE DNS_DC DNS_DOMAIN DNS_FOREST CLOSE_SITE FULL_SECRET WS DS_8 DS_9 DS_10 KEYLISTThe command completed successfully- Flags: GC = global catalog, KDC, WRITABLE (not RODC), CLOSE_SITE = DC is in your own site; DS_8/DS_9/DS_10 = minimum OS version.
nltest /dclist:fourthcoffeeGet list of DCs in domain 'ntdev' from '\\fourthcoffee-dc-01'. fourthcoffee-dc-01.forthcoffee.com [DS] Site: Rome fourthcoffee-dc-03.forthcoffee.com [DS] Site: LasVegas fourthcoffee-dc-09.forthcoffee.com [DS] Site: NYC fourthcoffee-dc-99.forthcoffee.com [DS] Site: Redmond fourthcoffee-dc-63.forthcoffee.com [PDC] [DS] Site: LondonThe command completed successfully| Option | Use |
|---|---|
| /DCLIST:domain | all DCs with their sites ([PDC] marked) |
| /DCNAME:domain | PDC name |
| /DSGETDC:domain | DC name, IP, site, flags |
| /PDC /GC /KDC /WRITABLE /TIMESERV ... | require a role |
| /FORCE | skip cache, rediscover |
| /TRY_NEXT_CLOSEST_SITE, /SITE:Branch1 | site behaviour |
| /DNSGETDC:domain | all DC records registered in DNS |
199.5 Linux lab: the DC locator on the wire
- Docker: dc container with lab DNS (dnsmasq), MIT Kerberos KDC and LDAP; client 192.168.219.20.
- _ldap._tcp.lab.local returns dc (priority 0) and dc2; _kerberos SRV records point to dc.lab.local:88.
- SiteA site record exists, SiteB is NXDOMAIN (the case where Windows tries the next closest site); example.com is REFUSED (no upstream, nothing leaves the lab).
dig @192.168.219.10 _ldap._tcp.lab.local SRV +noall +answerdig _ldap._tcp.dc._msdcs.lab.local SRV +noall +answerdig _kerberos._tcp.lab.local SRV +noall +answerdig _kerberos._udp.lab.local SRV +noall +answerdig _ldap._tcp.SiteB._sites.lab.local SRV +noall +commentsldapsearch -x -H ldap://dc.lab.local -s base \ -b '' -LLL namingContexts supportedLDAPVersion$ dig _kerberos._tcp.lab.local SRV +noall +answer_kerberos._tcp.lab.local. 0 IN SRV 0 100 88 dc.lab.local.$ dig _kerberos._udp.lab.local SRV +noall +answer_kerberos._udp.lab.local. 0 IN SRV 0 100 88 dc.lab.local.$ ldapsearch -x -H ldap://dc.lab.local -s base -b '' -LLL namingContexts supportedLDAPVersiondn:namingContexts: dc=lab,dc=localsupportedLDAPVersion: 312:44:03 dnsmasq[77]: query[SRV] _ldap._tcp.lab.local from 192.168.219.2012:44:03 dnsmasq[77]: config _ldap._tcp.lab.local is <SRV>12:44:18 dnsmasq[77]: query[SRV] _ldap._tcp.SiteB._sites.lab.local from 192.168.219.2012:44:18 dnsmasq[77]: config _ldap._tcp.SiteB._sites.lab.local is NXDOMAIN12:44:20 dnsmasq[77]: query[A] example.com from 192.168.219.2012:44:26 dnsmasq[77]: query[SRV] _kerberos._udp.LAB.LOCAL from 192.168.219.2012:44:26 dnsmasq[77]: config _kerberos._udp.LAB.LOCAL is <SRV>199.6 nltest: sites, trusts, DNS and debugging
nltest /dsgetsiteDefault-First-Site-NameThe command completed successfully nltest /domain_trustsList of domain trusts: 0: forthcoffee forthcoffee.com (NT 5) (Forest Tree Root) (Primary Domain)The command completed successfully- /DSGETSITE = this PC's AD site; /DSGETSITECOV = sites a DC covers; /DSADDRESSTOSITE maps IPs to sites; /PARENTDOMAIN.
- /DOMAIN_TRUSTS (+ /PRIMARY, /FOREST, /DIRECT_IN, /DIRECT_OUT, /ALL_TRUSTS /V); /WHOWILL:CORP* alice tests if a logon will work; /FINDUSER.
- /DSREGDNS re-registers a DC's SRV records, /DSDEREGDNS removes a dead DC's records, /DSQUERYDNS shows the last update.
- /DBFLAG:0x2080ffff turns on verbose netlogon.log in the debug folder (0x0 turns it off).
199.7 klist: Kerberos ticket cache
klist purgeklist get http/iisserver.contoso.comCached Tickets: (2)#0> Client: John @ CONTOSO.COM Server: krbtgt/CONTOSO.COM @ CONTOSO.COM KerbTicket Encryption Type: AES-256-CTS-HMAC-SHA1-96 Kdc Called: DCA.contoso.com#1> Client: John @ CONTOSO.COM Server: http/iisserver.contoso.com @ CONTOSO.COM Ticket Flags 0x40a10000 -> forwardable renewable pre_authent name_canonicalize Kdc Called: DCA.contoso.com- #0 is the krbtgt TGT, #1 the HTTP service ticket; Kdc Called shows which DC issued them; flags show forwardable, renewable, pre_authent.
> klist -?Usage: klist.exe [command]Command list: [tickets] [-lh <LogonId.HighPart>] [-li <LogonId.LowPart>] tgt [-lh <LogonId.HighPart>] [-li <LogonId.LowPart>] purge [-lh <LogonId.HighPart>] [-li <LogonId.LowPart>] sessions [-lh <LogonId.HighPart>] [-li <LogonId.LowPart>] kcd_cache [-lh <LogonId.HighPart>] [-li <LogonId.LowPart>] get <SPN> [-lh <LogonId.HighPart>] [-li <LogonId.LowPart>] [-kdcoptions <options>] [-cacheoptions <options>] add_bind <DOMAIN> <DC> query_bind purge_bind cloud_debug| klist command | Meaning |
|---|---|
| klist / tickets | cached tickets |
| tgt | TGT details and time skew |
| purge | delete all tickets |
| get <SPN> | request a service ticket (-kdcoptions, -cacheoptions) |
| sessions, -li 0x3e7 | logon sessions; 0x3e7 = SYSTEM (computer account tickets) |
| add_bind / query_bind / purge_bind | pin Kerberos to a preferred DC |
| kcd_cache, cloud_debug | delegation cache; Entra / Hello debug |
199.8 Linux lab: kinit, klist, kvno, kdestroy
echo asha-krb-199 | KRB5_TRACE=/dev/stdout kinit asha | grep -E 'Looking|DNS|Sending|Received|Response was'klistkvno ldap/dc.lab.local cifs/files.lab.localklist -f -ekdestroy; klist[135] 1794228266.921649: Sending request (178 bytes) to LAB.LOCAL[135] 1794228266.921657: Sending initial UDP request to dgram 192.168.219.10:88[135] 1794228266.921658: Received answer (223 bytes) from dgram 192.168.219.10:88[135] 1794228266.921664: Received error from KDC: -1765328359/Additional pre-authentication required$ kdestroy; klistklist: No credentials cache found (filename: /tmp/krb5cc_0)- krb5.conf has no KDC address, so kinit finds the KDC through the _kerberos SRV records and sends to 192.168.219.10:88; first reply asks for pre-authentication.
- kvno = Windows klist get (service tickets for ldap/ and cifs/ SPNs); kdestroy = klist purge.
199.9 Common mistakes
- Thinking 'trust relationship failed' is the user's password: it is the computer account's secure channel (e.g. VM restored from an old snapshot). Fix with /SC_RESET or rejoin, not a user password reset.
- New group membership but still access denied: the old ticket still has old groups. klist purge (and klist -li 0x3e7 purge for the computer), then reconnect or log off/on.
- Forgetting /FORCE: nltest returns the cached DC.
- Ignoring time skew: Kerberos fails if clocks differ too much (klist tgt shows skew).
199.10 Interview tips
- DC locator: Netlogon -> DsGetDcName -> DNS SRV _ldap._tcp.<domain> (+ _sites) -> UDP LDAP ping on 389 -> first reply wins, cached.
- Check it with nltest /DSGETDC:<domain> /FORCE.
- Secure channel: /SC_QUERY, /SC_VERIFY, /SC_RESET.
- Kerberos: TGT from krbtgt, service ticket per SPN (cifs/server); klist get / purge.
- Group change not applied = stale ticket.