====== Postfix - OP25B環境でFQDNを持たないホストからメールを投げる方法(SMTPリレー) ====== LAN内でFreeBSD/Linux鯖を動かし、ジャーナルやアラートをインタネットメールで \\ 投げたい事ってありますよね。 昔は第三者中継なんて気にしてなかったので深く考えないでメールが出せました。 \\ 今は25/tcpのパケットを外に出すことすら難しく、FQDNが正しくセットされていな \\ い計算機からのメールを受け取ってくれる奇特なsmtpサーバは皆無です。 postfixはsmtp-auth(smtp認証)のクライアントになってメールを特定の中継smtp \\ サーバに投げつけてくれる機能がありました。 smtp-auth(smtp認証)がサポートされているsmtpサーバにsmtp-authでアクセスす るために ===== Transportのサーバ側 ===== ※サーバ側は、色んなクライアントいるし「smtpd_tls_security_level=may」が良いかも smtpd_tls_security_level=encript だとTLSを強制。 smtpd_tls_security_level=may だとTLSが使える場合だけ使う。 ^値^意味^ |may|may を指定した場合は TLS は必須ではなく、TLS を使用するかどうかはクライアント側で決められます。 \\ そのため TLS に対応していないクライアントからの非暗号化の SMTP 通信も許可されます。 \\ こちらが一般的な設定になります。| |encrypt|encrypt は TLS が必須となり、TLS に対応していないクライアントからのメッセージは受け取りません。 \\ そのため機密情報などをやり取りするような、高いセキュリティレベルが求められる特別な MTA にのみ設定します。 | submission inet n - n - - smtpd -o smtpd_tls_security_level=may -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING ====== インストール ====== # yum -y install postfix ====== smtp認証ファイル用意 ====== hostname:port username:password # vi /etc/postfix/relay_password mail.flat8.co.jp:587 hogehoge:xxhoge ====== transportファイル用意 ====== # vi /etc/postfix/transport * smtp:dns.flat8.co.jp:587 ====== hashDB化 ====== # postmap /etc/postfix/relay_password # postmap /etc/postfix/transport === hashDB化したファイルを見るには === # strings /etc/postfix/transport.db smtp:dns.flat8.co.jp:587 ====== main.cfに下記追加 ====== # vi /etc/postfix/main.cf smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/relay_password smtp_sasl_security_options = noanonymous transport_maps = hash:/etc/postfix/transport smtp_tls_CApath = /etc/ssl/certs smtp_tls_security_level=may smtp_tls_loglevel = 1 ===== Untrusted TLS ===== これは暗号化自体はされているけど、transportクライアントのOS側にLet's EncryptのCA証明書が入ってないから ※最近のブラウザは、Let's EncryptのCA証明書が入ってる。 Apr 20 12:11:48 adm3004 postfix/smtp[23618]: setting up TLS connection to relay.hogehoge.com[xxx.xxx.72.82]:587 Apr 20 12:11:48 adm3004 postfix/smtp[23618]: certificate verification failed for relay.hogehoge.com[xxx.xxx.72.82]:587: untrusted issuer /O=Digital Signature Trust Co./CN=DST Root CA X3 Apr 20 12:11:48 adm3004 postfix/smtp[23618]: Untrusted TLS connection established to relay.hogehoge.com[xxx.xxx.72.82]:587: TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits) /etc/ssl/certs以下にLet's EncryptのCS証明書を置いておく。 * ISRG Root X1 (self-signed) * Let’s Encrypt Authority X3 (IdenTrust cross-signed) * Let’s Encrypt Authority X3 (Signed by ISRG Root X1) cd /etc/ssl/certs wget https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt wget https://letsencrypt.org/certs/isrgrootx1.pem.txt wget https://letsencrypt.org/certs/letsencryptauthorityx3.pem.txt ====== postfixをreload ====== # /usr/sbin/postfix reload ====== logwatchの送り先変更 ====== [[01_linux:01_net:logwatchの設定|]] ===== CentOS 6 の場合 ===== 下記のエラーが出て送信できない SASL authentication failure: No worthy mechs found SASL authentication failed; cannot authenticate to server mail.flat8.co.j === 対応方法 === 下記のライブラリをインストールしてあげると上手くい # yum install cyrus-sasl-md5 [[https://smtps.jp/docs/integrate/si/postfix/index.html]] [[https://linux-svr.com/SSL%E8%A8%BC%E6%98%8E%E6%9B%B8/41.php]] {{tag>postfix mail transport}}