Virtual aliases are how Postfix rewrites a recipient address to one or many other addresses — the forwarding fabric of a mail edge. This article is the reference we use when configuring forwards, role accounts (sales@, support@), distribution lists, catchalls, and BCC-style auditing. Pairs with postfix-transport-maps-routing for the routing side.
How to verify
sudo postconf | grep -E 'virtual_alias|recipient_bcc|sender_bcc|smtpd_recipient_restrictions'
sudo postmap -s hash:/etc/postfix/virtual 2>/dev/null | head -20
sudo postmap -q "postmaster@example.com" hash:/etc/postfix/virtual 2>/dev/null
postmap -q is the single most useful diagnostic — it asks the compiled map what it would return for a given key. If the answer doesn’t match what you wrote, the compile is stale.
What’s happening — alias semantics
Postfix has three address-rewriting layers, applied in order:
canonical_maps— rewrites the envelope and headers of mail entering or leaving the system (e.g.bob@internal.example.com→bob@example.comfor outbound).virtual_alias_maps— rewrites the recipient address during local resolution. The most common one. Operates on the envelope only.recipient_canonical_maps— rewrites just the envelopeRCPT TOafter virtual aliases resolve.
For day-to-day work, the one you touch is virtual_alias_maps. The map is the same key→value format as transport — keys are addresses or patterns, values are one or more comma-separated destinations.
Pattern matching for keys
user@example.com— exact match.@example.com— catchall for the domain. Lowest priority — only matches when nothing more specific does.@.example.com— catchall for the domain and all subdomains.user@— local part, any domain. Only matches when no fuller address matches.
The order of evaluation: full address first, then local-part@, then @domain, then @.parent.com.
Common alias shapes
1. Forward a single address
# /etc/postfix/virtual
alice@example.com alice.smith@gmail.com
Postfix replaces RCPT TO:alice@example.com with RCPT TO:alice.smith@gmail.com and re-runs delivery. No mail is stored locally.
2. Distribution list (group alias)
sales@example.com alice@example.com, bob@example.com, carol@example.com
Each recipient is independently delivered. If bob@ itself aliases elsewhere, the chain follows.
3. Role account that goes to a real mailbox
postmaster@example.com ops@example.com
abuse@example.com ops@example.com
hostmaster@example.com ops@example.com
The RFC-required role accounts (postmaster, abuse) MUST exist on every mail domain. Aliasing them to a real ops mailbox satisfies the requirement without provisioning the dedicated mailboxes.
4. Catchall — every unmatched address goes one place
@example.com ops@example.com
Catchalls are usually a bad idea (they accept spam to non-existent addresses, hurting reputation) but useful temporarily during a migration when you don’t know yet which addresses are valid. Keep them off for production.
5. Per-user-plus-tag forward
alice+invoices@example.com invoices-archive@example.com
Or with a regex for any + suffix:
# /etc/postfix/virtual-regex
/^alice\+(.+)@example\.com$/ alice@example.com
Then in main.cf:
virtual_alias_maps = hash:/etc/postfix/virtual,
regexp:/etc/postfix/virtual-regex
The regex map is processed in order alongside the hash map.
6. Recipient BCC for auditing
# /etc/postfix/recipient_bcc
ceo@example.com audit-archive@example.com
Then in main.cf:
recipient_bcc_maps = hash:/etc/postfix/recipient_bcc
Every message to ceo@example.com also delivers to audit-archive@. Same for sender_bcc_maps on outbound. Used for compliance archives.
The procedure
-
Write the alias file. One key→destination(s) per line:
sudo $EDITOR /etc/postfix/virtual -
Compile to hash database:
sudo postmap hash:/etc/postfix/virtual -
Wire into
main.cf:virtual_alias_maps = hash:/etc/postfix/virtual -
Reload and verify:
sudo postfix check sudo systemctl reload postfix sudo postmap -q "sales@example.com" hash:/etc/postfix/virtual -
Smoke-test the rewrite. Send a message and check the log:
echo "hello" | mail -s "alias test" sales@example.com sudo journalctl -u postfix | grep "sales@example.com" # Look for: ... to=<alice@example.com>, relay=local, ... orig_to=<sales@example.com>The
orig_tofield shows the alias resolution worked.
SQL-backed virtual aliases (PostfixAdmin)
In a PostfixAdmin install (see postfixadmin-virtual-domains), the alias map is a SQL lookup. /etc/postfix/sql/virtual-alias.cf:
user = postfix
password = pa-db-pw
hosts = 127.0.0.1
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active='1'
The alias table has address, goto, domain, active columns; UI adds and edits become live without a postmap step.
Recipient-level policies
smtpd_recipient_restrictions runs before virtual alias resolution. So reject_unknown_recipient_domain and reject_unverified_recipient check the envelope recipient, not the aliased one. If sales@example.com aliases to alice@gmail.com and Gmail is unreachable, reject_unverified_recipient would still pass — the check sees sales@example.com, which Postfix knows accepts.
This is why you keep alias maps and recipient policies as separate concerns: aliases shape delivery, policies shape acceptance.
Common pitfalls
- The map file is edited but
postmapwas forgotten; the change appears to do nothing. Always runpostmapafter editing a hash map, then verify withpostmap -q. - A catchall
@example.comis configured and specific aliases — the specific ones win, the catchall fires only for addresses no specific alias matched. Operators sometimes expect catchall to “BCC everything” — it doesn’t. - An alias points to another alias which points back — Postfix’s alias loop detection caps at 4 levels by default (
virtual_alias_recursion_limit); a loop hits the cap silently and the message bounces with5.4.6 Routing loop. - The alias file has CRLF line endings (from being edited on Windows);
postmapsilently treats some entries as garbled. Alwaysdos2unixmail config files. - A
regexp:map is evaluated for every address before being short-circuited by a match — heavy regex maps add measurable latency per message. Keep regex maps small and ordered most-likely-first.
Stack Harbor manages virtual aliases as the forwarding fabric of multi-tenant mail edges in the engagements we run — flat-file or SQL depending on deployment, every postmap step verified by a postmap -q smoke test, role accounts (postmaster/abuse) confirmed alive on every domain. If you have a mail server where forwards work for some users and not others and nobody knows why, that audit is part of our Managed Operations practice.