Postfixで外部からのメールが受信できない…587が開いてない?問題を解決(CentOS7、さくらVPS)

さくらVPSで新しいサーバhogehogeを立てて、ここでいくつかのドメインのメールアドレスを、Postfixのバーチャルホストで受信だけ転送する予定で。

が、なぜかメールの受信ができない。自分のサーバ内のサイトにあるフォームからの送信は、ローカル転送なので受け取れるんだけど、外部からのメールが全然届かない。

他のサーバfugafugaからmailコマンドで試してみると、こんなエラーが出ている。

Apr 30 23:08:23 fugafuga postfix/smtp[15437]: connect to mx.hogehoge.net[153.126.209.139]:25: No route to host

「ホストへのルートがないので接続できない。」
ああー、これはあれだな。さくらVPSのヘルプに書いてあったけど、25番ポートが使えなくて、OBP 587(Submission posrt)を使わないといけないっちゅうアレやろ。と合点して、さくらVPSの下記ヘルプページを参照して、master.cfとmain.cfをそれぞれ編集。

5.Submissionポート設定

Submissionポート(587番ポート)を設定します。
設定するには、/etc/postfix/master.cfを編集します。

[root@ ~]# vi /etc/postfix/master.cf

下記のハイライト部分の行頭にある#を削除します。

#
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       n       -       -       smtpd
#smtp      inet  n       -       n       -       1       postscreen
#smtpd     pass  -       -       n       -       -       smtpd
#dnsblog   unix  -       -       n       -       0       dnsblog
#tlsproxy  unix  -       -       n       -       0       tlsproxy
submission inet n       -       n       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       n       -       -       smtpd
#  -o syslog_name=postfix/smtps
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING

以上で、master.cfの編集完了です。

ところが、これで何度試しても、「25: no route to host」のエラーが解除されず、メールが受け取れない。

fugafugaからtelnetしてみても繋がらない。

[dacelo@fugafuga ~]$ telnet hogehoge.net 587
Trying 123.456.789.000...
telnet: connect to address 153.126.209.139: No route to host

2日ほどハマってたんですけど、ハタと気づいた。サーバ内ファイヤウォールだ。それも、iptablesじゃなくて、CentOS7だからfirewalldだったんだ。

firewalldでSMTP用のポートを開放

まずサービスが動いていることを確認。

[dacelo@hogehoge ~]$ systemctl list-unit-files | grep firewalld
firewalld.service                             enabled

現在許可しているサービスを確認。

[dacelo@hogehoge ~]$ sudo firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client http ssh https
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

サブミッションポートを許可サービスに追加。

[dacelo@hogehoge ~]$ sudo firewall-cmd --permanent --zone=public --add-service=smtp-submission
success

firewalldを再起動して反映。

[dacelo@hogehoge ~]$ sudo systemctl restart firewalld

ところがこの状態でも、外部からメールを送信しようとすると繋がらない。

Apr 30 23:08:23 fugafuga postfix/smtp[15437]: connect to mx.hogehoge.net[123.456.789.000]:25: No route to host

エラーメッセージからは、25番につなごうとしている気配なんだけど、587につないでほしいのよね。うーん。どうやって587に繋いでもらえばいいのか…。あれ?mailコマンドって指定しないとデフォルトでは25番につなぐっていう話なんじゃないか?ひょっとして。そうだよ。メールクライアントの役割だもんな。

でも待てよ。firewalldで25番も開放しちまえばいいんじゃないか?

広告

[dacelo@hogehoge ~]$ sudo firewall-cmd --permanent --zone=public --add-service=smtp
success

firewalldを再起動して反映。

[dacelo@hogehoge ~]$ sudo systemctl restart firewalld

そしたらめでたく繋がり、配信・受信できました。

Apr 30 23:42:08 www5254ue postfix/smtp[15941]: 71F13302205: to=, relay=mx.hogehoge.net[123.456.789.000]:25, delay=80220, delays=80220/0.02/0.17/0.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as C7AE8E00303D)

25番開けておいていいのかという問題はひとまず置いておいて、今日のところはこれで完了。

About: dacelo


2 thoughts on “Postfixで外部からのメールが受信できない…587が開いてない?問題を解決(CentOS7、さくらVPS)”

  1. 初めまして。

    私もさくらのVPSで同じ症状でハマって、同様にfirewalldでsmtpを開放してしのいでいます。
    私もセキュリティが気になっているのですが、このあと、何か追加の設定をされましたでしょうか?

    ご教授いただければ幸いです。

    1. 結局25番ポートを開放し続けたまま今に至ります…。
      お役に立てず申し訳ないです。
      逆にそちらでも何か分かりましたらご教授いただければ、と…

Leave a Reply to TAKA Cancel reply

Your email address will not be published. Required fields are marked *