Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 38 ยท Getting Started

Lab Setup and Tools for LDAP and AD

Build a safe practice lab with OpenLDAP or a Windows Server domain controller, and learn the essential tools: ldapsearch, ADUC, PowerShell and LDAP browsers.

The best way to learn directories is to touch one. This lesson shows how to build a safe practice lab and introduces the tools administrators use every day. You do not need to buy anything: free evaluation editions and open-source servers are enough.

The track's live examples run in your browser as Python stand-ins, but the commands in this lesson are the real thing. Run them in your own lab. Never practise on a production directory.

Choose your lab

You have two main options. Many learners do both.

Option What you need Best for
OpenLDAP in a container or Linux VM Docker or a small Linux machine LDAP protocol, LDIF, schema, filters
Windows Server domain controller A hypervisor (Hyper-V, VirtualBox, VMware) and an evaluation ISO Active Directory, Group Policy, Kerberos

An OpenLDAP lab with Docker

A quick way to get a working LDAP server is a container image. The command below starts the community osixia/openldap image (a widely used one; verify tags before use). It sets the organization and an admin password:

Terminal
docker run -d --name ldap-lab \
  -p 389:389 -p 636:636 \
  -e LDAP_ORGANISATION="Example Inc" \
  -e LDAP_DOMAIN="example.com" \
  -e LDAP_ADMIN_PASSWORD="admin-lab-only" \
  osixia/openldap:1.5.0

The base DN becomes dc=example,dc=com and the administrator DN cn=admin,dc=example,dc=com. Use throwaway passwords for a lab and never reuse a real one.

An Active Directory lab on Windows Server

  1. Download a Windows Server evaluation image from Microsoft's evaluation center (it is time limited, which is fine for learning).
  2. Create a virtual machine with 2 CPUs, 4 GB of RAM and a 60 GB disk. Give it a static IP address and set its own address as its DNS server.
  3. In Server Manager, choose Add roles and features and select Active Directory Domain Services.
  4. After the install, click the notification flag and choose Promote this server to a domain controller.
  5. Choose Add a new forest and enter a root domain name such as corp.example.test. Use a name you own or a reserved name such as .test, never a made-up top-level domain that could clash.
  6. Set a Directory Services Restore Mode (DSRM) password, accept the defaults and let the server restart.
  7. Add a Windows 10 or 11 client VM, point its DNS to the DC and join it to the domain.

The same promotion can be done in PowerShell:

POWERSHELL
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
Install-ADDSForest -DomainName "corp.example.test" -DomainNetbiosName "CORP" -InstallDns

Keep your lab on an isolated virtual network. A domain controller registers DNS records and offers DHCP-like behavior in some setups, and it should not be reachable from a production LAN.

Essential tools

ldapsearch and the OpenLDAP client tools

The OpenLDAP clients work against any LDAP server, including Active Directory. The most important commands:

Command Purpose
ldapsearch Search for entries
ldapadd Add entries from LDIF
ldapmodify Change entries from LDIF
ldapdelete Delete entries
ldappasswd Change a password
ldapwhoami Show which identity the server thinks you are

A first query against the lab server:

Terminal
ldapsearch -x -H ldap://localhost -D "cn=admin,dc=example,dc=com" -w admin-lab-only \
  -b "dc=example,dc=com" "(objectClass=*)"

The options mean: -x simple authentication, -H server URL, -D bind DN, -w password, -b search base and the last argument is the filter. You will study every part in the protocol chapter.

Active Directory tools

  • Active Directory Users and Computers (ADUC): the classic console for users, groups, computers and OUs. Start it with dsa.msc.
  • Active Directory Administrative Center (ADAC): a newer console with a PowerShell history pane.
  • Active Directory Sites and Services (dssite.msc) and Domains and Trusts (domain.msc).
  • Group Policy Management Console (gpmc.msc).
  • ADSI Edit (adsiedit.msc): a low-level editor that shows every attribute. Powerful and risky.
  • The Active Directory PowerShell module: commands such as Get-ADUser, New-ADUser and Get-ADGroupMember. It is the preferred way to automate.
  • Command-line utilities: dsquery, dsget, nltest, dcdiag, repadmin, klist and setspn.

A first PowerShell session in the lab:

POWERSHELL
Import-Module ActiveDirectory
Get-ADDomain
Get-ADUser -Filter * -Properties mail | Select-Object Name, SamAccountName, mail

Graphical LDAP browsers

If you prefer clicking, tools such as Apache Directory Studio and JXplorer let you browse the tree, edit entries and run filters. They are helpful for learning because you can see the whole structure at once.

Ports you should know

Network firewalls often cause "it does not work" problems. These are the standard ports:

Port Protocol Use
389 TCP and UDP LDAP and StartTLS
636 TCP LDAP over TLS (LDAPS)
3268 TCP Global Catalog (LDAP)
3269 TCP Global Catalog over TLS
88 TCP and UDP Kerberos
464 TCP and UDP Kerberos password change
53 TCP and UDP DNS
445 TCP SMB (SYSVOL, file shares)
135 and dynamic RPC TCP RPC endpoint mapper, replication

A command builder (Python stand-in)

Typing long ldapsearch commands is error-prone. This stand-in assembles one from parts and warns when a combination is risky. It only prints text; it does not connect to anything.

Python Build an ldapsearch command (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Lab hygiene

  • Take snapshots of your VMs before experiments so you can roll back.
  • Write down your lab passwords in a password manager, not in scripts you share.
  • Use a dedicated test domain name. Never join a lab machine to a real domain.
  • Practice backups and restores early. Chapter 8 covers them.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tool lets you search an LDAP directory from the command line?

    ldapsearch is the standard OpenLDAP client search tool and works with Active Directory too.
  2. 2. Which port does LDAP over TLS (LDAPS) use?

    LDAPS listens on 636. Port 389 is plain LDAP (with optional StartTLS).
  3. 3. Why give a lab domain controller a static IP and point it at itself for DNS?

    AD depends on DNS. A DC must have a stable address and resolve its own SRV records.
  4. 4. What does the -D option of ldapsearch specify?

    -D is the bind DN. -b is the base, -H the URL and the filter is the final argument.

Summary

  • Practise in an isolated lab: OpenLDAP in Docker for the protocol, a Windows Server evaluation VM for AD.
  • The OpenLDAP client tools (ldapsearch and friends) work with any LDAP server.
  • AD administrators use ADUC, ADAC, Sites and Services, GPMC and the ActiveDirectory PowerShell module.
  • Learn the key ports: 389, 636, 3268, 3269, 88, 53 and 445.
  • Use snapshots and throwaway credentials in every lab.

Next: The Directory Information Tree