Mailserver Workshop Konfiguration: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 1: | Zeile 1: | ||
= Zielsetzung = | = Zielsetzung = | ||
| − | * Einrichtung eines Mailservers mit Postfix | + | * Einrichtung eines Mailservers mit Postfix und Dovecot |
| − | * | + | * Schrittweiser Aufbau der Mailinfrastruktur |
| − | * | + | * Verständnis der einzelnen Komponenten eines Mailservers |
| − | * | + | * Test der lokalen Mailzustellung |
| − | * | + | * Vorbereitung für spätere Absicherung mit TLS und Spamfilter |
= Voraussetzungen = | = Voraussetzungen = | ||
| − | * Debian | + | * Debian oder Ubuntu Server mit Root-Zugriff |
| − | * Domain ''' | + | * Domain '''it213.int''' ist bereits als MX für den Mailserver eingetragen |
| − | * | + | * Hostname des Mailservers '''mail.it213.int''' |
| − | * Internetzugang für Paketinstallation | + | * Internetzugang für Paketinstallation |
| − | = | + | = Ist der MX Record richtig eingetragen? = |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | ;Verwende eines dieser Tools | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | *host -t mx it213.int | |
| − | * | + | *nslookup -q=mx it213.int |
| − | * | + | *dig -t mx it213.int |
| − | * | ||
| − | |||
| − | = | + | = Installation der Mailserver-Komponenten = |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | *apt update | |
| − | * | + | *apt install postfix dovecot-core dovecot-imapd dovecot-lmtpd mailutils |
| − | * | ||
| − | |||
| − | |||
| − | + | Bei der Abfrage '''Internet Site''' wählen. | |
| − | |||
| − | |||
| − | |||
| + | = Beschreibung der Pakete = | ||
| − | = | + | == Postfix == |
| − | + | * Mail Transport Agent (MTA) | |
| − | + | * Verantwortlich für Versand und Empfang von E-Mails | |
| − | * | + | * Transportiert E-Mails zwischen Mailservern |
| − | * | ||
| − | |||
| − | |||
| − | * | ||
| − | |||
| − | = | + | == Dovecot == |
| + | * IMAP- und POP3-Server | ||
| + | * Ermöglicht Mailclients den Zugriff auf Mailboxen | ||
| − | == | + | == Dovecot LMTP == |
| − | * Postfix | + | * Zustellung von Postfix an Dovecot |
| − | + | * Effizienter als lokale mailbox_command Zustellung | |
| − | * | ||
| − | == | + | == Mailutils == |
| − | * | + | * Sammlung von Mailtools für Tests |
| − | + | * Enthält z. B. das Programm '''mail''' | |
| − | * Enthält | ||
| − | == | + | = Mailformate = |
| − | |||
| − | |||
| − | |||
| − | == | + | == mbox (/var/mail) == |
| − | + | * Alle Mails eines Benutzers liegen in einer Datei | |
| − | + | * Probleme bei parallelem Zugriff möglich | |
| − | + | * Wird historisch verwendet | |
| − | |||
| − | * | ||
| − | |||
| − | * | ||
| − | * | ||
| + | == Maildir == | ||
| + | * Jede Mail ist eine eigene Datei | ||
| + | * Keine Locking-Probleme | ||
| + | * Paralleler Zugriff möglich | ||
| + | * Bessere Backupmöglichkeiten | ||
| − | == | + | == Empfehlung == |
| − | * | + | * Maildir wird empfohlen |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | = Maildir vorbereiten = | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Jeder neue Benutzer bekommt automatisch ein Maildir. | |
| − | |||
| − | |||
| − | |||
*mkdir -p /etc/skel/Maildir/{cur,new,tmp} | *mkdir -p /etc/skel/Maildir/{cur,new,tmp} | ||
*echo 'export MAIL=$HOME/Maildir' >> /etc/skel/.bashrc | *echo 'export MAIL=$HOME/Maildir' >> /etc/skel/.bashrc | ||
| − | = Postfix | + | = Postfix Konfiguration = |
| − | + | ||
| − | + | == /etc/postfix/main.cf == | |
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | =/etc/postfix/main.cf= | ||
<pre> | <pre> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) | smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) | ||
| − | |||
biff = no | biff = no | ||
| − | |||
| − | |||
append_dot_mydomain = no | append_dot_mydomain = no | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
readme_directory = no | readme_directory = no | ||
| − | |||
compatibility_level = 3.6 | compatibility_level = 3.6 | ||
| − | |||
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem | smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem | ||
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key | smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key | ||
| − | smtpd_tls_security_level=may | + | smtpd_tls_security_level=may |
| − | |||
smtp_tls_CApath=/etc/ssl/certs | smtp_tls_CApath=/etc/ssl/certs | ||
| − | smtp_tls_security_level=may | + | smtp_tls_security_level=may |
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache | smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache | ||
| − | |||
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination | smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination | ||
| − | + | myhostname = mail.it213.int | |
| − | myhostname = | ||
| − | |||
alias_maps = hash:/etc/aliases | alias_maps = hash:/etc/aliases | ||
alias_database = hash:/etc/aliases | alias_database = hash:/etc/aliases | ||
| − | |||
myorigin = /etc/mailname | myorigin = /etc/mailname | ||
| − | + | mydestination = $myhostname, localhost.it213.int, it213.int, localhost | |
| − | mydestination = $myhostname, | ||
| − | |||
relayhost = | relayhost = | ||
| − | |||
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 | mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 | ||
| − | |||
mailbox_size_limit = 0 | mailbox_size_limit = 0 | ||
| − | |||
| − | |||
recipient_delimiter = + | recipient_delimiter = + | ||
| − | |||
inet_interfaces = all | inet_interfaces = all | ||
| − | |||
| − | |||
inet_protocols = all | inet_protocols = all | ||
| + | home_mailbox = Maildir/ | ||
| + | mailbox_command = | ||
</pre> | </pre> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| + | = Postfix starten = | ||
| + | |||
| + | *systemctl start postfix | ||
| + | |||
| + | = Postfix steuern = | ||
| + | == über systemctl == | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
*systemctl start postfix | *systemctl start postfix | ||
| − | |||
*systemctl stop postfix | *systemctl stop postfix | ||
*systemctl restart postfix | *systemctl restart postfix | ||
| − | == | + | *systemctl status postfix |
| − | + | ||
| + | == über postfix == | ||
| + | |||
*postfix start | *postfix start | ||
*postfix stop | *postfix stop | ||
*postfix reload | *postfix reload | ||
| + | *postfix status | ||
*postfix check | *postfix check | ||
| − | + | ||
| + | = Logging = | ||
| + | |||
*journalctl -f -u postfix@-.service | *journalctl -f -u postfix@-.service | ||
| − | + | ||
| − | + | = Benutzer anlegen = | |
| − | + | ||
| − | + | *useradd -m -s /bin/bash martha | |
| − | + | *useradd -m -s /bin/bash leroy | |
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | = | ||
| − | *useradd | ||
| − | *useradd | ||
*passwd martha | *passwd martha | ||
*passwd leroy | *passwd leroy | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | = Lokale Mailzustellung testen = | |
| + | |||
| + | Öffne drei SSH-Sitzungen | ||
| + | |||
| + | * eine als '''martha''' | ||
| + | * eine als '''leroy''' | ||
| + | * eine als '''root''' | ||
| + | |||
| + | Root überwacht die Logs | ||
| + | |||
| + | *journalctl -f -u postfix@-.service | ||
| + | |||
| + | == Leroy sendet Mails == | ||
| − | + | *echo "1. Mail" | mail -s "1. Mail" martha | |
| + | *echo "2. Mail" | mail -s "2. Mail" martha@mail.it213.int | ||
| + | *echo "3. Mail" | mail -s "3. Mail" martha@it213.int | ||
| − | + | == Martha liest Mails == | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | *mail | |
| − | + | == Speicherort prüfen == | |
| + | |||
| + | *find Maildir -type f | ||
| − | + | = Dovecot = | |
| − | |||
| − | |||
| − | |||
| − | == | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Dovecot stellt IMAP und POP3 bereit. | |
| − | + | == Mailformat konfigurieren == | |
| − | + | */etc/dovecot/conf.d/10-mail.conf* | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
<pre> | <pre> | ||
| − | + | mail_driver = maildir | |
| − | + | mail_home = /home/%{user | username} | |
| − | + | mail_path = %{home}/Maildir | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</pre> | </pre> | ||
| − | == | + | |
| − | * | + | == Authentifizierung == |
| + | |||
| + | */etc/dovecot/conf.d/10-auth.conf* | ||
| + | |||
<pre> | <pre> | ||
| − | + | auth_mechanisms = plain login | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</pre> | </pre> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | = | + | == Socket für Postfix == |
| − | + | ||
| − | + | */etc/dovecot/conf.d/10-master.conf* | |
| − | + | ||
| − | + | <pre> | |
| − | + | service imap-login { | |
| − | + | inet_listener imap { | |
| − | = | + | } |
| − | |||
| − | |||
| − | |||
| − | |||
| − | * | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | inet_listener imaps { | |
| − | + | } | |
| − | + | } | |
| − | + | service pop3-login { | |
| − | + | inet_listener pop3 { | |
| − | + | } | |
| − | |||
| − | |||
| − | |||
| − | + | inet_listener pop3s { | |
| − | + | } | |
| − | + | } | |
| − | |||
| − | = | + | service lmtp { |
| − | + | unix_listener /var/spool/postfix/private/dovecot-lmtp { | |
| + | mode = 0600 | ||
| + | user = postfix | ||
| + | group = postfix | ||
| + | } | ||
| + | } | ||
| − | |||
| − | |||
service auth { | service auth { | ||
| − | |||
| − | |||
unix_listener /var/spool/postfix/private/auth { | unix_listener /var/spool/postfix/private/auth { | ||
mode = 0660 | mode = 0660 | ||
| Zeile 450: | Zeile 231: | ||
group = postfix | group = postfix | ||
} | } | ||
| − | |||
} | } | ||
| − | </pre> | + | </pre> |
| − | + | = Dienste starten = | |
| − | |||
| − | + | *systemctl restart dovecot | |
| − | * | + | *systemctl restart postfix |
| − | |||
| − | |||
| − | |||
| − | = | + | = Kontrolle der offenen Ports = |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | *ss -lntp | |
| − | + | = Erwartete Dienste = | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | {| class="wikitable" | |
| − | + | ! Dienst !! Zweck !! Port | |
| − | + | |- | |
| − | + | | SMTP || Mailtransport || 25 | |
| − | + | |- | |
| − | + | | SMTPS || verschlüsselter Mailversand || 465 | |
| − | + | |- | |
| − | + | | IMAP || Zugriff auf Mailbox || 143 | |
| − | + | |- | |
| − | + | | IMAPS || verschlüsselter Zugriff || 993 | |
| − | + | |} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Version vom 11. März 2026, 12:15 Uhr
Zielsetzung
- Einrichtung eines Mailservers mit Postfix und Dovecot
- Schrittweiser Aufbau der Mailinfrastruktur
- Verständnis der einzelnen Komponenten eines Mailservers
- Test der lokalen Mailzustellung
- Vorbereitung für spätere Absicherung mit TLS und Spamfilter
Voraussetzungen
- Debian oder Ubuntu Server mit Root-Zugriff
- Domain it213.int ist bereits als MX für den Mailserver eingetragen
- Hostname des Mailservers mail.it213.int
- Internetzugang für Paketinstallation
Ist der MX Record richtig eingetragen?
- Verwende eines dieser Tools
- host -t mx it213.int
- nslookup -q=mx it213.int
- dig -t mx it213.int
Installation der Mailserver-Komponenten
- apt update
- apt install postfix dovecot-core dovecot-imapd dovecot-lmtpd mailutils
Bei der Abfrage Internet Site wählen.
Beschreibung der Pakete
Postfix
- Mail Transport Agent (MTA)
- Verantwortlich für Versand und Empfang von E-Mails
- Transportiert E-Mails zwischen Mailservern
Dovecot
- IMAP- und POP3-Server
- Ermöglicht Mailclients den Zugriff auf Mailboxen
Dovecot LMTP
- Zustellung von Postfix an Dovecot
- Effizienter als lokale mailbox_command Zustellung
Mailutils
- Sammlung von Mailtools für Tests
- Enthält z. B. das Programm mail
Mailformate
mbox (/var/mail)
- Alle Mails eines Benutzers liegen in einer Datei
- Probleme bei parallelem Zugriff möglich
- Wird historisch verwendet
Maildir
- Jede Mail ist eine eigene Datei
- Keine Locking-Probleme
- Paralleler Zugriff möglich
- Bessere Backupmöglichkeiten
Empfehlung
- Maildir wird empfohlen
Maildir vorbereiten
Jeder neue Benutzer bekommt automatisch ein Maildir.
- mkdir -p /etc/skel/Maildir/{cur,new,tmp}
- echo 'export MAIL=$HOME/Maildir' >> /etc/skel/.bashrc
Postfix Konfiguration
/etc/postfix/main.cf
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
readme_directory = no
compatibility_level = 3.6
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level=may
smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.it213.int
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost.it213.int, it213.int, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
home_mailbox = Maildir/
mailbox_command =
Postfix starten
- systemctl start postfix
Postfix steuern
über systemctl
- systemctl start postfix
- systemctl stop postfix
- systemctl restart postfix
- systemctl status postfix
über postfix
- postfix start
- postfix stop
- postfix reload
- postfix status
- postfix check
Logging
- journalctl -f -u postfix@-.service
Benutzer anlegen
- useradd -m -s /bin/bash martha
- useradd -m -s /bin/bash leroy
- passwd martha
- passwd leroy
Lokale Mailzustellung testen
Öffne drei SSH-Sitzungen
- eine als martha
- eine als leroy
- eine als root
Root überwacht die Logs
- journalctl -f -u postfix@-.service
Leroy sendet Mails
- echo "1. Mail" | mail -s "1. Mail" martha
- echo "2. Mail" | mail -s "2. Mail" martha@mail.it213.int
- echo "3. Mail" | mail -s "3. Mail" martha@it213.int
Martha liest Mails
Speicherort prüfen
- find Maildir -type f
Dovecot
Dovecot stellt IMAP und POP3 bereit.
Mailformat konfigurieren
- /etc/dovecot/conf.d/10-mail.conf*
mail_driver = maildir
mail_home = /home/%{user | username}
mail_path = %{home}/Maildir
Authentifizierung
- /etc/dovecot/conf.d/10-auth.conf*
auth_mechanisms = plain login
Socket für Postfix
- /etc/dovecot/conf.d/10-master.conf*
service imap-login {
inet_listener imap {
}
inet_listener imaps {
}
}
service pop3-login {
inet_listener pop3 {
}
inet_listener pop3s {
}
}
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600
user = postfix
group = postfix
}
}
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
Dienste starten
- systemctl restart dovecot
- systemctl restart postfix
Kontrolle der offenen Ports
- ss -lntp
Erwartete Dienste
| Dienst | Zweck | Port |
|---|---|---|
| SMTP | Mailtransport | 25 |
| SMTPS | verschlüsselter Mailversand | 465 |
| IMAP | Zugriff auf Mailbox | 143 |
| IMAPS | verschlüsselter Zugriff | 993 |