Ubuntu 25.04
Sponsored Link

Mail サーバー : Postfix インストール2025/04/23

 

Postfix をインストールして SMTP サーバーを構築します。SMTP は [25/TCP] を使用します。

[1] メール不正中継防止に、後述の Dovecot の SASL機能を利用し、送信にも認証が必要なように Postfix を設定します。
root@mail:~#
apt -y install postfix sasl2-bin
# 一般的な構成設定の選択を求められるが
# 当例では後ほど手動設定するため [No Configuration] を選択

+------+ Postfix Configuration +-------+
| General type of mail configuration:  |
|                                      |
|       No configuration               |
|       Internet Site                  |
|       Internet with smarthost        |
|       Satellite system               |
|       Local only                     |
|                                      |
|                                      |
|       <Ok>           <Cancel>        |
|                                      |
+--------------------------------------+

root@mail:~#
cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf

root@mail:~#
vi /etc/postfix/main.cf
# 82行目 : コメント解除
mail_owner = postfix

# 97行目 : IPv4 のみリスンする場合は [ipv4] に変更
inet_protocols = all

# 106行目 : コメント解除してホスト名指定
myhostname = mail.srv.world

# 114行目 : コメント解除してドメイン名指定
mydomain = srv.world

# 133行目 : コメント化
# 135行目 : コメント解除
#myorigin = /etc/mailname
#myorigin = $myhostname
myorigin = $mydomain

# 149行目 : コメント解除
inet_interfaces = all

# 197行目 : コメント解除
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

# 285行目 : コメント解除
mynetworks_style = subnet

# 299行目 : コメント解除して自ネットワーク追記
mynetworks = 127.0.0.0/8, 10.0.0.0/24

# 423行目 : コメント解除
alias_maps = hash:/etc/aliases

# 434行目 : コメント解除
alias_database = hash:/etc/aliases

# 456行目 : コメント解除
home_mailbox = Maildir/

# 592行目 : コメントにしてその下に追記
# SMTP ソフトウェアの種類やバージョンは非表示にする
#smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_banner = $myhostname ESMTP

# 665行目 : コメント解除
sendmail_path = /usr/sbin/sendmail

# 670行目 : コメント解除
newaliases_path = /usr/bin/newaliases

# 675行目 : コメント解除
mailq_path = /usr/bin/mailq

# 681行目 : コメント解除
setgid_group = postdrop

# 以下 最終行へ追記
# SMTP VRFY コマンドは無効にする
disable_vrfy_command = yes

# クライアントに対して HELO コマンドを要求する
smtpd_helo_required = yes

# 1 メールのサイズを制限する
# 下例は 10M バイト
message_size_limit = 10240000

# SMTP-Auth の設定
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = 
  permit_mynetworks,
  permit_sasl_authenticated,
  reject_unauth_destination

root@mail:~#
touch /etc/aliases

root@mail:~#
root@mail:~#
systemctl restart postfix

関連コンテンツ