SkillPilotAI

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

DC locator: DNS SRV + LDAP ping
  1. 1.At login Netlogon calls DsGetDcName (what nltest /DSGETDC shows)

  2. 2.PC asks DNS for _ldap._tcp.<domain> SRV (site-specific _sites records if the site is known)

  3. 3.DNS returns DC01 and port 389

  4. 4.PC sends a small UDP LDAP ping to the candidate DCs

  5. 5.First DC to reply is used and cached by Netlogon

Kerberos: TGT + service ticket
  1. 1.At login the PC gets a TGT from the KDC on the DC (server krbtgt)

  2. 2.User opens a share on the file server

  3. 3.PC requests a service ticket for the SPN cifs/fileserver

  4. 4.PC shows that ticket to the file server

  5. 5.File server grants access using the groups inside the ticket

PowerShell
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.
Command Prompt
nltest /sc_query:corp.example.comnltest /sc_verify:corp.example.comnltest /sc_reset:corp.example.com\dc02nltest /server:PC042 /sc_query:corp.example.com
Output
nltest.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
OptionMeaning
/SC_QUERY:domainstatus and the DC in use (Status 0 = NERR_Success = healthy)
/SC_VERIFY:domainverify the channel (resets if broken)
/SC_RESET:domain[\dc]rebuild the channel, optionally to a specific DC
/SC_CHANGE_PWD:domainchange the computer account password

199.4 nltest: locating domain controllers

Command Prompt
nltest /dsgetdc:contoso.comnltest /dsgetdc:<domain_name> /forcenltest /dclist:fourthcoffeenltest /dsgetsitenltest /domain_trusts
Output
nltest /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.
Output
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
OptionUse
/DCLIST:domainall DCs with their sites ([PDC] marked)
/DCNAME:domainPDC name
/DSGETDC:domainDC name, IP, site, flags
/PDC /GC /KDC /WRITABLE /TIMESERV ...require a role
/FORCEskip cache, rediscover
/TRY_NEXT_CLOSEST_SITE, /SITE:Branch1site behaviour
/DNSGETDC:domainall 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).
Terminal
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
Output
$ 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: 3
Output
12: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

Output
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

Command Prompt
klist purgeklist get http/iisserver.contoso.com
Output
Cached 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.
Output
> 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 commandMeaning
klist / ticketscached tickets
tgtTGT details and time skew
purgedelete all tickets
get <SPN>request a service ticket (-kdcoptions, -cacheoptions)
sessions, -li 0x3e7logon sessions; 0x3e7 = SYSTEM (computer account tickets)
add_bind / query_bind / purge_bindpin Kerberos to a preferred DC
kcd_cache, cloud_debugdelegation cache; Entra / Hello debug

199.8 Linux lab: kinit, klist, kvno, kdestroy

Terminal
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
Output
[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.