2.5. Using an LDAP directory as a lookup table
If you use a Lightweight Directory Access Protocol (LDAP) server to store accounts, domains or aliases, you can configure Postfix to use the LDAP server as a lookup table. By using LDAP instead of files for lookups enables you to have a central database.
Prerequisites
- You have the root access.
-
You have the
postfixpackage installed on your server. - You have an LDAP server with the required schema and user credentials.
-
You have the
postfix-ldapplugin installed on the server running Postfix.
Procedure
Configure the LDAP lookup parameters by creating a
/etc/postfix/ldap-aliases.cffile with the following content:Specify the hostname of the LDAP server:
server_host = ldap.example.comSpecify the base domain name for the LDAP search:
search_base = dc=example,dc=com-
Optional: Customize the LDAP search filter and attributes based on your requirements. The filter for searching the directory defaults to
query_filter = mailacceptinggeneralid=%s.
Enable the LDAP source as a lookup table in the
/etc/postfix/main.cfconfiguration file by adding the following content:virtual_alias_maps = ldap:/etc/postfix/ldap-aliases.cfVerify the LDAP configuration by running the
postmapcommand, which checks for any syntax errors or connectivity issues:# postmap -q @example.com ldap:/etc/postfix/ldap-aliases.cfReload the
postfixservice to apply the changes:# systemctl reload postfix
Verification
-
Send a test email to verify that the LDAP lookup works correctly. Check the mail logs in
/var/log/maillogfor any errors.