Postfix » Historique » Version 53
Patrice Nadeau, 2016-02-05 15:03
| 1 | 13 | Patrice Nadeau | h1. Postfix |
|---|---|---|---|
| 2 | 1 | Patrice Nadeau | |
| 3 | 12 | Patrice Nadeau | > Issue : #16 |
| 4 | |||
| 5 | 4 | Patrice Nadeau | http://www.postfix.org |
| 6 | 1 | Patrice Nadeau | |
| 7 | Logiciel de courrier électronique permettant, le transfert de courrier électronique (Message Transfert Agent). |
||
| 8 | |||
| 9 | Souvent installé de base pour l’envoie des message du serveur à une adresse externe. |
||
| 10 | 14 | Patrice Nadeau | |
| 11 | ---- |
||
| 12 | |||
| 13 | {{toc}} |
||
| 14 | |||
| 15 | 5 | Patrice Nadeau | Si le serveur doit envoyer et recevoir des messages de et vers l’Internet, les items suivant sont obligatoire : |
| 16 | * Domaine : Un nom de domaine enregistrer et sa gestion disponible |
||
| 17 | 1 | Patrice Nadeau | * MX records : pour permettre la réception de courriel. |
| 18 | 5 | Patrice Nadeau | * SPF records : pour permettre l’envoie de messages sans être bannis par les « reverse lookup ». |
| 19 | 1 | Patrice Nadeau | |
| 20 | 21 | Patrice Nadeau | Un serveur de relais (SMTP) externe seras nécessaire pour envoyer des courriels vers l’Internet si le port 25 est bloqué en entré (la majorité des cas). |
| 21 | 1 | Patrice Nadeau | |
| 22 | Les fichiers de configuration sont : |
||
| 23 | 5 | Patrice Nadeau | * _/etc/postfix/master.cf_ |
| 24 | * _/etc/postfix/main.cf_ |
||
| 25 | |||
| 26 | 13 | Patrice Nadeau | h2. Installation |
| 27 | 5 | Patrice Nadeau | |
| 28 | <pre><code class="bash"> |
||
| 29 | 50 | Patrice Nadeau | zypper install postfix perl-Mail-SP |
| 30 | wget http://download.opensuse.org/repositories/devel:/languages:/perl/openSUSE_Leap_42.1/noarch/postfix-policyd-spf-perl-2.010-3.1.noarch.rpm |
||
| 31 | rpm -Uhv postfix-policyd-spf-perl-2.010-3.1.noarch.rpm |
||
| 32 | 15 | Patrice Nadeau | systemctl enable postfix |
| 33 | systemctl start postfix |
||
| 34 | 17 | Patrice Nadeau | # Ouvrir dans le pare-feu seulement si le serveur doit recevoir des courriels |
| 35 | 22 | Patrice Nadeau | yast firewall services add service=service:smtp zone=EXT |
| 36 | 5 | Patrice Nadeau | </code></pre> |
| 37 | |||
| 38 | 42 | Patrice Nadeau | h2. Configuration de base |
| 39 | 5 | Patrice Nadeau | |
| 40 | 21 | Patrice Nadeau | Si les courriels doivent sortir via un relais sur un autre serveur SMTP, modifier le fichier _/etc/postfix/main.cf_ : |
| 41 | 5 | Patrice Nadeau | <pre><code class="bash"> |
| 42 | # Inscrire votre serveur SMTP de sortie |
||
| 43 | relayhost = smtp_server |
||
| 44 | # Spécifier toutes les interfaces |
||
| 45 | inet_interfaces = all |
||
| 46 | # A la ligne mydestination, ajouter |
||
| 47 | $mydomain |
||
| 48 | # Permettre aux machines du réseau local, l'utilisation du serveur |
||
| 49 | smtpd_client_restrictions = permit_mynetworks |
||
| 50 | </code></pre> |
||
| 51 | > La ligne myhostname DOIT être la même que l’enregistrement DNS de type MX sur internet pour ce domaine. |
||
| 52 | 1 | Patrice Nadeau | |
| 53 | 13 | Patrice Nadeau | h2. Création de «blacklist» et de «whitelist». |
| 54 | 1 | Patrice Nadeau | |
| 55 | 6 | Patrice Nadeau | Informations provenant de : http://www.postfix.org/RESTRICTION_CLASS_README.html |
| 56 | 1 | Patrice Nadeau | |
| 57 | 6 | Patrice Nadeau | Fichier _/etc/postfix/main.cf_ |
| 58 | <pre><code class="bash"> |
||
| 59 | smtpd_recipient_restrictions = |
||
| 60 | check_sender_access hash: /etc/postfix/sender_access |
||
| 61 | </code></pre> |
||
| 62 | 1 | Patrice Nadeau | |
| 63 | 6 | Patrice Nadeau | Créer un fichier _/etc/postfix/sender_access_. |
| 64 | Placer à l’intérieur, l’adresse de courriel, le nom de domaine ou l’adresse IP avec l’une des options : |
||
| 65 | * OK |
||
| 66 | * REJECT |
||
| 67 | 1 | Patrice Nadeau | |
| 68 | 6 | Patrice Nadeau | Modifier le fichier _/etc/postfix/sender_access_ : |
| 69 | <pre><code class="bash"> |
||
| 70 | # myfriend.com OK |
||
| 71 | # myennemies.com REJECT |
||
| 72 | # myfriend@example.com OK |
||
| 73 | # junk@spam.com REJECT |
||
| 74 | # marketing@ REJECT |
||
| 75 | # theboss@ OK |
||
| 76 | # deals.marketing.com REJECT |
||
| 77 | # somedomain.com OK |
||
| 78 | 101.15.251.176 REJECT |
||
| 79 | </code></pre> |
||
| 80 | |||
| 81 | 7 | Patrice Nadeau | Relancer : |
| 82 | <pre><code class="bash"> |
||
| 83 | postmap /etc/postfix/sender_access |
||
| 84 | postfix reload |
||
| 85 | </code></pre> |
||
| 86 | |||
| 87 | 13 | Patrice Nadeau | h3. Utilisation de services de « blacklist » internet : |
| 88 | 7 | Patrice Nadeau | |
| 89 | Modifier le fichier _/etc/postfix/main.cf_ : |
||
| 90 | <pre><code class="bash"> |
||
| 91 | 29 | Patrice Nadeau | smtpd_recipient_restrictions = reject_rbl_client zen.spamhaus.org, reject_rhsbl_helo dbl.spamhaus.org, reject_rhsbl_sender dbl.spamhaus.org |
| 92 | </code></pre> |
||
| 93 | |||
| 94 | Relire la configuration |
||
| 95 | <pre><code class="bash"> |
||
| 96 | systemctl reload postix |
||
| 97 | 7 | Patrice Nadeau | </code></pre> |
| 98 | 6 | Patrice Nadeau | |
| 99 | 53 | Patrice Nadeau | h3. Utilisation des enregistrements SPF |
| 100 | 51 | Patrice Nadeau | |
| 101 | Modifier le fichier _/etc/postfix/main.cf_ et ajouter *à la suite* de la ligne _smtpd_recipient_restrictions_ : |
||
| 102 | <pre><code class="bash"> |
||
| 103 | check_policy_service unix:private/policy |
||
| 104 | </code></pre> |
||
| 105 | |||
| 106 | 52 | Patrice Nadeau | Modifier le fichier_/etc/postfix/master.cf_ eta jouter la ligne : |
| 107 | <pre><code class="bash"> |
||
| 108 | policy unix - n n - 0 spawn user=nobody argv=/usr/bin/perl /usr/lib/policyd-spf-perl |
||
| 109 | </code></pre> |
||
| 110 | |||
| 111 | 13 | Patrice Nadeau | h3. Alias |
| 112 | 10 | Patrice Nadeau | |
| 113 | 20 | Patrice Nadeau | Usagers systèmes devant être redirigé vers des comptes utilisateurs réel. |
| 114 | 10 | Patrice Nadeau | |
| 115 | 20 | Patrice Nadeau | Les ajouter dans le fichier _/etc/postfix/aliases_ |
| 116 | |||
| 117 | Lancer la commande _newaliases_ pour activer les changements. |
||
| 118 | |||
| 119 | 10 | Patrice Nadeau | |
| 120 | 13 | Patrice Nadeau | h3. Options courantes |
| 121 | 11 | Patrice Nadeau | |
| 122 | Dans _main.cf_ : |
||
| 123 | * *message_size_limit* : |
||
| 124 | |||
| 125 | 13 | Patrice Nadeau | h2. Entrés DNS |
| 126 | 6 | Patrice Nadeau | |
| 127 | 13 | Patrice Nadeau | h3. A record |
| 128 | 6 | Patrice Nadeau | |
| 129 | 13 | Patrice Nadeau | h3. MX record |
| 130 | 6 | Patrice Nadeau | |
| 131 | 13 | Patrice Nadeau | h3. SPF record |
| 132 | 6 | Patrice Nadeau | |
| 133 | 2 | Patrice Nadeau | Ajouter ceux du fournisseur internet (le fournisseur et et tous ses abonnées pourront "se faire passer" pour le domaine) |
| 134 | |||
| 135 | 13 | Patrice Nadeau | h2. Test |
| 136 | 2 | Patrice Nadeau | |
| 137 | 13 | Patrice Nadeau | h3. SPF |
| 138 | 3 | Patrice Nadeau | |
| 139 | Envoyer un courriel à une des adresses suivantes : |
||
| 140 | * check-auth@verifier.port25.com |
||
| 141 | 6 | Patrice Nadeau | * check-auth2@verifier.port25.com |
| 142 | 8 | Patrice Nadeau | |
| 143 | 43 | Patrice Nadeau | h2. TLS |
| 144 | 19 | Patrice Nadeau | |
| 145 | Site internet pour vérifier la configuration TLS : |
||
| 146 | * Envoie : https://www.checktls.com/perl/TestSender.pl |
||
| 147 | * Réception : https://www.checktls.com/perl/TestReceiver.pl |
||
| 148 | |||
| 149 | 37 | Patrice Nadeau | 2 paramètres sont utilisés : |
| 150 | * *smtp_tls_security_level* : En envoie vers un autre serveur SMTP |
||
| 151 | * *smtpd_tls_security_level* : En réception d'un client |
||
| 152 | |||
| 153 | Les valeurs suivantes peuvent être utilisées : |
||
| 154 | * *none* : TLs n'est pas utilisé |
||
| 155 | 45 | Patrice Nadeau | * *may* : TLS est utilisé/annoncé au client distant mais n'est pas obligatoire (Opportunistic) |
| 156 | 37 | Patrice Nadeau | * *encrypt* : TLS DOIT être utilisé. Selon le "RFC 2487":http://tools.ietf.org/html/rfc2487, cette option ne devrait pas être utilisée avec des serveur publiques. |
| 157 | |||
| 158 | 43 | Patrice Nadeau | h3. De Postfix vers un autre serveur SMTP |
| 159 | 31 | Patrice Nadeau | |
| 160 | 35 | Patrice Nadeau | Dans le fichier _/etc/postfix/mainc.cf_ |
| 161 | 1 | Patrice Nadeau | <pre><code class="bash"> |
| 162 | 35 | Patrice Nadeau | # Utilise l'encryption si disponible |
| 163 | smtp_tls_security_level = may |
||
| 164 | 45 | Patrice Nadeau | # Ajoute les messages TLS au journal |
| 165 | 35 | Patrice Nadeau | smtp_tls_loglevel = 1 |
| 166 | </code></pre> |
||
| 167 | 1 | Patrice Nadeau | |
| 168 | 47 | Patrice Nadeau | Dans le fichier _/etc/postfix/master.cf_, enlever le commentaire au début de la ligne |
| 169 | <pre><code class="bash"> |
||
| 170 | tlsmgr unix - - n 1000? 1 tlsmgr |
||
| 171 | </code></pre> |
||
| 172 | |||
| 173 | 35 | Patrice Nadeau | Relire la configuration |
| 174 | <pre><code class="bash"> |
||
| 175 | systemctl reload postfix |
||
| 176 | 31 | Patrice Nadeau | </code></pre> |
| 177 | 30 | Patrice Nadeau | |
| 178 | 43 | Patrice Nadeau | h3. D'un client vers Postfix |
| 179 | 36 | Patrice Nadeau | |
| 180 | 37 | Patrice Nadeau | > Voir #54 |
| 181 | |||
| 182 | 40 | Patrice Nadeau | Si un certificat externe n'est pas disponible, en généré un local : |
| 183 | 38 | Patrice Nadeau | <pre><code class="bash"> |
| 184 | cd /etc/postfix |
||
| 185 | openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509 |
||
| 186 | </code></pre> |
||
| 187 | |||
| 188 | 36 | Patrice Nadeau | Dans le fichier _/etc/postfix/main./cf_ |
| 189 | 32 | Patrice Nadeau | <pre><code class="bash"> |
| 190 | # Utilise l'encryption si disponible |
||
| 191 | 1 | Patrice Nadeau | smtp_tls_security_level = may |
| 192 | # Ajoute les messages TLs au journal |
||
| 193 | smtp_tls_loglevel = 1 |
||
| 194 | 41 | Patrice Nadeau | # Fichiers du certificat |
| 195 | 38 | Patrice Nadeau | smtpd_tls_key_file = /etc/postfix/smtpd.key |
| 196 | smtpd_tls_cert_file = /etc/postfix/smtpd.cert |
||
| 197 | 1 | Patrice Nadeau | </code></pre> |
| 198 | 37 | Patrice Nadeau | |
| 199 | Relire la configuration |
||
| 200 | <pre><code class="bash"> |
||
| 201 | systemctl reload postfix |
||
| 202 | </code></pre> |
||
| 203 | 32 | Patrice Nadeau | |
| 204 | 46 | Patrice Nadeau | Si le serveur est disponible à partir d'internet, on peux faire un test avec https://starttls.info/ |
| 205 | |||
| 206 | 44 | Patrice Nadeau | h2. Domaines supplémentaires |
| 207 | |||
| 208 | > Voir #55 |
||
| 209 | |||
| 210 | 13 | Patrice Nadeau | h2. Dépannage |
| 211 | 8 | Patrice Nadeau | |
| 212 | La commande *mailq* permet de voir les requêtes en attentes. |
||
| 213 | 18 | Patrice Nadeau | |
| 214 | 23 | Patrice Nadeau | h3. Messages ne s'envoient pas |
| 215 | |||
| 216 | 26 | Patrice Nadeau | > Vu sur une nouvelle installation openSUSE 13.2 |
| 217 | |||
| 218 | 27 | Patrice Nadeau | La commande _postqueue -p_ affiche : *address resolver failure* |
| 219 | |||
| 220 | 26 | Patrice Nadeau | Modififer le fichier */etc/postfix/main.cf* |
| 221 | <pre><code class="bash"> |
||
| 222 | disable_dns_lookups = yes |
||
| 223 | </code></pre> |
||
| 224 | 25 | Patrice Nadeau | |
| 225 | 23 | Patrice Nadeau | h3. Messages *error: open database /etc/postfix/relay.db: No such file or directory* |
| 226 | |||
| 227 | > Vu sur une nouvelle installation openSUSE 13.2 |
||
| 228 | |||
| 229 | Exécuter la commande |
||
| 230 | <pre><code class="bash"> |
||
| 231 | postmap /etc/postfix/relay |
||
| 232 | 18 | Patrice Nadeau | </code></pre> |