Postfix/Standartkonfigurationen
topic kurze Beschreibung
Beschreibung
Dieses Dokument stellt eine Reihe typischer Postfix-Konfigurationen vor.
- Dieses Dokument sollte gelesen werden, nachdem Sie die grundlegenden Konfigurationsschritte durchgeführt haben, die im Dokument BASIC_CONFIGURATION_README beschrieben sind.
- Insbesondere sollten Sie hier nicht fortfahren, wenn Sie Postfix noch nicht für die lokale Posteinreichung und -zustellung eingerichtet haben.
- Standardkonfigurationen
Standardkonfigurationen, die jeweils ein bestimmtes Problem lösen
- Postfix auf einem eigenständigen Internet-Host
- Postfix auf einem Null-Client
- Postfix in einem lokalen Netzwerk
- Postfix E-Mail-Firewall/Gateway
- Zusätzliche Konfigurationen
Zusätzliche Konfigurationen für Hosts in bestimmten Umgebungen
- Delivering some but not all accounts locally
- Running Postfix behind a firewall
- Configuring Postfix as primary or backup MX host for a remote site
- Postfix on a dialup machine
- Postfix on hosts without a real Internet hostname
Standardkonfigurationen
Zusätzliche Konfigurationen
Installation
Anwendungen
Syntax
Optionen
Parameter
Umgebungsvariablen
Exit-Status
Konfiguration
Dateien
Sicherheit
Dokumentation
RFC
Man-Pages
Info-Pages
Siehe auch
Links
Projekt-Homepage
Weblinks
Einzelnachweise
Testfragen
Testfrage 1
Testfrage 2
Testfrage 3
Testfrage 4
Testfrage 5
Postfix on a stand-alone Internet host
Postfix should work out of the box without change on a stand-alone machine that has direct Internet access.
- At least, that is how Postfix installs when you download the Postfix source code via http://www.postfix.org/.
You can use the command "postconf -n" to find out what settings are overruled by your main.cf.
- Besides a few pathname settings, few parameters should be set on a stand-alone box, beyond what is covered in the BASIC_CONFIGURATION_README document:
- /etc/postfix/main.cf
# Optional: send mail as user@domainname instead of user@hostname. #myorigin = $mydomain
# Optional: specify NAT/proxy external address. #proxy_interfaces = 1.2.3.4
# Alternative 1: don't relay mail from other hosts. mynetworks_style = host relay_domains =
# Alternative 2: relay mail from local clients only. # mynetworks = 192.168.1.0/28 # relay_domains =
See also the section "Postfix on hosts without a real Internet hostname" if this is applicable to your configuration.
Postfix on a null client
A null client is a machine that can only send mail.
- It receives no mail from the network, and it does not deliver any mail locally.
- A null client typically uses POP, IMAP or NFS for mailbox access.
In this example we assume that the Internet domain name is "example.com" and that the machine is named "hostname.example.com".
- As usual, the examples show only parameters that are not left at their default settings.
1 /etc/postfix/main.cf: 2 myhostname = hostname.example.com 3 myorigin = $mydomain 4 relayhost = $mydomain 5 inet_interfaces = loopback-only 6 mydestination =
Translation:
- Line 2: Set myhostname to hostname.example.com, in case the machine name isn't set to a fully-qualified domain name (use the command "postconf -d myhostname" to find out what the machine name is).
- Line 2: The myhostname value also provides the default value for the mydomain parameter (here, "mydomain = example.com").
- Line 3: Send mail as "user@example.com" (instead of "user@hostname.example.com"), so that nothing ever has a reason to send mail to "user@hostname.example.com".
- Line 4: Forward all mail to the mail server that is responsible for the "example.com" domain.
- This prevents mail from getting stuck on the null client if it is turned off while some remote destination is unreachable.
- Specify a real hostname here if your "example.com" domain has no MX record.
- Line 5: Do not accept mail from the network.
- Line 6: Disable local mail delivery.
- All mail goes to the mail server as specified in line 4.
Postfix on a local network
This section describes a local area network environment of one main server and multiple other systems that send and receive email.
- As usual we assume that the Internet domain name is "example.com".
- All systems are configured to send mail as "user@example.com", and all systems receive mail for "user@hostname.example.com".
- The main server also receives mail for "user@example.com".
- We call this machine by the name of mailhost.example.com.
A drawback of sending mail as "user@example.com" is that mail for "root" and other system accounts is also sent to the central mailhost.
- See the section "Delivering some but not all accounts locally" below for possible solutions.
As usual, the examples show only parameters that are not left at their default settings.
First we present the non-mailhost configuration, because it is the simpler one.
- This machine sends mail as "user@example.com" and is the final destination for "user@hostname.example.com".
1 /etc/postfix/main.cf: 2 myorigin = $mydomain 3 mynetworks = 127.0.0.0/8 10.0.0.0/24 4 relay_domains = 5 # Optional: forward all non-local mail to mailhost 6 #relayhost = $mydomain
Translation:
- Line 2: Send mail as "user@example.com".
- Line 3: Specify the trusted networks.
- Line 4: This host does not relay mail from untrusted networks.
- Line 6: This is needed if no direct Internet access is available.
- See also below, "Postfix behind a firewall".
Next we present the mailhost configuration.
- This machine sends mail as "user@example.com" and is the final destination for "user@hostname.example.com" as well as "user@example.com".
1 DNS: 2 example.com IN MX 10 mailhost.example.com. 3 4 /etc/postfix/main.cf: 5 myorigin = $mydomain 6 mydestination = $myhostname localhost.$mydomain localhost $mydomain 7 mynetworks = 127.0.0.0/8 10.0.0.0/24 8 relay_domains = 9 # Optional: forward all non-local mail to firewall 10 #relayhost = [firewall.example.com]
Translation:
- Line 2: Send mail for the domain "example.com" to the machine mailhost.example.com.
- Remember to specify the "." at the end of the line.
- Line 5: Send mail as "user@example.com".
- Line 6: This host is the final mail destination for the "example.com" domain, in addition to the names of the machine itself.
- Line 7: Specify the trusted networks.
- Line 8: This host does not relay mail from untrusted networks.
- Line 10: This is needed only when the mailhost has to forward non-local mail via a mail server on a firewall.
- The [] forces Postfix to do no MX record lookups.
In an environment like this, users access their mailbox in one or more of the following ways:
- Mailbox access via NFS or equivalent.
- Mailbox access via POP or IMAP.
- Mailbox on the user's preferred machine.
In the latter case, each user has an alias on the mailhost that forwards mail to her preferred machine:
- /etc/aliases
joe: joe@joes.preferred.machine jane: jane@janes.preferred.machine
On some systems the alias database is not in /etc/aliases.
- To find out the location for your system, execute the command "postconf alias_maps".
Execute the command "newaliases" whenever you change the aliases file.
Postfix email firewall/gateway
The idea is to set up a Postfix email firewall/gateway that forwards mail for "example.com" to an inside gateway machine but rejects mail for "anything.example.com".
- There is only one problem: with "relay_domains = example.com", the firewall normally also accepts mail for "anything.example.com".
- That would not be right.
Note: this example requires Postfix version 2.0 and later.
- To find out what Postfix version you have, execute the command "postconf mail_version".
The solution is presented in multiple parts.
- This first part gets rid of local mail delivery on the firewall, making the firewall harder to break.
1 /etc/postfix/main.cf: 2 myorigin = example.com 3 mydestination = 4 local_recipient_maps = 5 local_transport = error:local mail delivery is disabled 6 7 /etc/postfix/master.cf: 8 Comment out the local delivery agent
Translation:
- Line 2: Send mail from this machine as "user@example.com", so that no reason exists to send mail to "user@firewall.example.com".
- Lines 3-8: Disable local mail delivery on the firewall machine.
For the sake of technical correctness the firewall must be able to receive mail for postmaster@[firewall ip address].
- Reportedly, some things actually expect this ability to exist.
- The second part of the solution therefore adds support for postmaster@[firewall ip address], and as a bonus we do abuse@[firewall ip address] as well.
- All the mail to these two accounts is forwarded to an inside address.
1 /etc/postfix/main.cf: 2 virtual_alias_maps = hash:/etc/postfix/virtual 3 4 /etc/postfix/virtual: 5 postmaster postmaster@example.com 6 abuse abuse@example.com
Translation:
- Because mydestination is empty (see the previous example), only address literals matching $inet_interfaces or $proxy_interfaces are deemed local.
- So "localpart@[a.d.d.r]" can be matched as simply "localpart" in canonical(5) and virtual(5).
- This avoids the need to specify firewall IP addresses in Postfix configuration files.
The last part of the solution does the email forwarding, which is the real purpose of the firewall email function.
1 /etc/postfix/main.cf: 2 mynetworks = 127.0.0.0/8 12.34.56.0/24 3 relay_domains = example.com 4 parent_domain_matches_subdomains = 5 debug_peer_list smtpd_access_maps
6a # Postfix 2.10 and later support separate relay control and 7a # spam control. 8a smtpd_relay_restrictions = 9a permit_mynetworks reject_unauth_destination 10a smtpd_recipient_restrictions = ...spam blocking rules....
6b # Older configurations combine relay control and spam control. To 7b # use this with Postfix ≥ 2.10 specify "smtpd_relay_restrictions=". 8b smtpd_recipient_restrictions = 9b permit_mynetworks reject_unauth_destination 10b ...spam blocking rules....
11 relay_recipient_maps = hash:/etc/postfix/relay_recipients 12 transport_maps = hash:/etc/postfix/transport 13 14 /etc/postfix/relay_recipients: 15 user1@example.com x 16 user2@example.com x 17 . . . 18 19 /etc/postfix/transport: 20 example.com relay:[inside-gateway.example.com]
Translation:
- Lines 1-10: Accept mail from local systems in $mynetworks, and accept mail from outside for "user@example.com" but not for "user@anything.example.com".
- The magic is in lines 4-5.
- Lines 11, 13-16: Define the list of valid addresses in the "example.com" domain that can receive mail from the Internet.
- This prevents the mail queue from filling up with undeliverable MAILER-DAEMON messages.
- If you can't maintain a list of valid recipients then you must specify "relay_recipient_maps =" (that is, an empty value), or you must specify an "@example.com x" wild-card in the relay_recipients table.
- Lines 12, 19-20: Route mail for "example.com" to the inside gateway machine.
- The [] forces Postfix to do no MX lookup.
- This uses the "relay" delivery transport (a copy of the default "smtp" delivery transport) to forward inbound mail.
- This can improve performance of deliveries to internal domains because they will compete for SMTP clients from the "relay" delivery transport, instead of competing with other SMTP deliveries for SMTP clients from the default "smtp" delivery transport.
Specify dbm instead of hash if your system uses dbm files instead of db files.
- To find out what lookup tables Postfix supports, use the command "postconf -m".
Execute the command "postmap /etc/postfix/relay_recipients" whenever you change the relay_recipients table.
Execute the command "postmap /etc/postfix/transport" whenever you change the transport table.
In some installations, there may be separate instances of Postfix processing inbound and outbound mail on a multi-homed firewall.
- The inbound Postfix instance has an SMTP server listening on the external firewall interface, and the outbound Postfix instance has an SMTP server listening on the internal interface.
- In such a configuration is it is tempting to configure $inet_interfaces in each instance with just the corresponding interface address.
In most cases, using inet_interfaces in this way will not work, because as documented in the $inet_interfaces reference manual, the smtp(8) delivery agent will also use the specified interface address as the source address for outbound connections and will be unable to reach hosts on "the other side" of the firewall.
- The symptoms are that the firewall is unable to connect to hosts that are in fact up.
- See the inet_interfaces parameter documentation for suggested work-arounds.