0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[postfix 2.10]myhostname, inet_interfaces, inet_protocols, mynetworks, relay_domains, home_mailbox, mynetworks_style, mydestination, relayhost, transport_maps チートシート

Last updated at Posted at 2020-05-04

Postfix 2.10 基本パラメータ(main.cf)のチートシート

  • この記事のMISSSION
  • 自MTA -> 外部MTAへメール配送できるようにする.
  • 不正中継等, 必要最小限のセキュリティは考慮する.
  • サーバ環境
  • CentOS Linux release 7.6
  • postfix-2.10.1-7.el7.x86_64

May 4, 2020 @pa_pa_paper

myhostname

自ホストのInternet上での名称を設定する.

  • デフォルト値
# myhostname = virtual.domain.tld
  • パラメータ変更後
myhostname = xxxx.vs.sakura.ne.jp

デフォルト値ではlocalhost.localdomainになっている.
Internetに直接接続する環境なら変更は必須.

inet_interfaces

外部MTAから配送されるメールを受取るネットワークI/Fを設定.

  • 標準設定(デフォルト値はall)
# inet_interfaces = $myhostname
# inet_interfaces = $myhostname, localhost
inet_interfaces = 127.0.0.1
  • パラメータ変更後
# inet_interfaces = $myhostname #inet_interfaces = $myhostname, localhost
# inet_interfaces = 127.0.0.1
inet_interfaces = all

標準設定は127.0.0.1のため, 外部MTAからのメールを受取ることができない.
今回は全てのネットワークI/Fでメールを受取るためallを設定.
下記のように$myhostnameをそのまま使うこともある.

inet_interfaces = 192.168.1.2, 127.0.0.1
inet_interfaces = $myhostname, 127.0.0.1

inet_protocols

Postfixのメール配送/受取り時に使用を試みるIPのバージョンを設定.

  • デフォルト値
inet_protocols = all
  • パラメータ変更後
inet_protocols = ipv4

サーバ自体にIPv4のアドレスしか付与していない場合は,デフォルト値のallからipv4へ変更した方がよさそう. postconf(5)によるとallの場合は, IPv6での接続を優先的に試みてから, その後にIPv4での接続を試みるらしい. inet_protocolsのパラメータを適切に設定しないと, メール遅延の原因になったりするときもあるため, 注意が必要.

When both IPv4 and IPv6 support are enabled, the Postfix SMTP client will attempt to connect via IPv6 before attempting to use IPv4.

↓こんな設定もできるらしい

inet_protocols = ipv4, ipv6

mynetworks

25/tcpポートでメールリレーを許可するSMTPクライアントを設定.

  • 標準設定(インストール時はmynetworks_style = hostを適用)
# mynetworks = 168.100.189.0/28, 127.0.0.0/8
# mynetworks = $config_directory/mynetworks
# mynetworks = hash:/etc/postfix/network_table
  • パラメータ変更後
mynetworks = 127.0.0.0/8

インストール時にはmynetworks_style = hostの値が適用され, 自ホストのみ"信頼できる"SMTPクライアントとして25/tcpポートでメールリレーを許可する. postconf(5)にはmynetworksを明示的に設定することで, mynetworks_styleのパラメータは無視されると記載されている.

If you specify the mynetworks list by hand, Postfix ignores the mynetworks_style setting.

SPAMの中継サーバとして悪用されないためにも、注意が必要な設定項目. 仮にInternet上の全てのSMTPクライアントからのメールリレーを許可している場合(オープンリレーと呼ばれる), 不正中継サーバとして, 世界中のMTAに迷惑を掛けてしまうことが予想される. 血迷っても0.0.0.0/0なんて設定してはいけない.

↓例えば, 自ホスト(127.0.0.0/8)と社内ネットワーク(172.0.0.0/8, 168.100.189.0/28)からのみメールリレーを許可したい場合は,下記のように設定するイメージ.

mynetworks = 127.0.0.0/8, 172.0.0.0/8, 168.100.189.0/28

ただ, このままでは色々と不便なことが予想される.(例えばビジネスシーンでは社外からもメールを利用したいなどの要望が想定される)
枯れた技術だけにMessage Submission(587/tcp)ポートという回避策がちゃんと用意されている. Submissionポートとか, SMTP-AUTHとかの話は別の記事で書くよ.

relay_domains

メールリレーを許可するドメイン及びサブドメインの設定.

  • 標準設定(デフォルト値は$mydestination)
# relay_domains = $mydestination

relay_domainsは他の設定項目で間接的に利用される.
relay_domainsにマッチするドメインはrelay_transportでtransport配送されたり, 受信者アドレスをrelay_recipient_mapsで確認し, 存在しない受信者宛てのメール配送を拒否したりする.

Domains that match $relay_domains are delivered with the $relay_transport mail delivery transport. The SMTP server validates recipient addresses with $relay_recipient_maps and rejects non-existent recipients.

home_mailbox

ローカル配送の配送形式を設定.

  • 標準設定(デフォルト値はMailbox)
# home_mailbox = Mailbox
# home_mailbox = Maildir/
  • パラメータ変更後
home_mailbox = Maildir/

mailbox形式からMaildir形式に変更し, 1メール1ファイルで管理する.

mynetworks_style

mynetworksのデフォルト値の生成方法を設定.

  • デフォルト値
mynetworks_style = host

mynetworksを変更すると無視される設定項目のため, あまり変更する機会がないと思う.

mydestination

自ホストが受取るドメインのリストを設定.

  • デフォルト値
mydestination = $myhostname, localhost.$mydomain, localhost

SMTPサーバは受信者アドレスをlocal_recipient_mapsで確認し, 存在しない受信者宛てのメール受取りを拒否する.

The list of domains that are delivered via the $local_transport mail delivery transport. By default this is the Postfix local(8) delivery agent which looks up all recipients in /etc/passwd and /etc/aliases. The SMTP server validates recipient addresses with $local_recipient_maps and rejects non-existent recipients.

local_recipient_mapsはデフォルト値は↓の設定.
local_recipient_maps = proxy:unix:passwd.byname $alias_maps

*本記事では扱わないけど, バーチャルドメインのドメイン名と重複しないように注意する.

relayhost

自ホストが直接Internet上のMTAにメール配送せず、特定のMTAにリレーするような構成で設定.

  • 標準設定(デフォルト値はempty)
# relayhost = $mydomain
# relayhost = [gateway.my.domain]
# relayhost = [mailserver.isp.tld]
# relayhost = uucphost
# relayhost = [an.ip.add.ress]

transport_maps

relayhostだとリレー先を1つのMTAしか指定できない. ドメイン毎に複数リレー先を指定したい時に設定.

  • xxxx.vs.sakura.ne.jp宛てのメールは自ホストでローカル配送
  • dev-xxxx.vs.sakura.ne.jp宛てのメールは指定したMTAにメール配送
transport_maps = hash:/etc/postfix/transport
xxxx.vs.sakura.ne.jp    local:
dev-xxxx.vs.sakura.ne.jp    smtp:[dev-xxxx.vs.sakura.ne.jp]:25

transport_mapsの設定はmydestinationで指定する受信者アドレスよりも優先的に利用されるため, xxxx.vs.sakura.ne.jp local:のように明示的にローカルの設定を記載するようにする.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?