Home | History | Annotate | Line # | Download | only in html
      1 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
      2         "https://www.w3.org/TR/html4/loose.dtd">
      3 
      4 <html>
      5 
      6 <head>
      7 
      8 <title>Postfix Standard Configuration Examples</title>
      9 
     10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     11 <link rel='stylesheet' type='text/css' href='postfix-doc.css'>
     12 
     13 </head>
     14 
     15 <body>
     16 
     17 <h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix Standard Configuration Examples</h1>
     18 
     19 <hr>
     20 
     21 <h2>Purpose of this document</h2>
     22 
     23 <p> This document presents a number of typical Postfix configurations.
     24 This document should be reviewed after you have followed the basic
     25 configuration steps as described in the <a href="BASIC_CONFIGURATION_README.html">BASIC_CONFIGURATION_README</a>
     26 document. In particular, do not proceed here if you don't already
     27 have Postfix working for local mail submission and for local mail
     28 delivery. </p>
     29 
     30 <p> The first part of this document presents standard configurations
     31 that each solve one specific problem. </p>
     32 
     33 <ul>
     34 
     35 <li><a href="#stand_alone">Postfix on a stand-alone Internet host</a>
     36 
     37 <li><a href="#null_client">Postfix on a null client</a>
     38 
     39 <li><a href="#local_network">Postfix on a local network</a>
     40 
     41 <li><a href="#firewall">Postfix email firewall/gateway</a>
     42 
     43 </ul>
     44 
     45 <p> The second part of this document presents additional configurations
     46 for hosts in specific environments. </p>
     47 
     48 <ul>
     49 
     50 <li><a href="#some_local">Delivering some but not all accounts locally</a>
     51 
     52 <li><a href="#intranet">Running Postfix behind a firewall</a>
     53 
     54 <li><a href="#backup">Configuring Postfix as primary or backup MX host for a remote
     55 site</a>
     56 
     57 <li><a href="#dialup">Postfix on a dialup machine</a>
     58 
     59 <li><a href="#fantasy">Postfix on hosts without a real
     60 Internet hostname</a>
     61 
     62 </ul>
     63 
     64 <h2><a name="stand_alone">Postfix on a stand-alone Internet host</a></h2>
     65 
     66 <p> Postfix should work out of the box without change on a stand-alone
     67 machine that has direct Internet access.  At least, that is how
     68 Postfix installs when you download the Postfix source code via
     69 <a href="https://www.postfix.org/">https://www.postfix.org/</a>. </p>
     70 
     71 <p> You can use the command "<b>postconf -n</b>" to find out what
     72 settings are overruled by your <a href="postconf.5.html">main.cf</a>. Besides a few pathname
     73 settings, few parameters should be set on a stand-alone box, beyond
     74 what is covered in the <a href="BASIC_CONFIGURATION_README.html">BASIC_CONFIGURATION_README</a> document: </p>
     75 
     76 <blockquote>
     77 <pre>
     78 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
     79     # Optional: send mail as user@domainname instead of user@hostname.
     80     #<a href="postconf.5.html#myorigin">myorigin</a> = $<a href="postconf.5.html#mydomain">mydomain</a>
     81 
     82     # Optional: specify NAT/proxy external address.
     83     #<a href="postconf.5.html#proxy_interfaces">proxy_interfaces</a> = 1.2.3.4
     84 
     85     # Alternative 1: don't relay mail from other hosts.
     86     <a href="postconf.5.html#mynetworks_style">mynetworks_style</a> = host
     87     <a href="postconf.5.html#relay_domains">relay_domains</a> =
     88 
     89     # Alternative 2: relay mail from local clients only.
     90     # <a href="postconf.5.html#mynetworks">mynetworks</a> = 192.168.1.0/28
     91     # <a href="postconf.5.html#relay_domains">relay_domains</a> =
     92 </pre>
     93 </blockquote>
     94 
     95 <p> See also the section "<a href="#fantasy">Postfix on hosts without
     96 a real Internet hostname</a>" if this is applicable to your configuration.
     97 </p>
     98 
     99 <h2><a name="null_client">Postfix on a null client</a></h2>
    100 
    101 <p> A null client is a machine that can only send mail. It receives no
    102 mail from the network, and it does not deliver any mail locally. A
    103 null client typically uses POP, IMAP or NFS for mailbox access. </p>
    104 
    105 <p> In this example we assume that the Internet domain name is
    106 "example.com" and that the machine is named "hostname.example.com".
    107 As usual, the examples show only parameters that are not left at
    108 their default settings. </p>
    109 
    110 <blockquote>
    111 <pre>
    112 1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    113 2     <a href="postconf.5.html#myhostname">myhostname</a> = hostname.example.com
    114 3     <a href="postconf.5.html#myorigin">myorigin</a> = $<a href="postconf.5.html#mydomain">mydomain</a>
    115 4     <a href="postconf.5.html#relayhost">relayhost</a> = $<a href="postconf.5.html#mydomain">mydomain</a>
    116 5     <a href="postconf.5.html#inet_interfaces">inet_interfaces</a> = loopback-only
    117 6     <a href="postconf.5.html#mydestination">mydestination</a> =
    118 </pre>
    119 </blockquote>
    120 
    121 <p> Translation: </p>
    122 
    123 <ul>
    124 
    125 <li> <p> Line 2: Set <a href="postconf.5.html#myhostname">myhostname</a> to hostname.example.com, in case
    126 the machine name isn't set to a fully-qualified domain name (use
    127 the command "postconf -d <a href="postconf.5.html#myhostname">myhostname</a>" to find out what the machine
    128 name is).  </p>
    129 
    130 <li> <p> Line 2: The <a href="postconf.5.html#myhostname">myhostname</a> value also provides the default
    131 value for the <a href="postconf.5.html#mydomain">mydomain</a> parameter (here, "<a href="postconf.5.html#mydomain">mydomain</a> = example.com").
    132 </p>
    133 
    134 <li> <p> Line 3: Send mail as "user (a] example.com" (instead of
    135 "user (a] hostname.example.com"), so that nothing ever has a reason
    136 to send mail to "user (a] hostname.example.com". </p>
    137 
    138 <li> <p> Line 4: Forward all mail to the mail server that is
    139 responsible for the "example.com" domain. This prevents mail from
    140 getting stuck on the null client if it is turned off while some
    141 remote destination is unreachable. Specify a real hostname
    142 here if your "example.com" domain has no MX record. </p>
    143 
    144 <li> <p> Line 5: Do not accept mail from the network. </p>
    145 
    146 <li> <p> Line 6: Disable local mail delivery. All mail goes to
    147 the mail server as specified in line 4.  </p>
    148 
    149 </ul>
    150 
    151 <h2><a name="local_network">Postfix on a local network</a></h2>
    152 
    153 <p> This section describes a local area network environment of one
    154 main server and multiple other systems that send and receive email.
    155 As usual we assume that the Internet domain name is "example.com".
    156 All systems are configured to send mail as "user (a] example.com", and
    157 all systems receive mail for "user (a] hostname.example.com".  The main
    158 server also receives mail for "user (a] example.com". We call this
    159 machine by the name of mailhost.example.com. </p>
    160 
    161 <p> A drawback of sending mail as "user (a] example.com" is that mail
    162 for "root" and other system accounts is also sent to the central
    163 mailhost. See the section "<a href="#some_local">Delivering some
    164 but not all accounts locally</a>" below for possible solutions.
    165 </p>
    166 
    167 <p> As usual, the examples show only parameters that are not left
    168 at their default settings. </p>
    169 
    170 <p> First we present the non-mailhost configuration, because it is
    171 the simpler one. This machine sends mail as "user (a] example.com" and
    172 is the final destination for "user (a] hostname.example.com". </p>
    173 
    174 <blockquote>
    175 <pre>
    176 1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    177 2     <a href="postconf.5.html#myorigin">myorigin</a> = $<a href="postconf.5.html#mydomain">mydomain</a>
    178 3     <a href="postconf.5.html#mynetworks">mynetworks</a> = 127.0.0.0/8 10.0.0.0/24
    179 4     <a href="postconf.5.html#relay_domains">relay_domains</a> =
    180 5     # Optional: forward all non-local mail to mailhost
    181 6     #<a href="postconf.5.html#relayhost">relayhost</a> = $<a href="postconf.5.html#mydomain">mydomain</a>
    182 </pre>
    183 </blockquote>
    184 
    185 <p> Translation: </p>
    186 
    187 <ul>
    188 
    189 <li> <p> Line 2: Send mail as "user (a] example.com". </p>
    190 
    191 <li> <p> Line 3: Specify the trusted networks. </p>
    192 
    193 <li> <p> Line 4: This host does not relay mail from untrusted networks. </p>
    194 
    195 <li> <p> Line 6: This is needed if no direct Internet access is
    196 available.  See also below, "<a href="#firewall">Postfix behind
    197 a firewall</a>". </p>
    198 
    199 </ul>
    200 
    201 <p> Next we present the mailhost configuration.  This machine sends
    202 mail as "user (a] example.com" and is the final destination for
    203 "user (a] hostname.example.com" as well as "user (a] example.com". </p>
    204 
    205 <blockquote>
    206 <pre>
    207  1 DNS:
    208  2     example.com    IN    MX  10 mailhost.example.com.
    209  3 
    210  4 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    211  5     <a href="postconf.5.html#myorigin">myorigin</a> = $<a href="postconf.5.html#mydomain">mydomain</a>
    212  6     <a href="postconf.5.html#mydestination">mydestination</a> = $<a href="postconf.5.html#myhostname">myhostname</a> localhost.$<a href="postconf.5.html#mydomain">mydomain</a> localhost $<a href="postconf.5.html#mydomain">mydomain</a>
    213  7     <a href="postconf.5.html#mynetworks">mynetworks</a> = 127.0.0.0/8 10.0.0.0/24
    214  8     <a href="postconf.5.html#relay_domains">relay_domains</a> =
    215  9     # Optional: forward all non-local mail to firewall
    216 10     #<a href="postconf.5.html#relayhost">relayhost</a> = [firewall.example.com]
    217 </pre>
    218 </blockquote>
    219 
    220 <p> Translation: </p>
    221 
    222 <ul>
    223 
    224 <li> <p> Line 2: Send mail for the domain "example.com" to the
    225 machine mailhost.example.com.  Remember to specify the "." at the
    226 end of the line. </p>
    227 
    228 <li> <p> Line 5: Send mail as "user (a] example.com". </p>
    229 
    230 <li> <p> Line 6: This host is the final mail destination for the
    231 "example.com" domain, in addition to the names of the machine
    232 itself. </p>
    233 
    234 <li> <p> Line 7: Specify the trusted networks. </p>
    235 
    236 <li> <p> Line 8: This host does not relay mail from untrusted networks. </p>
    237 
    238 <li> <p> Line 10: This is needed only when the mailhost has to
    239 forward non-local mail via a mail server on a firewall.  The
    240 <tt>[]</tt> forces Postfix to do no MX record lookups. </p>
    241 
    242 </ul>
    243 
    244 <p> In an environment like this, users access their mailbox in one
    245 or more of the following ways:
    246 
    247 <ul>
    248 
    249 <li> <p> Mailbox access via NFS or equivalent.  </p>
    250 
    251 <li> <p> Mailbox access via POP or IMAP. </p>
    252 
    253 <li> <p> Mailbox on the user's preferred machine. </p>
    254 
    255 </ul>
    256 
    257 <p> In the latter case, each user has an alias on the mailhost that
    258 forwards mail to her preferred machine: </p>
    259 
    260 <blockquote>
    261 <pre>
    262 /etc/aliases:
    263     joe:    joe (a] joes.preferred.machine
    264     jane:   jane (a] janes.preferred.machine
    265 </pre>
    266 </blockquote>
    267 
    268 <p> On some systems the alias database is not in /etc/aliases.  To
    269 find out the location for your system, execute the command "<b>postconf
    270 <a href="postconf.5.html#alias_maps">alias_maps</a></b>". </p>
    271 
    272 <p> Execute the command "<b>newaliases</b>" whenever you change
    273 the aliases file.  </p>
    274 
    275 <h2><a name="firewall">Postfix email firewall/gateway</a></h2>
    276 
    277 <p> The idea is to set up a Postfix email firewall/gateway that
    278 forwards mail for "example.com" to an inside gateway machine but
    279 rejects mail for "anything.example.com". There is only one problem:
    280 with "<a href="postconf.5.html#relay_domains">relay_domains</a> = example.com", the firewall normally also
    281 accepts mail for "anything.example.com".  That would not be right.
    282 </p>
    283 
    284 <p> Note: this example requires Postfix version 2.0 and later. To find
    285 out what Postfix version you have, execute the command "<b>postconf
    286 <a href="postconf.5.html#mail_version">mail_version</a></b>". </p>
    287 
    288 <p> The solution is presented in multiple parts. This first part
    289 gets rid of local mail delivery on the firewall, making the firewall
    290 harder to break. </p>
    291 
    292 <blockquote>
    293 <pre>
    294 1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    295 2     <a href="postconf.5.html#myorigin">myorigin</a> = example.com
    296 3     <a href="postconf.5.html#mydestination">mydestination</a> =
    297 4     <a href="postconf.5.html#local_recipient_maps">local_recipient_maps</a> =
    298 5     <a href="postconf.5.html#local_transport">local_transport</a> = <a href="error.8.html">error</a>:local mail delivery is disabled
    299 6 
    300 7 /etc/postfix/<a href="master.5.html">master.cf</a>:
    301 8     Comment out the local delivery agent
    302 </pre>
    303 </blockquote>
    304 
    305 <p> Translation: </p>
    306 
    307 <ul>
    308 
    309 <li> <p> Line 2: Send mail from this machine as "user (a] example.com",
    310 so that no reason exists to send mail to "user (a] firewall.example.com".
    311 </p>
    312 
    313 <li> <p> Lines 3-8: Disable local mail delivery on the firewall
    314 machine. </p>
    315 
    316 </ul>
    317 
    318 <p> For the sake of technical correctness the firewall must be able
    319 to receive mail for postmaster@[firewall ip address]. Reportedly,
    320 some things actually expect this ability to exist. The second part
    321 of the solution therefore adds support for postmaster@[firewall ip
    322 address], and as a bonus we do abuse@[firewall ip address] as well.
    323 All the mail to these two accounts is forwarded to an inside address.
    324 </p>
    325 
    326 <blockquote>
    327 <pre>
    328 1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    329 2     <a href="postconf.5.html#virtual_alias_maps">virtual_alias_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/virtual
    330 3 
    331 4 /etc/postfix/virtual:
    332 5     postmaster      postmaster (a] example.com
    333 6     abuse           abuse (a] example.com
    334 </pre>
    335 </blockquote>
    336 
    337 <p> Translation: </p>
    338 
    339 <ul>
    340 
    341 <li> <p> Because <a href="postconf.5.html#mydestination">mydestination</a> is empty (see the previous example),
    342 only address literals matching $<a href="postconf.5.html#inet_interfaces">inet_interfaces</a> or $<a href="postconf.5.html#proxy_interfaces">proxy_interfaces</a>
    343 are deemed local.  So "localpart@[a.d.d.r]" can be matched as simply
    344 "localpart" in <a href="canonical.5.html">canonical(5)</a> and <a href="virtual.5.html">virtual(5)</a>. This avoids the need to
    345 specify firewall IP addresses in Postfix configuration files. </p>
    346 
    347 </ul>
    348 
    349 <p> The last part of the solution does the email forwarding, which
    350 is the real purpose of the firewall email function. </p>
    351 
    352 <blockquote>
    353 <pre>
    354  1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    355  2     <a href="postconf.5.html#mynetworks">mynetworks</a> = 127.0.0.0/8 12.34.56.0/24
    356  3     <a href="postconf.5.html#relay_domains">relay_domains</a> = example.com
    357  4     <a href="postconf.5.html#parent_domain_matches_subdomains">parent_domain_matches_subdomains</a> = 
    358  5         <a href="postconf.5.html#debug_peer_list">debug_peer_list</a> smtpd_access_maps
    359 <br>
    360  6a    # Postfix 2.10 and later support separate relay control and
    361  7a    # spam control.
    362  8a    <a href="postconf.5.html#smtpd_relay_restrictions">smtpd_relay_restrictions</a> =
    363  9a        <a href="postconf.5.html#permit_mynetworks">permit_mynetworks</a> <a href="postconf.5.html#reject_unauth_destination">reject_unauth_destination</a>
    364 10a    <a href="postconf.5.html#smtpd_recipient_restrictions">smtpd_recipient_restrictions</a> = ...spam blocking rules....
    365 <br>
    366  6b    # Older configurations combine relay control and spam control. To
    367  7b    # use this with Postfix &ge; 2.10 specify "<a href="postconf.5.html#smtpd_relay_restrictions">smtpd_relay_restrictions</a>=".
    368  8b    <a href="postconf.5.html#smtpd_recipient_restrictions">smtpd_recipient_restrictions</a> =
    369  9b        <a href="postconf.5.html#permit_mynetworks">permit_mynetworks</a> <a href="postconf.5.html#reject_unauth_destination">reject_unauth_destination</a>
    370 10b        ...spam blocking rules....
    371 <br>
    372 11     <a href="postconf.5.html#relay_recipient_maps">relay_recipient_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/relay_recipients
    373 12     <a href="postconf.5.html#transport_maps">transport_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/transport
    374 13 
    375 14 /etc/postfix/relay_recipients:
    376 15     user1 (a] example.com   x
    377 16     user2 (a] example.com   x
    378 17      . . .
    379 18 
    380 19 /etc/postfix/transport:
    381 20     example.com   relay:[inside-gateway.example.com]
    382 </pre>
    383 </blockquote>
    384 
    385 <p> Translation: </p>
    386 
    387 <ul>
    388  
    389 <li><p> Lines 1-10: Accept mail from local systems in $<a href="postconf.5.html#mynetworks">mynetworks</a>,
    390 and accept mail from outside for "user (a] example.com" but not for
    391 "user (a] anything.example.com". The magic is in lines 4-5. </p>
    392 
    393 <li> <p> Lines 11, 13-16: Define the list of valid addresses in the
    394 "example.com" domain that can receive mail from the Internet. This
    395 prevents the mail queue from filling up with undeliverable
    396 MAILER-DAEMON messages. If you can't maintain a list of valid
    397 recipients then you must specify "<a href="postconf.5.html#relay_recipient_maps">relay_recipient_maps</a> =" (that
    398 is, an empty value), or you must specify an "@example.com  x"
    399 wild-card in the relay_recipients table. </p>
    400 
    401 <li> <p> Lines 12, 19-20: Route mail for "example.com" to the inside
    402 gateway machine. The <tt>[]</tt> forces Postfix to do no MX lookup.
    403 This uses the "relay" delivery transport (a copy of the default
    404 "smtp" delivery transport) to forward inbound mail. This can improve
    405 performance of deliveries to internal domains because they will
    406 compete for SMTP clients from the "relay" delivery transport, instead
    407 of competing with other SMTP deliveries for SMTP clients from the
    408 default "smtp" delivery transport. </p>
    409 
    410 </ul>
    411 
    412 <p> Instead of <a href="lmdb_table.5.html">lmdb</a>:, some systems use <a href="CDB_README.html">cdb</a>:, <a href="DATABASE_README.html#types">hash</a>:, or <a href="DATABASE_README.html#types">dbm</a>:. </p>
    413 
    414 <p> Execute the command "<b>postmap /etc/postfix/virtual</b>"
    415 whenever you change the virtual file, to (re)build a default-type
    416 indexed file. Execute "<b>postmap <i>type</i>:/etc/postfix/virtual</b>"
    417 to specify an explicit type. </p>
    418 
    419 <p> The default indexed file type is configured with the
    420 <a href="postconf.5.html#default_database_type">default_database_type</a> parameter. To list available explicit types, 
    421 execute the command "<b>postconf -m</b>".</p>
    422 
    423 <p> Execute the command "<b>postmap /etc/postfix/relay_recipients</b>"
    424 whenever you change the relay_recipients file, to (re)build a
    425 default-type indexed file. Execute "<b>postmap
    426 <i>type</i>:/etc/postfix/relay_recipients</b>" to specify an explicit
    427 type.</p>
    428 
    429 <p> Execute the command "<b>postmap /etc/postfix/transport</b>"
    430 whenever you change the transport file, to (re)build a default-type
    431 indexed file. Execute "<b>postmap <i>type</i>:/etc/postfix/transport</b>"
    432 to specify an explicit type. </p>
    433 
    434 <p> In some installations, there may be separate instances of Postfix
    435 processing inbound and outbound mail on a multi-homed firewall. The
    436 inbound Postfix instance has an SMTP server listening on the external
    437 firewall interface, and the outbound Postfix instance has an SMTP server
    438 listening on the internal interface. In such a configuration it is
    439 tempting to configure $<a href="postconf.5.html#inet_interfaces">inet_interfaces</a> in each instance with just the
    440 corresponding interface address. </p>
    441 
    442 <p> In most cases, using <a href="postconf.5.html#inet_interfaces">inet_interfaces</a> in this way will not work,
    443 because as documented in the $<a href="postconf.5.html#inet_interfaces">inet_interfaces</a> reference manual, the
    444 <a href="smtp.8.html">smtp(8)</a> delivery agent will also use the specified interface address
    445 as the source address for outbound connections and will be unable to
    446 reach hosts on "the other side" of the firewall. The symptoms are that
    447 the firewall is unable to connect to hosts that are in fact up. See the
    448 <a href="postconf.5.html#inet_interfaces">inet_interfaces</a> parameter documentation for suggested work-arounds.</p>
    449 
    450 <h2><a name="some_local">Delivering some but not all accounts
    451 locally</a></h2>
    452 
    453 <p> A drawback of sending mail as "user (a] example.com" (instead of
    454 "user (a] hostname.example.com") is that mail for "root" and other
    455 system accounts is also sent to the central mailhost.  In order to
    456 deliver such accounts locally, you can set up virtual aliases as
    457 follows:  </p>
    458 
    459 <blockquote>
    460 <pre>
    461 1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    462 2     <a href="postconf.5.html#virtual_alias_maps">virtual_alias_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/virtual
    463 3 
    464 4 /etc/postfix/virtual:
    465 5     root     root@localhost
    466 6     . . .
    467 </pre>
    468 </blockquote>
    469 
    470 <p> Translation: </p>
    471 
    472 <ul>
    473 
    474 <li> <p> Line 5: As described in the <a href="virtual.5.html">virtual(5)</a> manual page, the
    475 bare name "root" matches "root@site" when "site" is equal to
    476 $<a href="postconf.5.html#myorigin">myorigin</a>, when "site" is listed in $<a href="postconf.5.html#mydestination">mydestination</a>, or when it
    477 matches $<a href="postconf.5.html#inet_interfaces">inet_interfaces</a> or $<a href="postconf.5.html#proxy_interfaces">proxy_interfaces</a>. </p>
    478 
    479 </ul>
    480 
    481 <p> Instead of <a href="lmdb_table.5.html">lmdb</a>:, some systems use <a href="CDB_README.html">cdb</a>:, <a href="DATABASE_README.html#types">hash</a>:, or <a href="DATABASE_README.html#types">dbm</a>:. </p>
    482 
    483 <p> Execute the command "<b>postmap /etc/postfix/virtual</b>" after
    484 editing the virtual file, to (re)build a default-type indexed file.
    485 Execute "<b>postmap <i>type</i>:/etc/postfix/virtual</b>" to specify
    486 an explicit type. </p>
    487 
    488 <p> The default indexed file type is configured with the
    489 <a href="postconf.5.html#default_database_type">default_database_type</a> parameter. To list available explicit types, 
    490 execute the command "<b>postconf -m</b>".</p>
    491 
    492 <h2><a name="intranet">Running Postfix behind a firewall</a></h2>
    493 
    494 <p> The simplest way to set up Postfix on a host behind a firewalled
    495 network is to send all mail to a gateway host, and to let that mail
    496 host take care of internal and external forwarding. Examples of that
    497 are shown in the <a href="#local_network">local area network</a>
    498 section above. A more sophisticated approach is to send only external
    499 mail to the gateway host, and to send intranet mail directly. </p>
    500 
    501 <p> Note: this example requires Postfix version 2.0 and later. To find
    502 out what Postfix version you have, execute the command "<b>postconf
    503 <a href="postconf.5.html#mail_version">mail_version</a></b>". </p>
    504 
    505 <p> The following example presents additional configuration. You
    506 need to combine this with basic configuration information as
    507 discussed in the first half of this document. </p>
    508 
    509 <blockquote>
    510 <pre>
    511  1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    512  2     <a href="postconf.5.html#transport_maps">transport_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/transport
    513  3     <a href="postconf.5.html#relayhost">relayhost</a> =
    514  4     # Optional for a machine that isn't "always on"
    515  5     #<a href="postconf.5.html#fallback_relay">fallback_relay</a> = [gateway.example.com]
    516  6 
    517  7 /etc/postfix/transport:
    518  8     # Internal delivery.
    519  9     example.com      :
    520 10     .example.com     :
    521 11     # External delivery.
    522 12     *                <a href="smtp.8.html">smtp</a>:[gateway.example.com]
    523 </pre>
    524 </blockquote>
    525 
    526 <p> Translation: </p>
    527 
    528 <ul>
    529 
    530 <li> <p> Lines 2, 7-12: Request that intranet mail is delivered
    531 directly, and that external mail is given to a gateway. Obviously,
    532 this example assumes that the organization uses DNS MX records
    533 internally.  The <tt>[]</tt> forces Postfix to do no MX lookup.
    534 </p>
    535 
    536 <li> <p> Line 3: IMPORTANT: do not specify a <a href="postconf.5.html#relayhost">relayhost</a> in <a href="postconf.5.html">main.cf</a>.
    537 </p>
    538 
    539 <li> <p> Line 5: This prevents mail from being stuck in the queue
    540 when the machine is turned off.  Postfix tries to deliver mail
    541 directly, and gives undeliverable mail to a gateway.  </p>
    542 
    543 </ul>
    544 
    545 <p> Instead of <a href="lmdb_table.5.html">lmdb</a>:, some systems use <a href="CDB_README.html">cdb</a>:, <a href="DATABASE_README.html#types">hash</a>:, or <a href="DATABASE_README.html#types">dbm</a>:. </p>
    546 
    547 <p> Execute the command "<b>postmap /etc/postfix/transport</b>"
    548 whenever you edit the transport file, to (re)build a default-type
    549 indexed file. Execute "<b>postmap <i>type</i>:/etc/postfix/transport</b>"
    550 to specify an explicit type. </p>
    551 
    552 <p> The default indexed file type is configured with the
    553 <a href="postconf.5.html#default_database_type">default_database_type</a> parameter. To list available explicit types, 
    554 execute the command "<b>postconf -m</b>".</p>
    555 
    556 
    557 <h2><a name="backup">Configuring Postfix as primary or backup MX host for a remote site</a></h2>
    558 
    559 <p> This section presents additional configuration. You need to
    560 combine this with basic configuration information as discussed in the
    561 first half of this document. </p>
    562 
    563 <p> When your system is SECONDARY MX host for a remote site this
    564 is all you need: </p>
    565 
    566 <blockquote>
    567 <pre>
    568  1 DNS:
    569  2     the.backed-up.domain.tld        IN      MX 100 your.machine.tld.
    570  3 
    571  4 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    572  5     <a href="postconf.5.html#relay_domains">relay_domains</a> = . . . the.backed-up.domain.tld
    573 <br>
    574  6a    # Postfix 2.10 and later support separate relay control and
    575  7a    # spam control.
    576  8a    <a href="postconf.5.html#smtpd_relay_restrictions">smtpd_relay_restrictions</a> =
    577  9a        <a href="postconf.5.html#permit_mynetworks">permit_mynetworks</a> <a href="postconf.5.html#reject_unauth_destination">reject_unauth_destination</a>
    578 10a    <a href="postconf.5.html#smtpd_recipient_restrictions">smtpd_recipient_restrictions</a> = ...spam blocking rules....
    579 <br>
    580  6b    # Older configurations combine relay control and spam control. To
    581  7b    # use this with Postfix &ge; 2.10 specify "<a href="postconf.5.html#smtpd_relay_restrictions">smtpd_relay_restrictions</a>=".
    582  8b    <a href="postconf.5.html#smtpd_recipient_restrictions">smtpd_recipient_restrictions</a> =
    583  9b        <a href="postconf.5.html#permit_mynetworks">permit_mynetworks</a> <a href="postconf.5.html#reject_unauth_destination">reject_unauth_destination</a>
    584 10b        ...spam blocking rules....
    585 <br>
    586 11     # You must specify your NAT/proxy external address.
    587 12     #<a href="postconf.5.html#proxy_interfaces">proxy_interfaces</a> = 1.2.3.4
    588 13 
    589 14     <a href="postconf.5.html#relay_recipient_maps">relay_recipient_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/relay_recipients
    590 15 
    591 16 /etc/postfix/relay_recipients:
    592 17     user1 (a] the.backed-up.domain.tld   x
    593 18     user2 (a] the.backed-up.domain.tld   x
    594 19      . . .
    595 </pre>
    596 </blockquote>
    597 
    598 <p> When your system is PRIMARY MX host for a remote site you 
    599 need the above, plus: </p>
    600 
    601 <blockquote>
    602 <pre>
    603 20 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    604 21     <a href="postconf.5.html#transport_maps">transport_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/transport
    605 22 
    606 23 /etc/postfix/transport:
    607 24     the.backed-up.domain.tld       relay:[their.mail.host.tld]
    608 </pre>
    609 </blockquote>
    610 
    611 <p> Important notes:
    612 
    613 <ul>
    614 
    615 <li><p>Do not list the.backed-up.domain.tld in <a href="postconf.5.html#mydestination">mydestination</a>.</p>
    616 
    617 <li><p>Do not list the.backed-up.domain.tld in <a href="postconf.5.html#virtual_alias_domains">virtual_alias_domains</a>.</p>
    618 
    619 <li><p>Do not list the.backed-up.domain.tld in <a href="postconf.5.html#virtual_mailbox_domains">virtual_mailbox_domains</a>.</p>
    620 
    621 <li> <p> Lines 1-9: Forward mail from the Internet for
    622 "the.backed-up.domain.tld" to the primary MX host for that domain.
    623 </p>
    624 
    625 <li> <p> Line 12: This is a must if Postfix receives mail via a
    626 NAT relay or proxy that presents a different IP address to the
    627 world than the local machine. </p>
    628 
    629 <li> <p> Lines 14-18: Define the list of valid addresses in the
    630 "the.backed-up.domain.tld" domain.  This prevents your mail queue
    631 from filling up with undeliverable MAILER-DAEMON messages. If you
    632 can't maintain a list of valid recipients then you must specify
    633 "<a href="postconf.5.html#relay_recipient_maps">relay_recipient_maps</a> =" (that is, an empty value), or you must
    634 specify an "@the.backed-up.domain.tld  x" wild-card in the
    635 relay_recipients table. </p>
    636 
    637 <li> <p> Line 24: The <tt>[]</tt> forces Postfix to do no MX lookup. </p>
    638 
    639 </ul>
    640 
    641 <p> Instead of <a href="lmdb_table.5.html">lmdb</a>:, some systems use <a href="CDB_README.html">cdb</a>:, <a href="DATABASE_README.html#types">hash</a>:, or <a href="DATABASE_README.html#types">dbm</a>:. </p>
    642 
    643 <p> Execute the command "<b>postmap /etc/postfix/relay_recipients</b>"
    644 whenever you change the relay_recipients file, to (re)build a
    645 default-type indexed file. Execute "<b>postmap
    646 <i>type</i>:/etc/postfix/relay_recipients</b>" to specify an explicit
    647 type. </p>
    648 
    649 <p> The default indexed file type is configured with the
    650 <a href="postconf.5.html#default_database_type">default_database_type</a> parameter. To list available explicit types, 
    651 execute the command "<b>postconf -m</b>".</p>
    652 
    653 <p> Execute the command "<b>postmap /etc/postfix/transport</b>"
    654 whenever you change the transport file, to (re)build a default-type
    655 indexed file. Execute "<b>postmap <i>type</i>:/etc/postfix/transport</b>"
    656 to specify an explicit type. </p>
    657 
    658 <p> NOTE for Postfix &lt; 2.2: Do not use the <a href="postconf.5.html#fallback_relay">fallback_relay</a> feature
    659 when relaying mail
    660 for a backup or primary MX domain. Mail would loop between the
    661 Postfix MX host and the <a href="postconf.5.html#fallback_relay">fallback_relay</a> host when the final destination
    662 is unavailable. </p>
    663  
    664 <ul>
    665 
    666 <li> In <a href="postconf.5.html">main.cf</a> specify "<tt><a href="postconf.5.html#relay_transport">relay_transport</a> = relay</tt>",
    667 
    668 <li> In <a href="master.5.html">master.cf</a> specify "<tt>-o <a href="postconf.5.html#fallback_relay">fallback_relay</a> =</tt>" at the    
    669 end of the <tt>relay</tt> entry.
    670 
    671 <li> In transport maps, specify "<tt>relay:<i>nexthop...</i></tt>"
    672 as the right-hand side for backup or primary MX domain entries.
    673 
    674 </ul>
    675 
    676 <p> These are default settings in Postfix version 2.2 and later.
    677 </p>
    678 
    679 <h2><a name="dialup">Postfix on a dialup machine</a></h2>
    680 
    681 <p> This section applies to dialup connections that are down most
    682 of the time. For dialup connections that are up 24x7, see the <a
    683 href="#local_network">local area network</a> section above.  </p>
    684 
    685 <p> This section presents additional configuration. You need to
    686 combine this with basic configuration information as discussed in the
    687 first half of this document. </p>
    688 
    689 <p> If you do not have your own hostname and IP address (usually
    690 with dialup, cable TV or DSL connections) then you should also
    691 study the section on "<a href="#fantasy">Postfix on hosts without
    692 a real Internet hostname</a>".  </p>
    693 
    694 <ul>
    695 
    696 <li> Route all outgoing mail to your network provider.
    697 
    698 <p> If your machine is disconnected most of the time, there isn't
    699 a lot of opportunity for Postfix to deliver mail to hard-to-reach
    700 corners of the Internet. It's better to give the mail to a machine
    701 that is connected all the time. In the example below, the <tt>[]</tt>
    702 prevents Postfix from trying to look up DNS MX records.  </p>
    703 
    704 <pre>
    705 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    706     <a href="postconf.5.html#relayhost">relayhost</a> = [smtprelay.someprovider.com]
    707 </pre>
    708 
    709 <li> <p><a name="spontaneous_smtp">Disable spontaneous SMTP mail
    710 delivery (if using on-demand dialup IP only).</a> </p>
    711 
    712 <p> Normally, Postfix attempts to deliver outbound mail at its convenience.
    713 If your machine uses on-demand dialup IP, this causes your system
    714 to place a telephone call whenever you submit new mail, and whenever
    715 Postfix retries to deliver delayed mail. To prevent such telephone
    716 calls from being placed, disable spontaneous SMTP mail deliveries. </p>
    717 
    718 <pre>
    719 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    720     <a href="postconf.5.html#defer_transports">defer_transports</a> = smtp (Only for on-demand dialup IP hosts)
    721 </pre>
    722 
    723 <li> <p>Disable SMTP client DNS lookups (dialup LAN only).</p>
    724 
    725 <pre>
    726 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    727     <a href="postconf.5.html#disable_dns_lookups">disable_dns_lookups</a> = yes (Only for on-demand dialup IP hosts)
    728 </pre>
    729 
    730 <li> Flush the mail queue whenever the Internet link is established.
    731 
    732 <p> Put the following command into your PPP or SLIP dialup scripts: </p>
    733 
    734 <pre>
    735 /usr/sbin/sendmail -q (whenever the Internet link is up)
    736 </pre>
    737 
    738 <p> The exact location of the Postfix sendmail command is system-specific.
    739 Use the command "<b>postconf <a href="postconf.5.html#sendmail_path">sendmail_path</a></b>" to find out where the
    740 Postfix sendmail command is located on your machine. </p>
    741 
    742 <p> In order to find out if the mail queue is flushed, use something
    743 like: </p>
    744 
    745 <pre>
    746 #!/bin/sh
    747 
    748 # Start mail deliveries.
    749 /usr/sbin/sendmail -q
    750 
    751 # Allow deliveries to start.
    752 sleep 10
    753 
    754 # Loop until all messages have been tried at least once.
    755 while mailq | grep '^[^ ]*\*' &gt;/dev/null
    756 do  
    757     sleep 10
    758 done
    759 </pre>
    760 
    761 <p> If you have disabled <a href="#spontaneous_smtp">spontaneous
    762 SMTP mail delivery</a>, you also need to run the "<b>sendmail -q</b>"
    763 command every now and then while the dialup link is up, so that
    764 newly-posted mail is flushed from the queue. </p>
    765 
    766 </ul>
    767 
    768 <h2><a name="fantasy">Postfix on hosts without a real Internet
    769 hostname</a></h2>
    770 
    771 <p> This section is for hosts that don't have their own Internet
    772 hostname.  Typically these are systems that get a dynamic IP address
    773 via DHCP or via dialup. Postfix will let you send and receive mail
    774 just fine between accounts on a machine with a fantasy name. However,
    775 you cannot use a fantasy hostname in your email address when sending
    776 mail into the Internet, because no-one would be able to reply to
    777 your mail. In fact, more and more sites refuse mail addresses with
    778 non-existent domain names. </p>
    779 
    780 <p> Note: the following information is Postfix version dependent.
    781 To find out what Postfix version you have, execute the command
    782 "<b>postconf <a href="postconf.5.html#mail_version">mail_version</a></b>". </p>
    783 
    784 <h3>Solution 1: Postfix version 2.2 and later </h3>
    785 
    786 <p> Postfix 2.2 uses the <a href="generic.5.html">generic(5)</a> address mapping to replace
    787 local fantasy email addresses by valid Internet addresses.  This
    788 mapping happens ONLY when mail leaves the machine; not when you
    789 send mail between users on the same machine. </p>
    790 
    791 <p> The following example presents additional configuration. You
    792 need to combine this with basic configuration information as
    793 discussed in the first half of this document. </p>
    794 
    795 <blockquote>
    796 <pre>
    797 1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    798 2     <a href="postconf.5.html#smtp_generic_maps">smtp_generic_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/generic
    799 3 
    800 4 /etc/postfix/generic:
    801 5     his (a] localdomain.local             hisaccount (a] hisisp.example
    802 6     her (a] localdomain.local             heraccount (a] herisp.example
    803 7     @localdomain.local                hisaccount+local (a] hisisp.example
    804 </pre>
    805 </blockquote>
    806 
    807 <p> When mail is sent to a remote host via SMTP: </p>
    808 
    809 <ul>
    810 
    811 <li> <p> Line 5 replaces <i>his (a] localdomain.local</i> by his ISP
    812 mail address, </p>
    813 
    814 <li> <p> Line 6 replaces <i>her (a] localdomain.local</i> by her ISP
    815 mail address, and </p>
    816 
    817 <li> <p> Line 7 replaces other local addresses by his ISP account,
    818 with an address extension of +<i>local</i> (this example assumes
    819 that the ISP supports "+" style address extensions). </p>
    820 
    821 </ul>
    822 
    823 <p> Instead of <a href="lmdb_table.5.html">lmdb</a>:, some systems use <a href="CDB_README.html">cdb</a>:, <a href="DATABASE_README.html#types">hash</a>:, or <a href="DATABASE_README.html#types">dbm</a>:. </p>
    824 
    825 <p> Execute the command "<b>postmap /etc/postfix/generic</b>"
    826 whenever you change the generic file, to (re)build a default-type
    827 indexed file. Execute  "<b>postmap <i>type</i>:/etc/postfix/generic</b>"
    828 to specify an explicit type.</p>
    829 
    830 <p> The default indexed file type is configured with the
    831 <a href="postconf.5.html#default_database_type">default_database_type</a> parameter. To list available explicit types, 
    832 execute the command "<b>postconf -m</b>".</p>
    833 
    834 <h3>Solution 2: Postfix version 2.1 and earlier </h3>
    835 
    836 <p> The solution with older Postfix systems is to use valid
    837 Internet addresses where possible, and to let Postfix map valid
    838 Internet addresses to local fantasy addresses. With this, you can
    839 send mail to the Internet and to local fantasy addresses, including
    840 mail to local fantasy addresses that don't have a valid Internet
    841 address of their own.</p>
    842 
    843 <p> The following example presents additional configuration. You
    844 need to combine this with basic configuration information as
    845 discussed in the first half of this document. </p>
    846 
    847 <blockquote>
    848 <pre>
    849  1 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
    850  2     <a href="postconf.5.html#myhostname">myhostname</a> = hostname.localdomain
    851  3     <a href="postconf.5.html#mydomain">mydomain</a> = localdomain
    852  4 
    853  5     <a href="postconf.5.html#canonical_maps">canonical_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/canonical
    854  6 
    855  7     <a href="postconf.5.html#virtual_alias_maps">virtual_alias_maps</a> = <a href="lmdb_table.5.html">lmdb</a>:/etc/postfix/virtual
    856  8 
    857  9 /etc/postfix/canonical:
    858 10     your-login-name    your-account (a] your-isp.com
    859 11 
    860 12 /etc/postfix/virtual:
    861 13     your-account (a] your-isp.com       your-login-name
    862 </pre>
    863 </blockquote>
    864 
    865 <p> Translation: </p>
    866 
    867 <ul>
    868 
    869 <li> <p> Lines 2-3: Substitute your fantasy hostname here. Do not
    870 use a domain name that is already in use by real organizations
    871 on the Internet. See <a href="https://tools.ietf.org/html/rfc2606">RFC 2606</a> for examples of domain
    872 names that are guaranteed not to be owned by anyone. </p>
    873 
    874 <li> <p> Lines 5, 9, 10: This provides the mapping from
    875 "your-login-name (a] hostname.localdomain" to "your-account (a] your-isp.com".
    876 This part is required. </p>
    877 
    878 <li> <p> Lines 7, 12, 13: Deliver mail for "your-account (a] your-isp.com"
    879 locally, instead of sending it to the ISP. This part is not required
    880 but is convenient.
    881 
    882 </ul>
    883 
    884 <p> Instead of <a href="lmdb_table.5.html">lmdb</a>:, some systems use <a href="CDB_README.html">cdb</a>:, <a href="DATABASE_README.html#types">hash</a>:, or <a href="DATABASE_README.html#types">dbm</a>:. </p>
    885 
    886 <p> Execute the command "<b>postmap /etc/postfix/canonical</b>"
    887 whenever you change the canonical file, to (re)build a default-type
    888 indexed file. Execute "<b>postmap <i>type</i>:/etc/postfix/canonical</b>"
    889 to specify an explicit type. </p>
    890 
    891 <p> The default indexed file type is configured with the
    892 <a href="postconf.5.html#default_database_type">default_database_type</a> parameter. To list available explicit types, 
    893 execute the command "<b>postconf -m</b>".</p>
    894 
    895 <p> Execute the command "<b>postmap /etc/postfix/virtual</b>"
    896 whenever you change the virtual file, to (re)build a default-type
    897 indexed file. Execute "<b>postmap <i>type</i>:/etc/postfix/virtual</b>"
    898 to specify an explicit type. </p>
    899 
    900 </body>
    901 
    902 </html>
    903