Postfix 実用ガイド
Postfix の設計、設定、運用を詳しく確認したい場合の参考書籍です。価格や在庫はリンク先で確認してください。
Amazon で見るこのリンクは Amazon アソシエイトリンクです。
Ubuntu 26.04 で Postfix を使う場合、単に postfix package を入れるだけではなく、配送範囲、submission / smtps、TLS、LDAP alias、recipient access、設定反映前の検証を分けて考える必要があります。
この記事では、内部向け SMTP 基盤の入口として Postfix を構成する基本をまとめます。公開 MTA のセキュリティ設計や DKIM / DMARC は別記事に分け、ここでは main.cf、master.cf、LDAP alias、recipient access、サービス確認を扱います。
postfixとmailutilsの導入/etc/postfix/main.cfと/etc/postfix/master.cfの管理- submission / smtps と TLS の位置づけ
- LDAP alias を使う場合の
postfix-ldap recipient_accessとpostmap
| 対象 OS | Ubuntu 26.04 Server |
|---|---|
| packages | postfix、mailutils、必要に応じて postfix-ldap |
| main config | /etc/postfix/main.cf |
| service config | /etc/postfix/master.cf |
| LDAP alias | /etc/postfix/ldap-aliases.cf |
| recipient access | /etc/postfix/recipient_access |
Postfix の役割を決める
Postfix はローカル配送、内部リレー、submission、外部配送など複数の役割を持てます。最初に、このサーバーがどのネットワークからメールを受け、どこへ配送してよいかを決めます。
- 内部 SMTP と公開 MTA を混ぜない
- 許可する送信元ネットワークを
mynetworksで限定する - TLS 証明書の配置と信頼を先に確認する
- LDAP alias や recipient access は必要な環境だけ有効化する
packages をインストールする
基本 package として postfix と mailutils を導入します。LDAP alias を使う場合だけ postfix-ldap を追加します。
sudo apt update
sudo apt install -y postfix mailutils
sudo apt install -y postfix-ldap
postconf -d mail_versionmain.cf を管理する
/etc/postfix/main.cf は Postfix の中心設定です。ここでは hostname、domain、配送範囲、TLS、LDAP alias、recipient restriction などをまとめて管理します。
sudo tee /etc/postfix/main.cf >/dev/null <<'EOF'
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mynetworks = 127.0.0.0/8 10.0.0.0/8
smtpd_tls_cert_file = /etc/ssl/certs/mail.example.com.crt
smtpd_tls_key_file = /etc/ssl/private/mail.example.com.key
smtpd_tls_security_level = may
alias_maps = hash:/etc/aliases
virtual_alias_maps = ldap:/etc/postfix/ldap-aliases.cf
smtpd_recipient_restrictions = permit_mynetworks reject_unauth_destination check_recipient_access hash:/etc/postfix/recipient_access
EOF
sudo chown root:root /etc/postfix/main.cf
sudo chmod 0644 /etc/postfix/main.cfmaster.cf で submission と smtps を分ける
/etc/postfix/master.cf では、25/tcp の SMTP に加えて、submission と smtps を別サービスとして定義します。submission は TLS を必須にし、smtps は wrapper mode で扱います。
sudo tee /etc/postfix/master.cf >/dev/null <<'EOF'
smtp inet n - n - - smtpd
submission inet n - n - - smtpd
-o milter_macro_daemon_name=ORIGINATING
-o smtpd_tls_security_level=encrypt
-o smtpd_tls_auth_only=yes
-o syslog_name=postfix/submission
smtps inet n - n - - smtpd
-o milter_macro_daemon_name=ORIGINATING
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
EOF
sudo chown root:root /etc/postfix/master.cf
sudo chmod 0644 /etc/postfix/master.cfLDAP alias を設定する
LDAP にメール alias を持たせる場合は、/etc/postfix/ldap-aliases.cf を作成します。bind password を含むため、権限は 0600 にします。
sudo tee /etc/postfix/ldap-aliases.cf >/dev/null <<'EOF'
server_host = ldaps://ldap.example.com
search_base = ou=mail-aliases,ou=main,ou=tenants,dc=example,dc=com
bind = yes
bind_dn = cn=bind-ro,ou=system,dc=example,dc=com
bind_pw = change-this-password
version = 3
query_filter = mailAlternateAddress=%s
result_attribute = mailRoutingAddress
EOF
sudo chown root:root /etc/postfix/ldap-aliases.cf
sudo chmod 0600 /etc/postfix/ldap-aliases.cf
postmap -q info@example.com ldap:/etc/postfix/ldap-aliases.cfrecipient_access を使う
受信を許可する宛先 domain を明示したい場合は、recipient_access を作成して postmap で db 化します。
sudo tee /etc/postfix/recipient_access >/dev/null <<'EOF'
example.com OK
internal.example.com OK
EOF
sudo chown root:root /etc/postfix/recipient_access
sudo chmod 0644 /etc/postfix/recipient_access
sudo postmap /etc/postfix/recipient_access
ls -l /etc/postfix/recipient_access /etc/postfix/recipient_access.db設定を検証して反映する
Postfix の設定変更後は、reload の前に postfix check と postconf -n で確認します。構文エラーや権限エラーがある状態で反映しないようにします。
sudo postfix check
postconf -n
sudo systemctl reload postfix.service
systemctl status postfix.service --no-pager待ち受けポートを確認する
SMTP、submission、smtps を有効化している場合は、想定したポートだけが待ち受けているか確認します。外部公開範囲は firewall 側でも制限します。
ss -ltnp | grep master
sudo ufw status verbose送受信を確認する
内部配送や relay の確認では、まずローカルから test mail を送り、queue と log を見ます。
echo test | mail -s postfix-test user@example.com
mailq
journalctl -u postfix.service -n 100 --no-pager
tail -n 100 /var/log/mail.logTLS 証明書を確認する
submission や smtps で TLS を使う場合は、証明書ファイル、秘密鍵の権限、内部 CA の信頼を合わせて確認します。
sudo ls -l /etc/ssl/certs/mail.example.com.crt
sudo ls -l /etc/ssl/private/mail.example.com.key
openssl x509 -in /etc/ssl/certs/mail.example.com.crt -noout -subject -issuer -datesDKIM / DMARC とは分ける
Postfix 本体は配送と SMTP service の土台です。DKIM 署名や DMARC 検証は OpenDKIM / OpenDMARC と連携する別の層として考えます。Postfix の基本が安定してから追加します。
メール配送は DNS、TLS、認証、迷惑メール対策、配送先制限が絡みます。最初から公開 MTA として広く受けるのではなく、内部 SMTP、submission、DKIM / DMARC、IMAP を分けて段階的に確認します。
確認ポイント
postfixとmailutilsを導入している- LDAP alias を使う場合だけ
postfix-ldapを導入している /etc/postfix/main.cfと/etc/postfix/master.cfを管理している/etc/postfix/ldap-aliases.cfの権限を0600にしているrecipient_access変更後にpostmapを実行しているpostfix check後にpostfix.serviceを reload している
まとめ
Ubuntu 26.04 の Postfix 基本設定では、main.cf と master.cf を中心に、配送範囲、TLS、submission / smtps、LDAP alias、recipient access を分けて構成します。
設定変更後は postfix check、postconf -n、postmap、systemctl status postfix.service、mail log を順番に確認します。DKIM / DMARC や Dovecot 連携は、Postfix の基本動作を確認してから追加すると切り分けやすくなります。

