1
PPoossttffiixx SSttaannddaarrdd CCoonnffiigguurraattiioonn EExxaammpplleess
3
-------------------------------------------------------------------------------
5
PPuurrppoossee ooff tthhiiss ddooccuummeenntt
7
This document presents a number of typical Postfix configurations. This
8
document should be reviewed after you have followed the basic configuration
9
steps as described in the BASIC_CONFIGURATION_README document. In particular,
10
do not proceed here if you don't already have Postfix working for local mail
11
submission and for local mail delivery.
13
The first part of this document presents standard configurations that each
14
solve one specific problem.
16
* Postfix on a stand-alone Internet host
17
* Postfix on a null client
18
* Postfix on a local network
19
* Postfix email firewall/gateway
21
The second part of this document presents additional configurations for hosts
22
in specific environments.
24
* Delivering some but not all accounts locally
25
* Running Postfix behind a firewall
26
* Configuring Postfix as MX host for a remote site
27
* Postfix on a dialup machine
28
* Postfix on hosts without a real hostname
30
PPoossttffiixx oonn aa ssttaanndd--aalloonnee IInntteerrnneett hhoosstt
32
Postfix should work out of the box without change on a stand-alone machine that
33
has direct Internet access. At least, that is how Postfix installs when you
34
download the Postfix source code via http://www.postfix.org/.
36
You can use the command "postconf -n" to find out what settings are overruled
37
by your main.cf. Besides a few pathname settings, few parameters should be set
38
on a stand-alone box, beyond what is covered in the BASIC_CONFIGURATION_README
42
# Optional: send mail as user@domainname instead of user@hostname.
45
# Optional: specify NAT/proxy external address.
46
#proxy_interfaces = 1.2.3.4
48
# Don't relay mail from other hosts.
49
mynetworks_style = host
52
See also the section "Postfix on hosts without a real hostname" if this is
53
applicable to your configuration.
55
PPoossttffiixx oonn aa nnuullll cclliieenntt
57
A null client is a machine that can only send mail. It receives no mail from
58
the network, and it does not deliver any mail locally. A null client typically
59
uses POP, IMAP or NFS for mailbox access.
61
In this example we assume that the Internet domain name is "example.com" and
62
that the machine is named "nullclient.example.com". As usual, the examples show
63
only parameters that are not left at their default settings.
65
1 /etc/postfix/main.cf:
66
2 myorigin = $mydomain
67
3 relayhost = $mydomain
68
4 inet_interfaces = 127.0.0.1
69
5 local_transport = error:local delivery is disabled
71
7 /etc/postfix/master.cf:
72
8 Comment out the local delivery agent entry
76
* Line 2: Send mail as "user@example.com" (instead of
77
"user@nullclient.example.com"), so that nothing ever has a reason to send
78
mail to "user@nullclient.example.com".
80
* Line 3: Forward all mail to the mail server that is responsible for the
81
"example.com" domain. This prevents mail from getting stuck on the null
82
client if it is turned off while some remote destination is unreachable.
84
* Line 4: Do not accept mail from the network.
86
* Lines 5-8: Disable local mail delivery. All mail goes to the mail server as
89
PPoossttffiixx oonn aa llooccaall nneettwwoorrkk
91
This section describes a local area network environment of one main server and
92
multiple other systems that send and receive email. As usual we assume that the
93
Internet domain name is "example.com". All systems are configured to send mail
94
as "user@example.com", and all systems receive mail for
95
"user@hostname.example.com". The main server also receives mail for
96
"user@example.com". We call this machine by the name of mailhost.example.com.
98
A drawback of sending mail as "user@example.com" is that mail for "root" and
99
other system accounts is also sent to the central mailhost. See the section
100
"Delivering some but not all accounts locally" below for possible solutions.
102
As usual, the examples show only parameters that are not left at their default
105
First we present the non-mailhost configuration, because it is the simpler one.
106
This machine sends mail as "user@example.com" and is final destination for
107
"user@hostname.example.com".
109
1 /etc/postfix/main.cf:
110
2 myorigin = $mydomain
111
3 mynetworks = 127.0.0.0/8 10.0.0.0/24
113
5 # Optional: forward all non-local mail to mailhost
114
6 #relayhost = $mydomain
118
* Line 2: Send mail as "user@example.com".
120
* Line 3: Specify the trusted networks.
122
* Line 4: This host does not relay mail from untrusted networks.
124
* Line 6: This is needed if no direct Internet access is available. See also
125
below, "Postfix behind a firewall".
127
Next we present the mailhost configuration. This machine sends mail as
128
"user@example.com" and is final destination for "user@hostname.example.com" as
129
well as "user@example.com".
132
2 example.com IN MX 10 mailhost.example.com.
134
4 /etc/postfix/main.cf:
135
5 myorigin = $mydomain
136
6 mydestination = $myhostname localhost.$mydomain localhost $mydomain
137
7 mynetworks = 127.0.0.0/8 10.0.0.0/24
139
9 # Optional: forward all non-local mail to firewall
140
10 #relayhost = [firewall.example.com]
144
* Line 2: Send mail for the domain "example.com" to the machine
145
mailhost.example.com. Remember to specify the "." at the end of the line.
147
* Line 5: Send mail as "user@example.com".
149
* Line 6: This host is the final mail destination for the "example.com"
150
domain, in addition to the names of the machine itself.
152
* Line 7: Specify the trusted networks.
154
* Line 8: This host does not relay mail from untrusted networks.
156
* Line 10: This is needed only when the mailhost has to forward non-local
157
mail via a mail server on a firewall. The [] forces Postfix to do no MX
160
In an environment like this, users access their mailbox in one or more of the
163
* Mailbox access via NFS or equivalent.
165
* Mailbox access via POP or IMAP.
167
* Mailbox on the user's preferred machine.
169
In the latter case, each user has an alias on the mailhost that forwards mail
170
to her preferred machine:
173
joe: joe@joes.preferred.machine
174
jane: jane@janes.preferred.machine
176
On some systems the alias database is not in /etc/aliases. To find out the
177
location for your system, execute the command "postconf alias_maps".
179
Execute the command "newaliases" whenever you change the aliases file.
181
PPoossttffiixx eemmaaiill ffiirreewwaallll//ggaatteewwaayy
183
The idea is to set up a Postfix email firewall/gateway that forwards mail for
184
"example.com" to an inside gateway machine but rejects mail for
185
"anything.example.com". There is only one problem: with "relay_domains =
186
example.com", the firewall normally also accepts mail for
187
"anything.example.com". That would not be right.
189
Note: this example requires Postfix version 2.0 and later. To find out what
190
Postfix version you have, execute the command "postconf mail_version".
192
The solution is presented in multiple parts. This first part gets rid of local
193
mail delivery on the firewall, making the firewall harder to break.
195
1 /etc/postfix/main.cf:
196
2 myorigin = example.com
198
4 local_recipient_maps =
199
5 local_transport = error:local mail delivery is disabled
201
7 /etc/postfix/master.cf:
202
8 Comment out the local delivery agent
206
* Line 2: Send mail from this machine as "user@example.com", so that no
207
reason exists to send mail to "user@firewall.example.com".
209
* Lines 3-8: Disable local mail delivery on the firewall machine.
211
For the sake of technical correctness the firewall must be able to receive mail
212
for postmaster@[firewall ip address]. Reportedly, some things actually expect
213
this ability to exist. The second part of the solution therefore adds support
214
for postmaster@[firewall ip address], and as a bonus we do abuse@[firewall ip
215
address] as well. All the mail to these two accounts is forwarded to an inside
218
1 /etc/postfix/main.cf:
219
2 virtual_alias_maps = hash:/etc/postfix/virtual
221
4 /etc/postfix/virtual:
222
5 postmaster postmaster@example.com
223
6 abuse abuse@example.com
227
* Because mydestination is empty (see the previous example), only address
228
literals matching $inet_interfaces or $proxy_interfaces are deemed local.
229
So "localpart@[a.d.d.r]" can be matched as simply "localpart" in canonical
230
(5) and virtual(5). This avoids the need to specify firewall IP addresses
231
into Postfix configuration files.
233
The last part of the solution does the email forwarding, which is the real
234
purpose of the firewall email function.
236
1 /etc/postfix/main.cf:
237
2 mynetworks = 127.0.0.0/8 12.34.56.0/24
238
3 relay_domains = example.com
239
4 parent_domain_matches_subdomains =
240
5 debug_peer_list smtpd_access_maps
241
6 smtpd_recipient_restrictions =
242
7 permit_mynetworks reject_unauth_destination
244
9 relay_recipient_maps = hash:/etc/postfix/relay_recipients
245
10 transport_maps = hash:/etc/postfix/transport
247
12 /etc/postfix/relay_recipients:
248
13 user1@example.com x
249
14 user2@example.com x
252
17 /etc/postfix/transport:
253
18 example.com smtp:[inside-gateway.example.com]
257
* Lines 1-7: Accept mail from local systems in $mynetworks, and accept mail
258
from outside for "user@example.com" but not for
259
"user@anything.example.com". The magic is in lines 4-5.
261
* Lines 9, 12-14: Define the list of valid addresses in the "example.com"
262
domain that can receive mail from the Internet. This prevents the mail
263
queue from filling up with undeliverable MAILER-DAEMON messages. If you
264
can't maintain a list of valid recipients then you must specify
265
"relay_recipient_maps =" (that is, an empty value), or you must specify an
266
"@example.com x" wild-card in the relay_recipients table.
268
* Lines 10, 17-18: Route mail for "example.com" to the inside gateway
269
machine. The [] forces Postfix to do no MX lookup.
271
Specify dbm instead of hash if your system uses dbm files instead of db. To
272
find out what lookup tables Postfix supports, use the command "postconf -m".
274
Execute the command "postmap /etc/postfix/relay_recipients" whenever you change
275
the relay_recipients table.
277
Execute the command "postmap /etc/postfix/transport" whenever you change the
280
DDeelliivveerriinngg ssoommee bbuutt nnoott aallll aaccccoouunnttss llooccaallllyy
282
A drawback of sending mail as "user@example.com" (instead of
283
"user@hostname.example.com") is that mail for "root" and other system accounts
284
is also sent to the central mailhost. In order to deliver such accounts
285
locally, you can set up virtual aliases as follows:
287
1 /etc/postfix/main.cf:
288
2 virtual_alias_maps = hash:/etc/postfix/virtual
290
4 /etc/postfix/virtual:
291
5 root root@localhost
296
* Line 5: As described in the virtual(5) manual page, the bare name "root"
297
matches "root@site" when "site" is equal to $myorigin, when "site" is
298
listed in $mydestination, or when it matches $inet_interfaces or
301
RRuunnnniinngg PPoossttffiixx bbeehhiinndd aa ffiirreewwaallll
303
The simplest way to set up Postfix on a host behind a firewalled network is to
304
send all mail to a gateway host, and to let that mail host take care of
305
internal and external forwarding. Examples of that are shown in the local area
306
network section above. A more sophisticated approach is to send only external
307
mail to the gateway host, and to send intranet mail directly. That's what
310
Note: this example requires Postfix version 2.0 and later. To find out what
311
Postfix version you have, execute the command "postconf mail_version".
313
The following example presents additional configuration. You need to combine
314
this with basic configuration information as discussed the first half of this
317
1 /etc/postfix/main.cf:
318
2 transport_maps = hash:/etc/postfix/transport
320
4 # Optional for a machine that isn't "always on"
321
5 #fallback_relay = [gateway.example.com]
323
7 /etc/postfix/transport:
324
8 # Internal delivery.
327
11 # External delivery.
328
12 * smtp:[gateway.example.com]
332
* Lines 2, 7-12: Request that intranet mail is delivered directly, and that
333
external mail is given to a gateway. Obviously, this example assumes that
334
the organization uses DNS MX records internally. The [] forces Postfix to
337
* Line 3: IMPORTANT: do not specify a relayhost in main.cf.
339
* Line 5: This prevents mail from being stuck in the queue when the machine
340
is turned off. Postfix tries to deliver mail directly, and gives
341
undeliverable mail to a gateway.
343
Specify dbm instead of hash if your system uses dbm files instead of db. To
344
find out what lookup tables Postfix supports, use the command "postconf -m".
346
Execute the command "postmap /etc/postfix/transport" whenever you edit the
349
CCoonnffiigguurriinngg PPoossttffiixx aass MMXX hhoosstt ffoorr aa rreemmoottee ssiittee
351
This section presents additional configuration. You need to combine this with
352
basic configuration information as discussed the first half of this document.
354
When your system is SECONDARY MX host for a remote site this is all you need:
357
2 the.backed-up.domain.tld IN MX 100 your.machine.tld.
359
4 /etc/postfix/main.cf:
360
5 relay_domains = . . . the.backed-up.domain.tld
361
6 smtpd_recipient_restrictions =
362
7 permit_mynetworks reject_unauth_destination
364
9 # You must specify your NAT/proxy external address.
365
10 #proxy_interfaces = 1.2.3.4
367
12 relay_recipient_maps = hash:/etc/postfix/relay_recipients
369
14 /etc/postfix/relay_recipients:
370
15 user1@the.backed-up.domain.tld x
371
16 user2@the.backed-up.domain.tld x
374
When your system is PRIMARY MX host for a remote site you need the above, plus:
376
18 /etc/postfix/main.cf:
377
19 transport_maps = hash:/etc/postfix/transport
379
21 /etc/postfix/transport:
380
22 the.backed-up.domain.tld relay:[their.mail.host.tld]
384
* Do not list the.backed-up.domain.tld in mydestination.
386
* Do not list the.backed-up.domain.tld in virtual_alias_domains.
388
* Do not list the.backed-up.domain.tld in virtual_mailbox_domains.
390
* Lines 1-7: Forward mail from the Internet for "the.backed-up.domain.tld" to
391
the primary MX host for that domain.
393
* Line 10: This is a must if Postfix receives mail via a NAT relay or proxy
394
that presents a different IP address to the world than the local machine.
396
* Lines 12-16: Define the list of valid addresses in the "the.backed-
397
up.domain.tld" domain. This prevents your mail queue from filling up with
398
undeliverable MAILER-DAEMON messages. If you can't maintain a list of valid
399
recipients then you must specify "relay_recipient_maps =" (that is, an
400
empty value), or you must specify an "@example.com x" wild-card in the
401
relay_recipients table.
403
* Line 22: The [] forces Postfix to do no MX lookup.
405
Specify dbm instead of hash if your system uses dbm files instead of db files.
406
To find out what lookup tables Postfix supports, use the command "postconf -m".
408
Execute the command "postmap /etc/postfix/transport" whenever you change the
411
PPoossttffiixx oonn aa ddiiaalluupp mmaacchhiinnee
413
This section applies to dialup connections that are down most of the time. For
414
dialup connections that are up 24x7, see the local area network section above.
416
This section presents additional configuration. You need to combine this with
417
basic configuration information as discussed the first half of this document.
419
If you do not have your own hostname (as with dynamic IP addressing) then you
420
should also study the section on "Postfix on hosts without a real hostname".
422
* Route all outgoing mail to your network provider.
423
If your machine is disconnected most of the time, there isn't a lot of
424
opportunity for Postfix to deliver mail to hard-to-reach corners of the
425
Internet. It's better to give the mail to a machine that is connected all
426
the time. In the example below, the [] prevents Postfix from trying to look
429
/etc/postfix/main.cf:
430
relayhost = [smtprelay.someprovider.com]
432
* Disable spontaneous SMTP mail delivery (if using on-demand dialup IP only).
434
Normally, Postfix attempts to deliver outbound mail at its convenience. If
435
your machine uses on-demand dialup IP, this causes your system to place a
436
telephone call whenever you submit new mail, and whenever Postfix retries
437
to deliver delayed mail. To prevent such telephone calls from being placed,
438
disable spontaneous SMTP mail deliveries.
440
/etc/postfix/main.cf:
441
defer_transports = smtp (Only for on-demand dialup IP hosts)
443
* Disable SMTP client DNS lookups (dialup LAN only).
445
/etc/postfix/main.cf:
446
disable_dns_lookups = yes (Only for on-demand dialup IP hosts)
448
* Flush the mail queue whenever the Internet link is established.
449
Put the following command into your PPP or SLIP dialup scripts:
451
/usr/sbin/sendmail -q (whenever the Internet link is up)
453
The exact location of the sendmail command is system-specific. Use the
454
command "postconf sendmail_path" to find out where the Postfix sendmail
455
command is located on your machine.
457
In order to find out if the mail queue is flushed, use something like:
461
# Start mail deliveries.
462
/usr/sbin/sendmail -q
464
# Allow deliveries to start.
467
# Loop until all messages have been tried at least once.
468
while mailq | grep '^[^ ]*\*' >/dev/null
473
If you have disabled spontaneous SMTP mail delivery, you also need to run
474
the "sendmail -q" command every now and then while the dialup link is up,
475
so that newly-posted mail is flushed from the queue.
477
PPoossttffiixx oonn hhoossttss wwiitthhoouutt aa rreeaall hhoossttnnaammee
479
This section is for hosts that don't have an Internet hostname. Typically these
480
are systems that get a dynamic IP address via DHCP or via dialup. Postfix will
481
let you send and receive mail just fine between accounts on a machine with a
482
fantasy name. However, you cannot use a fantasy hostname in your email address
483
when sending mail into the Internet, because no-one would be able to reply to
484
your mail. In fact, more and more sites refuse mail from non-existent domain
487
The perfect solution would be for Postfix to do a mapping from local fantasy
488
email addresses to valid Internet addresses when mail leaves the machine
489
(similar to Sendmail's generics table). This is planned for the near future.
491
In the mean time, the solution with Postfix is to use valid Internet addresses
492
where possible, and to let Postfix map valid Internet addresses to local
493
fantasy addresses. With this, you can send mail to the Internet and to local
494
fantasy addresses, including mail to local fantasy addresses that don't have a
495
valid Internet address of their own.
497
The following example presents additional configuration. You need to combine
498
this with basic configuration information as discussed the first half of this
501
1 /etc/postfix/main.cf:
502
2 myhostname = hostname.localdomain
503
3 mydomain = localdomain
505
5 canonical_maps = hash:/etc/postfix/canonical
507
7 virtual_alias_maps = hash:/etc/postfix/virtual
509
9 /etc/postfix/canonical:
510
10 your-login-name your-account@your-isp.com
512
12 /etc/postfix/virtual:
513
13 your-account@your-isp.com your-login-name
517
* Lines 2-3: Substitute your fantasy hostname here. Do not use a domain name
518
that is already in use by real organizations on the Internet. See RFC 2606
519
for examples of domain names that are guaranteed not to be owned by anyone.
521
* Lines 5, 9, 10: This provides the mapping from "your-login-
522
name@hostname.localdomain" to "your-account@your-isp.com". This part is
525
* Lines 7, 12, 13: Deliver mail for "your-account@your-isp.com" locally,
526
instead of sending it to the ISP. This part is not required but is