OracleLinux9.3 メールサーバーPostfixのインストール方法

環境
OracleLinux9.3

1. postfixのインストール
Postfix をインストールして SMTP サーバーを構築します
# dnf -y install postfix

Postfix がインストールされているか確認
# rpm -qa | grep postfix

2. Postfix をサービスへ登録

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl enable postfix.service
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
# systemctl is-enabled postfix.service
enabled
# systemctl enable postfix.service Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service. # systemctl is-enabled postfix.service enabled
# systemctl enable postfix.service
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
# systemctl is-enabled postfix.service
enabled

3. postfix の設定ファイルを変更します
# cp -p /etc/postfix/main.cf `date '+/etc/postfix/main.cf.%Y%m%d’`
# cp -p /etc/postfix/master.cf `date '+/etc/postfix/master.cf.%Y%m%d’`

4. postfix の設定ファイル編集
メール不正中継防止のため、Dovecot の SASL 機能を利用して、送信にも認証を要求するように Postfix を設定します

# vi /etc/postfix/main.cf

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#96 行目あたりに追加
#myhostname = virtual.domain.tld
myhostname = mail.<ドメイン>
#103 行目あたりに自ドメイン名を追加
#mydomain = domain.tld
mydomain = <ドメイン>
#118 行目あたりコメントアウト削除
myorigin = $mydomain
#135 行目あたり変更
inet_interfaces = all
#183 行目あたりをコメントアウトし、184 行目に追加します。
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#287 行目あたりに追加
#mynetworks = 168.100.189.0/28, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
mynetworks = 192.168.11.0/24, 127.0.0.0/8 ←192.168.11.0/24は各自環境に合わす
#440 行目あたりコメント削除
メールの格納形式の設定をします。
#home_mailbox = Mailbox
home_mailbox = Maildir/ 
#447 行目あたりコメント削除
mail_spool_directory = /var/spool/mail 
#593 行目あたりに追加
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown
以下の内容を最終行に追加
# 送受信メールサイズを 10M に制限
message_size_limit = 10485760
# メールボックスサイズを 1G に制限
mailbox_size_limit = 1073741824
# 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 = $mydomain
smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject
#96 行目あたりに追加 #myhostname = virtual.domain.tld myhostname = mail.<ドメイン> #103 行目あたりに自ドメイン名を追加 #mydomain = domain.tld mydomain = <ドメイン> #118 行目あたりコメントアウト削除 myorigin = $mydomain #135 行目あたり変更 inet_interfaces = all #183 行目あたりをコメントアウトし、184 行目に追加します。 #mydestination = $myhostname, localhost.$mydomain, localhost mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain #287 行目あたりに追加 #mynetworks = 168.100.189.0/28, 127.0.0.0/8 #mynetworks = $config_directory/mynetworks #mynetworks = hash:/etc/postfix/network_table mynetworks = 192.168.11.0/24, 127.0.0.0/8 ←192.168.11.0/24は各自環境に合わす #440 行目あたりコメント削除 メールの格納形式の設定をします。 #home_mailbox = Mailbox home_mailbox = Maildir/  #447 行目あたりコメント削除 mail_spool_directory = /var/spool/mail  #593 行目あたりに追加 #smtpd_banner = $myhostname ESMTP $mail_name #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) smtpd_banner = $myhostname ESMTP unknown 以下の内容を最終行に追加 # 送受信メールサイズを 10M に制限 message_size_limit = 10485760 # メールボックスサイズを 1G に制限 mailbox_size_limit = 1073741824 # 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 = $mydomain smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject
#96 行目あたりに追加
#myhostname = virtual.domain.tld
myhostname = mail.<ドメイン>

#103 行目あたりに自ドメイン名を追加
#mydomain = domain.tld
mydomain = <ドメイン>

#118 行目あたりコメントアウト削除
myorigin = $mydomain

#135 行目あたり変更
inet_interfaces = all

#183 行目あたりをコメントアウトし、184 行目に追加します。
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

#287 行目あたりに追加
#mynetworks = 168.100.189.0/28, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
mynetworks = 192.168.11.0/24, 127.0.0.0/8 ←192.168.11.0/24は各自環境に合わす

#440 行目あたりコメント削除
メールの格納形式の設定をします。
#home_mailbox = Mailbox
home_mailbox = Maildir/ 

#447 行目あたりコメント削除
mail_spool_directory = /var/spool/mail 

#593 行目あたりに追加
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown

以下の内容を最終行に追加
# 送受信メールサイズを 10M に制限
message_size_limit = 10485760
# メールボックスサイズを 1G に制限
mailbox_size_limit = 1073741824
# 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 = $mydomain
smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject

 

5.SMTP ポート(25 番ポート) の解放

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# firewall-cmd --add-service=smtp --permanent
success
# firewall-cmd --reload
success
# firewall-cmd --add-service=smtp --permanent success # firewall-cmd --reload success
# firewall-cmd --add-service=smtp --permanent
success
# firewall-cmd --reload
success

 

6. Postfix を起動する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl enable --now postfix
# systemctl enable --now postfix
# systemctl enable --now postfix

 

OracleLinux9.3

Posted by arkgame