« Info:: apsi.net: DOCUMENTATION MAIL SERVER » : différence entre les versions
Page créée avec « KEYWORDS: MAIL, SERVER, APSI.NET, OVH1, MAIL.APSI.NET, OVH2, BACKUP.APSI.NET '''Le 02/01/2026:''' » |
Aucun résumé des modifications |
||
| (Une version intermédiaire par le même utilisateur non affichée) | |||
| Ligne 1 : | Ligne 1 : | ||
KEYWORDS: MAIL, SERVER, APSI.NET, OVH1, MAIL.APSI.NET, OVH2, BACKUP.APSI.NET | KEYWORDS: MAIL, SERVER, APSI.NET, OVH1, MAIL.APSI.NET, OVH2, BACKUP.APSI.NET | ||
'''Le | '''Le 04/01/2026:''' | ||
<span id="documentation-serveur-mail-apsi.net"></span> | |||
= Documentation Serveur Mail APSI.NET = | |||
<span id="infrastructure-mail-avec-relay-backup"></span> | |||
== Infrastructure Mail avec Relay Backup == | |||
'''Date de création :''' 31 Décembre 2025 '''Domaines gérés :''' apsi.net, voilou.nl | |||
----- | |||
<span id="architecture-globale"></span> | |||
== Architecture Globale == | |||
<span id="serveurs"></span> | |||
=== Serveurs === | |||
<span id="ovh1.pcstreet.org-mail.apsi.net"></span> | |||
==== ovh1.pcstreet.org (mail.apsi.net) ==== | |||
* '''IP :''' 51.83.2.131 | |||
* '''Rôle :''' Serveur mail principal (MX 10) | |||
* '''Services :''' Postfix, Dovecot, Roundcube, Apache | |||
* '''Certificats :''' Let’s Encrypt (mail.apsi.net) | |||
<span id="ovh2.pcstreet.org-backup.apsi.net"></span> | |||
==== ovh2.pcstreet.org (backup.apsi.net) ==== | |||
* '''IP :''' 51.68.207.177 | |||
* '''Rôle :''' Relay backup (MX 20) | |||
* '''Services :''' Postfix relay uniquement | |||
* '''Fonction :''' Met les emails en queue si ovh1 est indisponible | |||
<span id="comptes-email"></span> | |||
=== Comptes Email === | |||
* pchevalier@apsi.net (mot de passe: 11as95ap23) | |||
* pchevalier@voilou.nl (mot de passe: 11as95ap23) | |||
* contact@apsi.net (mot de passe: 11as95ap23) | |||
* contact@voilou.nl (mot de passe: 11as95ap23) | |||
----- | |||
<span id="configuration-dns"></span> | |||
== Configuration DNS == | |||
<span id="enregistrements-mx"></span> | |||
=== Enregistrements MX === | |||
<pre>apsi.net. MX 10 mail.apsi.net | |||
apsi.net. MX 20 backup.apsi.net | |||
voilou.nl MX 10 mail.apsi.net | |||
voilou.nl MX 20 backup.apsi.net</pre> | |||
<span id="enregistrements-a"></span> | |||
=== Enregistrements A === | |||
<pre>mail.apsi.net A 51.83.2.131 | |||
backup.apsi.net A 51.68.207.177</pre> | |||
----- | |||
<span id="configuration-ovh1-serveur-principal"></span> | |||
== Configuration OVH1 (Serveur Principal) == | |||
<span id="postfix---etcpostfixmain.cf"></span> | |||
=== Postfix - /etc/postfix/main.cf === | |||
'''Certificats TLS :''' | |||
<pre>smtpd_tls_cert_file=/etc/letsencrypt/live/mail.apsi.net/fullchain.pem | |||
smtpd_tls_key_file=/etc/letsencrypt/live/mail.apsi.net/privkey.pem | |||
smtpd_tls_security_level=may</pre> | |||
'''Authentication SASL (Dovecot) :''' | |||
<pre>smtpd_sasl_type = dovecot | |||
smtpd_sasl_path = private/auth | |||
smtpd_sasl_auth_enable = yes | |||
smtpd_sasl_security_options = noanonymous</pre> | |||
'''Hostname et domaines :''' | |||
<pre>myhostname = mail.apsi.net | |||
mydestination = $myhostname, apsi.net, voilou.nl, localhost | |||
home_mailbox = Maildir/</pre> | |||
'''Restrictions :''' | |||
<pre>smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination | |||
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination</pre> | |||
<span id="dovecot---etcdovecotconf.d"></span> | |||
=== Dovecot - /etc/dovecot/conf.d/ === | |||
'''10-mail.conf :''' | |||
<pre>mail_location = maildir:~/Maildir</pre> | |||
'''10-ssl.conf :''' | |||
<pre>ssl_cert = </etc/letsencrypt/live/mail.apsi.net/fullchain.pem | |||
ssl_key = </etc/letsencrypt/live/mail.apsi.net/privkey.pem</pre> | |||
'''10-master.conf (Auth socket pour Postfix) :''' | |||
<pre>service auth { | |||
unix_listener /var/spool/postfix/private/auth { | |||
mode = 0660 | |||
user = postfix | |||
group = postfix | |||
} | |||
}</pre> | |||
<span id="roundcube---etcroundcubeconfig.inc.php"></span> | |||
=== Roundcube - /etc/roundcube/config.inc.php === | |||
'''Connexion IMAP :''' | |||
<syntaxhighlight lang="php">$config['default_host'] = 'tls://localhost'; | |||
$config['default_port'] = 143; | |||
$config['imap_auth_type'] = null; // Auto-detect | |||
$config['imap_conn_options'] = array( | |||
'ssl' => array( | |||
'verify_peer' => false, | |||
'verify_peer_name' => false, | |||
'allow_self_signed' => true, | |||
), | |||
);</syntaxhighlight> | |||
'''Connexion SMTP :''' | |||
<syntaxhighlight lang="php">$config['smtp_server'] = 'tls://localhost'; | |||
$config['smtp_port'] = 587; | |||
$config['smtp_user'] = '%u'; | |||
$config['smtp_pass'] = '%p'; | |||
$config['smtp_auth_type'] = null;</syntaxhighlight> | |||
'''Permissions fichier :''' | |||
<syntaxhighlight lang="bash">chown root:www-data /etc/roundcube/config.inc.php | |||
chmod 640 /etc/roundcube/config.inc.php</syntaxhighlight> | |||
<span id="firewall---etciptables.d.newiptables.start"></span> | |||
=== Firewall - /etc/iptables.d.new/iptables.start === | |||
'''Ports ouverts :''' | |||
<syntaxhighlight lang="bash"># Port 25 : SMTP (réception depuis autres serveurs mail) | |||
# Port 587 : Submission avec STARTTLS | |||
# Port 465 : SMTPS (envoi authentifié SSL/TLS) | |||
# Port 143 : IMAP (lecture emails) | |||
# Port 993 : IMAPS (lecture emails sécurisée SSL/TLS) | |||
iptables -A INPUT -p tcp -m multiport --dports 25,587,465,143,993 -j ACCEPT</syntaxhighlight> | |||
<span id="fail2ban"></span> | |||
=== Fail2ban === | |||
'''Jails actifs :''' - postfix-sasl (protection auth SMTP) - dovecot (protection auth IMAP) - sshd | |||
----- | |||
<span id="configuration-ovh2-relay-backup"></span> | |||
== Configuration OVH2 (Relay Backup) == | |||
<span id="postfix---etcpostfixmain.cf-1"></span> | |||
=== Postfix - /etc/postfix/main.cf === | |||
'''Configuration relay :''' | |||
<pre>myhostname = backup.apsi.net | |||
relay_domains = apsi.net, voilou.nl | |||
relay_transport = smtp:[mail.apsi.net]:25 | |||
inet_protocols = ipv4 | |||
mailbox_size_limit = 0 | |||
message_size_limit = 52428800</pre> | |||
<span id="résolution-dns---etchosts"></span> | |||
=== Résolution DNS - /etc/hosts === | |||
'''Ajout pour résolution directe :''' | |||
<pre>51.83.2.131 mail.apsi.net</pre> | |||
<span id="firewall---etciptables.d.newiptables.start.claudepayant"></span> | |||
=== Firewall - /etc/iptables.d.new/iptables.start.ClaudePayant === | |||
'''Ports ouverts :''' | |||
<syntaxhighlight lang="bash"># Port 25 : SMTP pour relay de backup mail | |||
iptables -A INPUT -p tcp --dport 25 -j ACCEPT | |||
ip6tables -A INPUT -p tcp --dport 25 -j ACCEPT | |||
# SORTIES MAIL : permettre au serveur relay d'envoyer vers ovh1 | |||
iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT | |||
iptables -A OUTPUT -p tcp --sport 25 -j ACCEPT</syntaxhighlight> | |||
----- | |||
<span id="configuration-spf-dkim-et-dmarc"></span> | |||
== Configuration SPF, DKIM et DMARC == | |||
<span id="opendkim---etcopendkim.conf"></span> | |||
=== OpenDKIM - /etc/opendkim.conf === | |||
'''Configuration multi-domaines :''' | |||
<pre>Mode sv | |||
Canonicalization relaxed/simple | |||
Socket local:/var/spool/postfix/opendkim/opendkim.sock | |||
KeyTable refile:/etc/opendkim/KeyTable | |||
SigningTable refile:/etc/opendkim/SigningTable | |||
ExternalIgnoreList /etc/opendkim/TrustedHosts | |||
InternalHosts /etc/opendkim/TrustedHosts</pre> | |||
'''Fichiers de configuration :''' | |||
'''/etc/opendkim/KeyTable :''' | |||
<pre>mail._domainkey.apsi.net apsi.net:mail:/etc/opendkim/keys/apsi.net/mail.private | |||
mail._domainkey.voilou.nl voilou.nl:mail:/etc/opendkim/keys/voilou.nl/mail.private</pre> | |||
'''/etc/opendkim/SigningTable :''' | |||
<pre>*@apsi.net mail._domainkey.apsi.net | |||
*@voilou.nl mail._domainkey.voilou.nl</pre> | |||
'''/etc/opendkim/TrustedHosts :''' | |||
<pre>127.0.0.1 | |||
localhost | |||
mail.apsi.net | |||
apsi.net | |||
voilou.nl | |||
51.83.2.131</pre> | |||
<span id="postfix-integration---etcpostfixmain.cf"></span> | |||
=== Postfix Integration - /etc/postfix/main.cf === | |||
'''Configuration milter :''' | |||
<pre>milter_default_action = accept | |||
milter_protocol = 6 | |||
smtpd_milters = local:opendkim/opendkim.sock | |||
non_smtpd_milters = $smtpd_milters</pre> | |||
<span id="clés-dkim-générées"></span> | |||
=== Clés DKIM Générées === | |||
'''Emplacement :''' - <code>/etc/opendkim/keys/apsi.net/mail.private</code> (clé privée) - <code>/etc/opendkim/keys/voilou.nl/mail.private</code> (clé privée) | |||
'''Taille des clés :''' 1024 bits (compatibles PowerAdmin) - Les clés ont été générées en 1024 bits car PowerAdmin tronque les enregistrements TXT longs - Les clés 2048 bits (~400 caractères) dépassent la limite de PowerAdmin - Les clés 1024 bits (~230 caractères) fonctionnent correctement | |||
'''Permissions :''' | |||
<syntaxhighlight lang="bash">chown opendkim:opendkim /etc/opendkim/keys/*/mail.private | |||
chmod 600 /etc/opendkim/keys/*/mail.private</syntaxhighlight> | |||
<span id="enregistrements-dns-à-ajouter"></span> | |||
=== Enregistrements DNS à Ajouter === | |||
'''Fichier complet :''' <code>/root/IA/MAIL.APSI.NET/DNS_RECORDS_SPF_DKIM_DMARC.txt</code> | |||
<span id="pour-apsi.net"></span> | |||
==== Pour apsi.net : ==== | |||
'''SPF (TXT) :''' | |||
<pre>apsi.net. TXT "v=spf1 mx ip4:51.83.2.131 ip4:51.68.207.177 ~all"</pre> | |||
'''DKIM (TXT) - Clé 1024 bits compatible PowerAdmin :''' | |||
<pre>mail._domainkey.apsi.net. TXT "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDoDc7b7mrS9IEkE331OW/1wYAoCWfaSoU9orNrEm7zclCCYh62hjYJMbQT5rVcISH/hU3uOTUyGjUwqFw/emYw3CnwJwwOSgqM44n30cBwWP3+piy+DnPXFZpJDR4iBBYTygbKXu3X0BCAgX7pnD79kqLxaRjktn3sBYa/RP9ZZQIDAQAB"</pre> | |||
'''DMARC (TXT) :''' | |||
<pre>_dmarc.apsi.net. TXT "v=DMARC1; p=quarantine; rua=mailto:postmaster@apsi.net; ruf=mailto:postmaster@apsi.net; fo=1; adkim=r; aspf=r; pct=100"</pre> | |||
<span id="pour-voilou.nl"></span> | |||
==== Pour voilou.nl : ==== | |||
'''SPF (TXT) :''' | |||
<pre>voilou.nl. TXT "v=spf1 mx ip4:51.83.2.131 ip4:51.68.207.177 ~all"</pre> | |||
'''DKIM (TXT) - Clé 1024 bits compatible PowerAdmin :''' | |||
<pre>mail._domainkey.voilou.nl. TXT "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMonQQKDHEUPkcQFr0Uxeaqpw0tF2pm/NiEIvPBM7TCmLZUJ9tu9yviBO9Mrrn2hDjdNSgAxWNWIzzRPIlpfCrRnUdqOOp+NeftiqsBP02pg8bQDQxgA+InGSgvQYhGd6BDF6yxA8lf7eNkVEDGrPfnNRLSJMWzJveTpzVIjIwfwIDAQAB"</pre> | |||
'''DMARC (TXT) :''' | |||
<pre>_dmarc.voilou.nl. TXT "v=DMARC1; p=quarantine; rua=mailto:postmaster@voilou.nl; ruf=mailto:postmaster@voilou.nl; fo=1; adkim=r; aspf=r; pct=100"</pre> | |||
<span id="vérification-dns"></span> | |||
=== Vérification DNS === | |||
'''Après ajout des enregistrements (délai 1-24h) :''' | |||
<syntaxhighlight lang="bash"># Vérifier SPF | |||
dig +short TXT apsi.net | |||
dig +short TXT voilou.nl | |||
# Vérifier DKIM | |||
dig +short TXT mail._domainkey.apsi.net | |||
dig +short TXT mail._domainkey.voilou.nl | |||
# Vérifier DMARC | |||
dig +short TXT _dmarc.apsi.net | |||
dig +short TXT _dmarc.voilou.nl</syntaxhighlight> | |||
<span id="test-de-signature-dkim"></span> | |||
=== Test de Signature DKIM === | |||
'''Vérifier qu’OpenDKIM signe les emails :''' | |||
<syntaxhighlight lang="bash"># Logs OpenDKIM | |||
journalctl -u opendkim -n 50 | |||
# Tester les clés | |||
opendkim-testkey -d apsi.net -s mail -vvv | |||
opendkim-testkey -d voilou.nl -s mail -vvv | |||
# Vérifier signature dans email | |||
grep "DKIM-Signature" /home/pchevalier/Maildir/cur/*</syntaxhighlight> | |||
'''Résultat attendu dans les logs :''' | |||
<pre>opendkim: DKIM-Signature field added (s=mail, d=apsi.net)</pre> | |||
<span id="tests-en-ligne"></span> | |||
=== Tests en Ligne === | |||
'''Envoyer un email de test à :''' - check-auth@verifier.port25.com - postmaster@dkimvalidator.com | |||
Ces services renvoient un rapport complet sur SPF, DKIM et DMARC. | |||
----- | |||
<span id="configuration-client-thunderbird"></span> | |||
== Configuration Client Thunderbird == | |||
<span id="paramètres-imap"></span> | |||
=== Paramètres IMAP === | |||
* '''Serveur :''' mail.apsi.net | |||
* '''Port :''' 143 | |||
* '''Sécurité :''' STARTTLS | |||
* '''Auth :''' Mot de passe normal | |||
* '''Nom utilisateur :''' pchevalier@apsi.net | |||
<span id="paramètres-smtp"></span> | |||
=== Paramètres SMTP === | |||
* '''Serveur :''' mail.apsi.net | |||
* '''Port :''' 587 | |||
* '''Sécurité :''' STARTTLS | |||
* '''Auth :''' Mot de passe normal | |||
* '''Nom utilisateur :''' pchevalier@apsi.net | |||
'''IMPORTANT :''' Utiliser le hostname mail.apsi.net, pas l’adresse IP, pour éviter les erreurs de certificat. | |||
----- | |||
<span id="tests-de-validation"></span> | |||
== Tests de Validation == | |||
<span id="test-1-relay-en-mode-normal"></span> | |||
=== Test 1 : Relay en Mode Normal === | |||
'''Commande :''' | |||
<syntaxhighlight lang="bash">ssh root@ovh2.pcstreet.org 'echo "Test relay" | sendmail pchevalier@apsi.net'</syntaxhighlight> | |||
'''Résultat :''' - ✅ Connexion TLS 1.3 établie entre ovh2 et ovh1 - ✅ Email livré dans /home/pchevalier/Maildir/new/ - ✅ Logs montrent : <code>status=sent (delivered to maildir)</code> | |||
'''Logs ovh1 :''' | |||
<pre>postfix/smtpd: Anonymous TLS connection established from ovh2.pcstreet.org[51.68.207.177]: TLSv1.3 | |||
postfix/local: to=<pchevalier@apsi.net>, relay=local, dsn=2.0.0, status=sent (delivered to maildir)</pre> | |||
<span id="test-2-relay-en-mode-panne"></span> | |||
=== Test 2 : Relay en Mode Panne === | |||
'''Étapes :''' 1. Arrêt de Postfix sur ovh1 : <code>systemctl stop postfix</code> 2. Envoi email depuis ovh2 3. Vérification queue ovh2 : <code>mailq</code> montre email en attente avec “Connection refused” 4. Redémarrage ovh1 : <code>systemctl start postfix</code> 5. Force flush queue ovh2 : <code>postqueue -f</code> 6. Vérification : queue vide, email livré | |||
'''Résultat :''' - ✅ Email mis en queue pendant la panne - ✅ Email automatiquement livré après récupération - ✅ Aucune perte de mail | |||
----- | |||
<span id="accès-webmail"></span> | |||
== Accès Webmail == | |||
'''URL :''' https://apsi.net/roundcube/ | |||
'''Login :''' - Utilisateur : pchevalier@apsi.net - Mot de passe : 11as95ap23 | |||
----- | |||
<span id="commandes-utiles"></span> | |||
== Commandes Utiles == | |||
<span id="surveillance-des-logs-en-temps-réel"></span> | |||
=== Surveillance des logs en temps réel === | |||
<syntaxhighlight lang="bash"># Sur ovh1 | |||
tail -f /var/log/mail.log | |||
# Sur ovh2 | |||
ssh root@ovh2.pcstreet.org 'tail -f /var/log/mail.log'</syntaxhighlight> | |||
<span id="vérifier-la-queue-mail"></span> | |||
=== Vérifier la queue mail === | |||
<syntaxhighlight lang="bash"># Sur ovh1 | |||
mailq | |||
# Sur ovh2 | |||
ssh root@ovh2.pcstreet.org 'mailq'</syntaxhighlight> | |||
<span id="forcer-le-flush-de-la-queue"></span> | |||
=== Forcer le flush de la queue === | |||
<syntaxhighlight lang="bash">postqueue -f</syntaxhighlight> | |||
<span id="tester-imap-manuellement"></span> | |||
=== Tester IMAP manuellement === | |||
<syntaxhighlight lang="bash">timeout 5 bash -c ' | |||
exec 3<>/dev/tcp/localhost/993 | |||
cat <&3 & | |||
echo "a1 LOGIN pchevalier@apsi.net 11as95ap23" >&3 | |||
sleep 1 | |||
echo "a2 LOGOUT" >&3 | |||
sleep 1 | |||
'</syntaxhighlight> | |||
<span id="vérifier-les-certificats"></span> | |||
=== Vérifier les certificats === | |||
<syntaxhighlight lang="bash">openssl s_client -connect mail.apsi.net:993 -starttls imap | |||
openssl s_client -connect mail.apsi.net:587 -starttls smtp</syntaxhighlight> | |||
<span id="statut-des-services"></span> | |||
=== Statut des services === | |||
<syntaxhighlight lang="bash">systemctl status postfix | |||
systemctl status dovecot | |||
systemctl status apache2 | |||
systemctl status fail2ban</syntaxhighlight> | |||
----- | |||
<span id="sécurité"></span> | |||
== Sécurité == | |||
<span id="fail2ban-protection"></span> | |||
=== Fail2ban Protection === | |||
* '''Bannissement après :''' 5 tentatives échouées | |||
* '''Durée ban :''' 10 minutes | |||
* '''Services protégés :''' Postfix SASL, Dovecot IMAP, SSH | |||
<span id="firewall"></span> | |||
=== Firewall === | |||
* Seuls les ports mail nécessaires sont ouverts | |||
* Connexions sortantes mail autorisées pour relay | |||
* Protection DDoS basique active | |||
<span id="certificats-ssltls"></span> | |||
=== Certificats SSL/TLS === | |||
* '''Émetteur :''' Let’s Encrypt | |||
* '''Renouvellement :''' Automatique via certbot | |||
* '''Protocoles :''' TLS 1.2 minimum | |||
* '''Ciphers :''' Strong ciphers uniquement | |||
----- | |||
<span id="maintenance"></span> | |||
== Maintenance == | |||
<span id="renouvellement-certificats-lets-encrypt"></span> | |||
=== Renouvellement certificats Let’s Encrypt === | |||
<syntaxhighlight lang="bash">certbot renew --dry-run # Test | |||
certbot renew # Renouvellement réel | |||
systemctl reload postfix dovecot apache2</syntaxhighlight> | |||
<span id="rotation-des-logs"></span> | |||
=== Rotation des logs === | |||
Les logs sont automatiquement rotés par logrotate. | |||
<span id="mise-à-jour-du-système"></span> | |||
=== Mise à jour du système === | |||
<syntaxhighlight lang="bash">apt update && apt upgrade | |||
systemctl restart postfix dovecot apache2</syntaxhighlight> | |||
----- | |||
<span id="dépannage"></span> | |||
== Dépannage == | |||
<span id="email-non-reçu"></span> | |||
=== Email non reçu === | |||
# Vérifier les logs : <code>tail -n 100 /var/log/mail.log</code> | |||
# Vérifier la queue : <code>mailq</code> | |||
# Vérifier le pare-feu : <code>iptables -L -n</code> | |||
# Tester la connectivité : <code>telnet mail.apsi.net 25</code> | |||
<span id="roundcube-ne-se-connecte-pas"></span> | |||
=== Roundcube ne se connecte pas === | |||
# Vérifier permissions : <code>ls -l /etc/roundcube/config.inc.php</code> | |||
# Vérifier logs : <code>tail /var/log/roundcube/*.log</code> | |||
# Vérifier Dovecot : <code>systemctl status dovecot</code> | |||
# Tester IMAP : <code>telnet localhost 143</code> | |||
<span id="relay-ne-fonctionne-pas"></span> | |||
=== Relay ne fonctionne pas === | |||
# Vérifier DNS : <code>host mail.apsi.net</code> (sur ovh2) | |||
# Vérifier connectivité : <code>telnet mail.apsi.net 25</code> (depuis ovh2) | |||
# Vérifier logs ovh2 : <code>tail -f /var/log/mail.log</code> | |||
# Vérifier configuration relay : <code>postconf relay_domains relay_transport</code> | |||
----- | |||
<span id="résumé-architecture"></span> | |||
== Résumé Architecture == | |||
<pre>Internet | |||
| | |||
v | |||
[MX 10] mail.apsi.net (51.83.2.131) - ovh1 | |||
| | |||
+-- Postfix (SMTP: 25, 587, 465) | |||
+-- Dovecot (IMAP: 143, 993) | |||
+-- Roundcube (HTTPS: 443) | |||
+-- Fail2ban | |||
| | |||
v | |||
/home/*/Maildir/ | |||
[MX 20] backup.apsi.net (51.68.207.177) - ovh2 | |||
| | |||
+-- Postfix Relay | |||
+-- Queue backup si ovh1 down | |||
| | |||
v (relay vers) | |||
mail.apsi.net:25</pre> | |||
'''Flux normal :''' Internet → ovh1 → Postfix → Dovecot → Maildir → Thunderbird/Roundcube | |||
'''Flux si panne ovh1 :''' Internet → ovh2 → Queue → (attente récupération ovh1) → ovh1 → Maildir | |||
----- | |||
<span id="auteur"></span> | |||
== Auteur == | |||
Configuration réalisée le 31 décembre 2025. Tests validés avec succès en mode normal et mode panne. | |||
Dernière version du 4 janvier 2026 à 08:38
KEYWORDS: MAIL, SERVER, APSI.NET, OVH1, MAIL.APSI.NET, OVH2, BACKUP.APSI.NET
Le 04/01/2026:
Documentation Serveur Mail APSI.NET
Infrastructure Mail avec Relay Backup
Date de création : 31 Décembre 2025 Domaines gérés : apsi.net, voilou.nl
Architecture Globale
Serveurs
ovh1.pcstreet.org (mail.apsi.net)
- IP : 51.83.2.131
- Rôle : Serveur mail principal (MX 10)
- Services : Postfix, Dovecot, Roundcube, Apache
- Certificats : Let’s Encrypt (mail.apsi.net)
ovh2.pcstreet.org (backup.apsi.net)
- IP : 51.68.207.177
- Rôle : Relay backup (MX 20)
- Services : Postfix relay uniquement
- Fonction : Met les emails en queue si ovh1 est indisponible
Comptes Email
- pchevalier@apsi.net (mot de passe: 11as95ap23)
- pchevalier@voilou.nl (mot de passe: 11as95ap23)
- contact@apsi.net (mot de passe: 11as95ap23)
- contact@voilou.nl (mot de passe: 11as95ap23)
Configuration DNS
Enregistrements MX
apsi.net. MX 10 mail.apsi.net apsi.net. MX 20 backup.apsi.net voilou.nl MX 10 mail.apsi.net voilou.nl MX 20 backup.apsi.net
Enregistrements A
mail.apsi.net A 51.83.2.131 backup.apsi.net A 51.68.207.177
Configuration OVH1 (Serveur Principal)
Postfix - /etc/postfix/main.cf
Certificats TLS :
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.apsi.net/fullchain.pem smtpd_tls_key_file=/etc/letsencrypt/live/mail.apsi.net/privkey.pem smtpd_tls_security_level=may
Authentication SASL (Dovecot) :
smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous
Hostname et domaines :
myhostname = mail.apsi.net mydestination = $myhostname, apsi.net, voilou.nl, localhost home_mailbox = Maildir/
Restrictions :
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
Dovecot - /etc/dovecot/conf.d/
10-mail.conf :
mail_location = maildir:~/Maildir
10-ssl.conf :
ssl_cert = </etc/letsencrypt/live/mail.apsi.net/fullchain.pem ssl_key = </etc/letsencrypt/live/mail.apsi.net/privkey.pem
10-master.conf (Auth socket pour Postfix) :
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
Roundcube - /etc/roundcube/config.inc.php
Connexion IMAP :
$config['default_host'] = 'tls://localhost';
$config['default_port'] = 143;
$config['imap_auth_type'] = null; // Auto-detect
$config['imap_conn_options'] = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
),
);
Connexion SMTP :
$config['smtp_server'] = 'tls://localhost';
$config['smtp_port'] = 587;
$config['smtp_user'] = '%u';
$config['smtp_pass'] = '%p';
$config['smtp_auth_type'] = null;
Permissions fichier :
chown root:www-data /etc/roundcube/config.inc.php
chmod 640 /etc/roundcube/config.inc.php
Firewall - /etc/iptables.d.new/iptables.start
Ports ouverts :
# Port 25 : SMTP (réception depuis autres serveurs mail)
# Port 587 : Submission avec STARTTLS
# Port 465 : SMTPS (envoi authentifié SSL/TLS)
# Port 143 : IMAP (lecture emails)
# Port 993 : IMAPS (lecture emails sécurisée SSL/TLS)
iptables -A INPUT -p tcp -m multiport --dports 25,587,465,143,993 -j ACCEPT
Fail2ban
Jails actifs : - postfix-sasl (protection auth SMTP) - dovecot (protection auth IMAP) - sshd
Configuration OVH2 (Relay Backup)
Postfix - /etc/postfix/main.cf
Configuration relay :
myhostname = backup.apsi.net relay_domains = apsi.net, voilou.nl relay_transport = smtp:[mail.apsi.net]:25 inet_protocols = ipv4 mailbox_size_limit = 0 message_size_limit = 52428800
Résolution DNS - /etc/hosts
Ajout pour résolution directe :
51.83.2.131 mail.apsi.net
Firewall - /etc/iptables.d.new/iptables.start.ClaudePayant
Ports ouverts :
# Port 25 : SMTP pour relay de backup mail
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
ip6tables -A INPUT -p tcp --dport 25 -j ACCEPT
# SORTIES MAIL : permettre au serveur relay d'envoyer vers ovh1
iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 25 -j ACCEPT
Configuration SPF, DKIM et DMARC
OpenDKIM - /etc/opendkim.conf
Configuration multi-domaines :
Mode sv Canonicalization relaxed/simple Socket local:/var/spool/postfix/opendkim/opendkim.sock KeyTable refile:/etc/opendkim/KeyTable SigningTable refile:/etc/opendkim/SigningTable ExternalIgnoreList /etc/opendkim/TrustedHosts InternalHosts /etc/opendkim/TrustedHosts
Fichiers de configuration :
/etc/opendkim/KeyTable :
mail._domainkey.apsi.net apsi.net:mail:/etc/opendkim/keys/apsi.net/mail.private mail._domainkey.voilou.nl voilou.nl:mail:/etc/opendkim/keys/voilou.nl/mail.private
/etc/opendkim/SigningTable :
*@apsi.net mail._domainkey.apsi.net *@voilou.nl mail._domainkey.voilou.nl
/etc/opendkim/TrustedHosts :
127.0.0.1 localhost mail.apsi.net apsi.net voilou.nl 51.83.2.131
Postfix Integration - /etc/postfix/main.cf
Configuration milter :
milter_default_action = accept milter_protocol = 6 smtpd_milters = local:opendkim/opendkim.sock non_smtpd_milters = $smtpd_milters
Clés DKIM Générées
Emplacement : - /etc/opendkim/keys/apsi.net/mail.private (clé privée) - /etc/opendkim/keys/voilou.nl/mail.private (clé privée)
Taille des clés : 1024 bits (compatibles PowerAdmin) - Les clés ont été générées en 1024 bits car PowerAdmin tronque les enregistrements TXT longs - Les clés 2048 bits (~400 caractères) dépassent la limite de PowerAdmin - Les clés 1024 bits (~230 caractères) fonctionnent correctement
Permissions :
chown opendkim:opendkim /etc/opendkim/keys/*/mail.private
chmod 600 /etc/opendkim/keys/*/mail.private
Enregistrements DNS à Ajouter
Fichier complet : /root/IA/MAIL.APSI.NET/DNS_RECORDS_SPF_DKIM_DMARC.txt
Pour apsi.net :
SPF (TXT) :
apsi.net. TXT "v=spf1 mx ip4:51.83.2.131 ip4:51.68.207.177 ~all"
DKIM (TXT) - Clé 1024 bits compatible PowerAdmin :
mail._domainkey.apsi.net. TXT "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDoDc7b7mrS9IEkE331OW/1wYAoCWfaSoU9orNrEm7zclCCYh62hjYJMbQT5rVcISH/hU3uOTUyGjUwqFw/emYw3CnwJwwOSgqM44n30cBwWP3+piy+DnPXFZpJDR4iBBYTygbKXu3X0BCAgX7pnD79kqLxaRjktn3sBYa/RP9ZZQIDAQAB"
DMARC (TXT) :
_dmarc.apsi.net. TXT "v=DMARC1; p=quarantine; rua=mailto:postmaster@apsi.net; ruf=mailto:postmaster@apsi.net; fo=1; adkim=r; aspf=r; pct=100"
Pour voilou.nl :
SPF (TXT) :
voilou.nl. TXT "v=spf1 mx ip4:51.83.2.131 ip4:51.68.207.177 ~all"
DKIM (TXT) - Clé 1024 bits compatible PowerAdmin :
mail._domainkey.voilou.nl. TXT "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMonQQKDHEUPkcQFr0Uxeaqpw0tF2pm/NiEIvPBM7TCmLZUJ9tu9yviBO9Mrrn2hDjdNSgAxWNWIzzRPIlpfCrRnUdqOOp+NeftiqsBP02pg8bQDQxgA+InGSgvQYhGd6BDF6yxA8lf7eNkVEDGrPfnNRLSJMWzJveTpzVIjIwfwIDAQAB"
DMARC (TXT) :
_dmarc.voilou.nl. TXT "v=DMARC1; p=quarantine; rua=mailto:postmaster@voilou.nl; ruf=mailto:postmaster@voilou.nl; fo=1; adkim=r; aspf=r; pct=100"
Vérification DNS
Après ajout des enregistrements (délai 1-24h) :
# Vérifier SPF
dig +short TXT apsi.net
dig +short TXT voilou.nl
# Vérifier DKIM
dig +short TXT mail._domainkey.apsi.net
dig +short TXT mail._domainkey.voilou.nl
# Vérifier DMARC
dig +short TXT _dmarc.apsi.net
dig +short TXT _dmarc.voilou.nl
Test de Signature DKIM
Vérifier qu’OpenDKIM signe les emails :
# Logs OpenDKIM
journalctl -u opendkim -n 50
# Tester les clés
opendkim-testkey -d apsi.net -s mail -vvv
opendkim-testkey -d voilou.nl -s mail -vvv
# Vérifier signature dans email
grep "DKIM-Signature" /home/pchevalier/Maildir/cur/*
Résultat attendu dans les logs :
opendkim: DKIM-Signature field added (s=mail, d=apsi.net)
Tests en Ligne
Envoyer un email de test à : - check-auth@verifier.port25.com - postmaster@dkimvalidator.com
Ces services renvoient un rapport complet sur SPF, DKIM et DMARC.
Configuration Client Thunderbird
Paramètres IMAP
- Serveur : mail.apsi.net
- Port : 143
- Sécurité : STARTTLS
- Auth : Mot de passe normal
- Nom utilisateur : pchevalier@apsi.net
Paramètres SMTP
- Serveur : mail.apsi.net
- Port : 587
- Sécurité : STARTTLS
- Auth : Mot de passe normal
- Nom utilisateur : pchevalier@apsi.net
IMPORTANT : Utiliser le hostname mail.apsi.net, pas l’adresse IP, pour éviter les erreurs de certificat.
Tests de Validation
Test 1 : Relay en Mode Normal
Commande :
ssh root@ovh2.pcstreet.org 'echo "Test relay" | sendmail pchevalier@apsi.net'
Résultat : - ✅ Connexion TLS 1.3 établie entre ovh2 et ovh1 - ✅ Email livré dans /home/pchevalier/Maildir/new/ - ✅ Logs montrent : status=sent (delivered to maildir)
Logs ovh1 :
postfix/smtpd: Anonymous TLS connection established from ovh2.pcstreet.org[51.68.207.177]: TLSv1.3 postfix/local: to=<pchevalier@apsi.net>, relay=local, dsn=2.0.0, status=sent (delivered to maildir)
Test 2 : Relay en Mode Panne
Étapes : 1. Arrêt de Postfix sur ovh1 : systemctl stop postfix 2. Envoi email depuis ovh2 3. Vérification queue ovh2 : mailq montre email en attente avec “Connection refused” 4. Redémarrage ovh1 : systemctl start postfix 5. Force flush queue ovh2 : postqueue -f 6. Vérification : queue vide, email livré
Résultat : - ✅ Email mis en queue pendant la panne - ✅ Email automatiquement livré après récupération - ✅ Aucune perte de mail
Accès Webmail
URL : https://apsi.net/roundcube/
Login : - Utilisateur : pchevalier@apsi.net - Mot de passe : 11as95ap23
Commandes Utiles
Surveillance des logs en temps réel
# Sur ovh1
tail -f /var/log/mail.log
# Sur ovh2
ssh root@ovh2.pcstreet.org 'tail -f /var/log/mail.log'
Vérifier la queue mail
# Sur ovh1
mailq
# Sur ovh2
ssh root@ovh2.pcstreet.org 'mailq'
Forcer le flush de la queue
postqueue -f
Tester IMAP manuellement
timeout 5 bash -c '
exec 3<>/dev/tcp/localhost/993
cat <&3 &
echo "a1 LOGIN pchevalier@apsi.net 11as95ap23" >&3
sleep 1
echo "a2 LOGOUT" >&3
sleep 1
'
Vérifier les certificats
openssl s_client -connect mail.apsi.net:993 -starttls imap
openssl s_client -connect mail.apsi.net:587 -starttls smtp
Statut des services
systemctl status postfix
systemctl status dovecot
systemctl status apache2
systemctl status fail2ban
Sécurité
Fail2ban Protection
- Bannissement après : 5 tentatives échouées
- Durée ban : 10 minutes
- Services protégés : Postfix SASL, Dovecot IMAP, SSH
Firewall
- Seuls les ports mail nécessaires sont ouverts
- Connexions sortantes mail autorisées pour relay
- Protection DDoS basique active
Certificats SSL/TLS
- Émetteur : Let’s Encrypt
- Renouvellement : Automatique via certbot
- Protocoles : TLS 1.2 minimum
- Ciphers : Strong ciphers uniquement
Maintenance
Renouvellement certificats Let’s Encrypt
certbot renew --dry-run # Test
certbot renew # Renouvellement réel
systemctl reload postfix dovecot apache2
Rotation des logs
Les logs sont automatiquement rotés par logrotate.
Mise à jour du système
apt update && apt upgrade
systemctl restart postfix dovecot apache2
Dépannage
Email non reçu
- Vérifier les logs :
tail -n 100 /var/log/mail.log - Vérifier la queue :
mailq - Vérifier le pare-feu :
iptables -L -n - Tester la connectivité :
telnet mail.apsi.net 25
Roundcube ne se connecte pas
- Vérifier permissions :
ls -l /etc/roundcube/config.inc.php - Vérifier logs :
tail /var/log/roundcube/*.log - Vérifier Dovecot :
systemctl status dovecot - Tester IMAP :
telnet localhost 143
Relay ne fonctionne pas
- Vérifier DNS :
host mail.apsi.net(sur ovh2) - Vérifier connectivité :
telnet mail.apsi.net 25(depuis ovh2) - Vérifier logs ovh2 :
tail -f /var/log/mail.log - Vérifier configuration relay :
postconf relay_domains relay_transport
Résumé Architecture
Internet | v [MX 10] mail.apsi.net (51.83.2.131) - ovh1 | +-- Postfix (SMTP: 25, 587, 465) +-- Dovecot (IMAP: 143, 993) +-- Roundcube (HTTPS: 443) +-- Fail2ban | v /home/*/Maildir/ [MX 20] backup.apsi.net (51.68.207.177) - ovh2 | +-- Postfix Relay +-- Queue backup si ovh1 down | v (relay vers) mail.apsi.net:25
Flux normal : Internet → ovh1 → Postfix → Dovecot → Maildir → Thunderbird/Roundcube
Flux si panne ovh1 : Internet → ovh2 → Queue → (attente récupération ovh1) → ovh1 → Maildir
Auteur
Configuration réalisée le 31 décembre 2025. Tests validés avec succès en mode normal et mode panne.