Port 389 is the LDAP port for directory lookups – user authentication, group membership, and address book queries. LDAP on port 389 transmits credentials in cleartext including bind passwords. Use LDAPS on port 636 or STARTTLS on port 389 for any production directory service.
Port Number
389
Protocol
TCP
Service
Lightweight Directory Access Protocol
Range
IANA Well-Known (0–1023)
Test anonymous bind (should fail if properly secured)
ldapsearch -H ldap://dc.example.com -x -b 'dc=example,dc=com' '(objectClass=user)' cn -LLL | head -20Test STARTTLS connection (-ZZ enforces TLS, fails if unavailable)
ldapsearch -H ldap://dc.example.com -x -ZZ -D 'cn=admin,dc=example,dc=com' -W -b 'dc=example,dc=com'Query LDAP root DSE (shows naming contexts, supported controls, server info)
nmap -p 389 --script ldap-rootdse targetTest LDAPS certificate chain and TLS version
openssl s_client -connect dc.example.com:636 -showcertsldapsearch -H ldap://dc.example.com -b 'dc=example,dc=com' '(uid=jdoe)'
ldapwhoami -H ldap://host -D 'cn=admin,dc=example,dc=com' -WLDAP (Lightweight Directory Access Protocol) was created in 1993 at the University of Michigan as a simpler alternative to the OSI X.500 DAP protocol. Port 389 was assigned by IANA. LDAPv3 (RFC 4511, 2006) added STARTTLS, SASL authentication, and schema extensibility. Microsoft adopted LDAP for Active Directory in Windows 2000 (1999). LDAP remains the backbone of enterprise authentication – nearly every corporate network uses port 389 or 636.
LDAP (389) vs LDAPS (636) vs STARTTLS – which should I use?
LDAPS (port 636): implicit TLS from first byte, no downgrade risk, simplest to configure. STARTTLS (port 389): upgrades plaintext connection to TLS mid-stream, susceptible to stripping attacks if client doesn't enforce. Recommendation: use LDAPS (636) for all new configurations. Microsoft is deprecating unencrypted LDAP: AD will require channel binding and LDAP signing by default in future Windows Server versions.
How do I prevent LDAP injection?
Sanitize all user input before constructing LDAP filters: escape these characters: * ( ) \ / NUL. Use parameterized LDAP queries (available in most LDAP client libraries). Never construct filters via string concatenation. Example vulnerable code: '(uid=' + username + ')'. Fixed: use ldap.filter.escape_filter_chars(username) then '(uid={0})'.format(escaped). Also enforce LDAP query result limits (sizelimit, timelimit).