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


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

  1. 初めまして。

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

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

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

  2. Hello my friend! I want to say that this article is awesome, great written and
    include approximately all vital infos. I would like to peer more posts like this .

  3. Excellent site you have here but I was wanting to know if
    you knew of any community forums that cover the same topics talked about in this article?
    I’d really love to be a part of group where I can get responses from other experienced people that share the same interest.
    If you have any suggestions, please let me know. Thanks
    a lot!

  4. Do you have a spam problem on this blog; I also am a blogger,
    and I was curious about your situation; many of us have developed some nice procedures and we are looking to
    exchange techniques with other folks, be sure to shoot me an email
    if interested.

  5. I’m curious to find out what blog system you have been working with?
    I’m experiencing some minor security issues with my latest site and I’d like to find something more safeguarded.
    Do you have any solutions?

  6. When I originally left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and
    now each time a comment is added I receive four emails with the exact same comment.
    Perhaps there is an easy method you are able to remove me
    from that service? Thanks a lot!

  7. Hi there, i read your blog occasionally and i own a
    similar one and i was just wondering if you get a lot of spam
    feedback? If so how do you reduce it, any plugin or anything you
    can suggest? I get so much lately it’s driving me mad so any assistance is very much appreciated.

  8. Cool blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple tweeks would really make my blog
    stand out. Please let me know where you got your theme.
    Bless you

  9. I absolutely love your site.. Very nice colors & theme. Did you create this web site yourself?
    Please reply back as I’m trying to create my own blog and would love to know where you got this from or
    just what the theme is called. Kudos!

  10. Hello There. I found your blog using msn. This is an extremely well written article.
    I will make sure to bookmark it and return to
    read more of your useful info. Thanks for the post. I will definitely
    return.

  11. Thanks for finally writing about > Postfixで外部からのメールが受信できない…587が開いてない?問題を解決(CentOS7、さくらVPS) – DACELO SPACE < Liked it!

  12. I’ve been exploring for a bit for any high-quality articles or blog posts on this sort of space .
    Exploring in Yahoo I ultimately stumbled upon this website.
    Reading this information So i’m happy to exhibit that
    I have a very excellent uncanny feeling I found out exactly what I needed.
    I so much indisputably will make certain to don?t put
    out of your mind this website and provides it a glance regularly.

  13. Thanks a lot for sharing this with all people you actually recognise what you’re talking
    approximately! Bookmarked. Kindly additionally discuss with my website =).

    We can have a hyperlink trade contract among us

  14. Hi excellent blog! Does running a blog like this require a great deal of work?
    I’ve virtually no understanding of coding
    but I was hoping to start my own blog soon. Anyway,
    should you have any ideas or techniques for new blog owners please share.
    I know this is off subject however I simply wanted to
    ask. Thanks a lot!

  15. Have you ever thought about writing an e-book
    or guest authoring on other sites? I have a blog centered on the same subjects you discuss and would really
    like to have you share some stories/information. I know my subscribers would enjoy your work.

    If you’re even remotely interested, feel free to send me an email.

  16. Good day very cool website!! Man .. Excellent .. Superb ..
    I will bookmark your blog and take the feeds additionally?
    I’m glad to find a lot of useful info here within the post, we’d like
    develop more techniques on this regard, thank you for sharing.
    . . . . .

  17. You actually make it appear so easy together with your presentation however I in finding this matter to be actually something that I feel I might never understand.
    It kind of feels too complicated and extremely vast
    for me. I am taking a look forward to your subsequent submit,
    I will attempt to get the hang of it!

  18. Hi there, You have done an excellent job. I’ll definitely digg
    it and personally recommend to my friends. I am confident they’ll be benefited from this web site.

  19. May I just say what a relief to discover an individual who actually knows
    what they’re discussing on the web. You certainly realize how to
    bring a problem to light and make it important.
    More and more people have to read this and understand this side of the story.
    It’s surprising you aren’t more popular since you certainly possess the gift.

  20. Hi, I do think this is an excellent website. I stumbledupon it 😉 I may come back yet again since i have saved as a favorite it.
    Money and freedom is the greatest way to change, may
    you be rich and continue to guide others.

  21. My brother suggested I may like this blog. He was entirely right.
    This post actually made my day. You can not consider simply how a lot
    time I had spent for this information! Thanks!

  22. I really love your blog.. Pleasant colors & theme. Did you make this website yourself?
    Please reply back as I’m wanting to create my own blog and want to find out where you got this from or just what the theme is named.
    Cheers!

  23. I know this if off topic but I’m looking into starting
    my own weblog and was curious what all is required to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very web savvy so I’m not 100% certain. Any suggestions or advice
    would be greatly appreciated. Many thanks

  24. Woah! I’m really loving the template/theme of this website.
    It’s simple, yet effective. A lot of times
    it’s difficult to get that “perfect balance” between user friendliness and
    appearance. I must say that you’ve done a amazing job
    with this. Also, the blog loads extremely fast for
    me on Safari. Excellent Blog!

  25. Hi excellent website! Does running a blog like this take
    a massive amount work? I’ve virtually no understanding of coding but I had been hoping to
    start my own blog in the near future. Anyways, should you have any recommendations or techniques for new blog owners please share.
    I know this is off topic however I simply had to ask.
    Thanks a lot!

Leave a Reply

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