logo_header

icon_bubbles Forum

icon_bubbles Wiki

icon_bubbles Planet

RootForum Community » Wiki

Postfix

From RootForum Community » Wiki

Jump to:navigation, search

Contents

Einleitung

Dieses Howto dient, in Anlehnung an Joe Users Konfigurationsbeispiel sowie dieses Tutorial, als Basis Konfiguration eines Postfix MTA mt SSL/TLS.

Die Idee war es, die möglichen Konfigurationsoptionen getrennt zu halten, sodass jemand selbständig und flexibel entscheiden kann, welche Komponenten zum Mailserver eingesetzt werden sollen.

Installation

Abhängig vom eingesetzen Betriebssystem sollten uns über den Paketmanager (YaST, aptitude, Portage usw.) der jeweiligen Distribution entsprechende Pakete bereitgestellt werden.

Entsprechend nehmen wir die Installation per aptitude install postfix bzw. yast -i postfix vor.

Sollten uns keine Binaries zur Verfügung stehen, müssen wir diese selbst erzeugen siehe hierzu die Postfix Dokumentation.

Vorbereitung der SSL-Zertifikate

mkdir -p /etc/postfix/ssl 
cd /etc/postfix/ssl
/etc/ssl/misc/CA.pl -newca
#/usr/share/ssl/misc/CA.pl -newca
openssl req -new -nodes -keyout server-key.pem -out server-req.pem - days 365
openssl ca -out server-crt.pem -infiles server-req.pem
openssl gendh -out /etc/postfix/ssl/dh_1024.pem -2 -rand /dev/urandom 1024
openssl gendh -out /etc/postfix/ssl/dh_512.pem -2 -rand /dev/urandom 512
chmod 644 /etc/postfix/ssl/server-crt.pem /etc/postfix/ssl/demoCA/cacert.pem
chmod 400 /etc/postfix/ssl/server-key.pem

In der Datei demoCA/index.txt.attr sollte unbedingt unique_subject = no gesetzt werden.

Basis Konfiguration

Eine mögliche Konfiguration könnte wie folgt aus sehen: (Achtung Kommentare beachten)

cat > /etc/postfix/main.cf << "EOF"
allow_percent_hack = no
biff = no
broken_sasl_auth_clients = yes
disable_vrfy_command = yes
home_mailbox = Maildir/
mailbox_size_limit = 102400000
masquerade_exceptions = root
message_size_limit = 20480000
mydestination = $myhostname, $mydomain, localhost
## Der Domain Name. In den üblichen rootserver Fällen ist myhostname = $mydomain 
mydomain = domain.tld
myhostname = mail.domain.tld
mynetworks_style = host
myorigin = $mydomain
recipient_delimiter = +
smtpd_client_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unknown_reverse_client_hostname,permit
smtpd_data_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_pipelining,permit
smtpd_delay_reject = yes
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_helo_hostname,
  ## Kann u.U. Probleme bereiten, sofern kein rdns Eintrag zum Host existiert.
  ## Das trifft besonders auf Wählverbindungen zu. Diese abzulehnen ist nicht RFC konform. 
  #  reject_non_fqdn_helo_hostname,
  permit
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, check_recipient_mx_access cidr:/etc/postfix/mx_access, reject_unauth_destination, check_recipient_access pcre:/etc/postfix/recipient_checks.pcre, check_policy_service inet:127.0.0.1:12525, permit
smtpd_sasl_auth_enable = yes
smtpd_sasl2_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_sender, reject_unknown_sender_domain,  permit 
smtpd_tls_auth_only = yes
smtpd_tls_CAfile = /etc/postfix/ssl/demoCA/cacert.pem
smtpd_tls_cert_file = /etc/postfix/ssl/server-crt.pem
smtpd_tls_dh1024_param_file = /etc/postfix/ssl/dh_1024.pem
smtpd_tls_dh512_param_file = /etc/postfix/ssl/dh_512.pem
smtpd_tls_key_file = /etc/postfix/ssl/server-key.pem
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_tls_session_cache
smtpd_tls_security_level = may
smtpd_use_tls = yes
unknown_local_recipient_reject_code = 550
## OS "spezifische" Parameter
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
data_directory = /var/lib/postfix 
mail_owner = postfix
mail_spool_directory = /var/mail
mailq_path = /usr/bin/mailq
newaliases_path = /usr/bin/newaliases
program_directory = /usr/lib/postfix 
queue_directory = /var/spool/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = maildrop
EOF
cat > /etc/postfix/recipient_checks.pcre << "EOF"
/^\@/             550 Invalid address format.
/[!%\@].*\@/      550 This server disallows weird address syntax.
/^postmaster\@/   OK
/^hostmaster\@/   OK
/^abuse\@/        OK
EOF
cat > /etc/postfix/mx_access << "EOF"
0.0.0.0/8         REJECT Domain MX in broadcast network
10.0.0.0/8        REJECT Domain MX in RFC 1918 private network
127.0.0.0/8       REJECT Domain MX in loopback network
169.254.0.0/16    REJECT Domain MX in link local network
172.16.0.0/12     REJECT Domain MX in RFC 1918 private network
192.0.2.0/24      REJECT Domain MX in TEST-NET network
192.168.0.0/16    REJECT Domain MX in RFC 1918 private network
224.0.0.0/4       REJECT Domain MX in class D multicast network
240.0.0.0/5       REJECT Domain MX in class E reserved network
248.0.0.0/5       REJECT Domain MX in reserved network
EOF
cat > /etc/postfix/dynamicmaps.cf << "EOF"
# Postfix dynamic maps configuration file.
#
# The first match found is the one that is used.
# Wildcards are not supported.
#
#type   location of .so file                open function   (mkmap func)
#====   =============================== =============   ============
pcre    /usr/lib/postfix/dict_pcre.so       dict_pcre_open
ldap    /usr/lib/postfix/dict_ldap.so       dict_ldap_open
tcp     /usr/lib/postfix/dict_tcp.so        dict_tcp_open
mysql   /usr/lib/postfix/dict_mysql.so      dict_mysql_open
EOF

Danach abschliessend postmap /etc/postfix/mx_access ausführen.

Erweiterungen

MySQL Support / PostfixAdmin

mailserver/postfix/postfix-admin

POP3/IMAP-Server

mailserver/postfix/dovecot

Spamschutz

mailserver/postfix/policyd-weight

mailserver/postfix/postfwd

mailserver/postfix/spamassassin

mailserver/postfix/postgrey

Virenschutz

mailserver/postfix/clamav+amavisd

Alternativ kann auch nur clamsmtp zum Virenschutz eingesetzt werden.

mailserver/postfix/clamsmtp

Prüfen der Konfiguration

Zunächst prüfen wir, ob Postfix überhaupt läuft und an Port 25/tcp gebunden wurde. Mit netstat -tnl|grep :25 bzw. lsof -i :25 solten wir diese Einträge finden.

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN


Wir versenden nun per telnet (oder einem beliebigen anderen TCP-Client wie netcat) eine E-Mail über unseren Postfix MTA:

telnet localhost 25

HELO localhost
MAIL FROM: <>
RCPT TO: <user@example.com>
DATA
From: test@example.com
Subject: Mailtest
Hello, 

this is a test.
.
quit


Die Nachricht mit dem Betreff Mailtest sollte unmittelbar im Postfach des Benutzers user@example.com (ggf. anpassen) landen.