Contents
1.Postfix、Dovecotのインストール
1-1.必要なソフトウェアのインストール
[root@Lepard ~]# dnf -y install postfix dovecot cyrus-sasl cyrus-sasl-plain cyrus-sasl-devel [root@Lepard ~]# systemctl enable postfix [root@Lepard ~]# systemctl enable dovecot [root@Lepard ~]# systemctl enable saslauthd Postfix がインストールされているか確認 [root@Lepard ~]# rpm -qa | grep postfix postfix-2.10.1-7.el7.x86_64 sasl 関連パッケージの確認 [root@Lepard ~]# rpm -qa | grep sasl cyrus-sasl-plain-2.1.26-23.el7.x86_64 cyrus-sasl-lib-2.1.26-23.el7.x86_64 cyrus-sasl-devel-2.1.26-23.el7.x86_64 cyrus-sasl-md5-2.1.26-23.el7.x86_64 これがない場合 # dnf install cyrus-sasl-md5 cyrus-sasl-2.1.26-23.el7.x86_64 Postfix をサービスへ登録 [root@Lepard ~]# systemctl enable postfix.service Created symlink from /etc/systemd/system/multi-user.target.wants/postfix.service to /usr/lib/systemd/system/postfix.service. |
1-2.ユーザー登録の前準備
①新規ユーザーの為の前準備
新規でユーザーを追加した場合、自動的にメールの送受信ができるよう設定をする
[root@Lepard ~]# mkdir -p /etc/skel/Maildir/{new,cur,tmp} [root@Lepard ~]# chmod -R 700 /etc/skel/Maildir/ [root@Lepard ~]# echo “~/Maildir/”> /etc/skel/.forward [root@Lepard ~]# chmod 600 /etc/skel/.forward |
➁既存ユーザーのメール環境の前準備
すでに作成してあるユーザー(例ではユーザー[tama])がメールの送受信が出来るよう設定をする
[root@Lepard ~]# mkdir -p /home/tama/Maildir/{new,cur,tmp} [root@Lepard ~]# chown -R tama:tama /home/tama/Maildir/ [root@Lepard ~]# chmod 700 /home/tama/Maildir [root@Lepard ~]# chmod 700 /home/tama/Maildir/{new,cur,tmp} |
1-3.Postfix設定ファイルの編集
①SMTP 認証設定ファイルの編集
SMTP 認証設定ファイルのバックアップ [root@Lepard ~]# cp -p /etc/sasl2/smtpd.conf `date ‘+ /etc/sasl2/smtpd.conf.%Y%m%d’` ■ 1 行目、2 行目の行頭に「#」を挿入し、赤太字の内容を追記 # pwcheck_method: saslauthd # mech_list: plain login pwcheck_method: auxprop auxprop_plugin: sasldb mech_list: cram-md5 digest-md5 plain login |
➁saslauthd のサービス登録
[root@Lepard ~]# systemctl enable saslauthd.service Created symlink from /etc/systemd/system/multi -user.target.wants/saslauthd.service to /usr/lib/systemd/sy stem/saslauthd.service. [root@Lepard ~]# systemctl is-enabled saslauthd.service enabled saslauthd の起動 [root@Lepard ~]# systemctl start saslauthd.service |
➂Postfix のサンプルユーザの作成
今回は例としてユーザー[rocky]
[root@Lepard ~]# useradd -s /sbin/nologin rocky [root@Lepard ~]# passwd rockySMTP-AUTH パスワードの設定 [root@Lepard ~]# echo “<任意のパスワード>” | saslpasswd2 -p -u <ドメイン名> -c rocky 登録したユーザーを確認し、/etc/sasldb2 のグループ権限をpostfix が読めるように、 postfix グループに変更 [root@Lepard ~]# sasldblistusers2 jimmy@<ドメイン名>: userPassword [root@Lepard ~]# chgrp postfix /etc/sasldb2 |
④Postfix 設定ファイルの編集
[root@Lepard ~]# vi /etc/postfix/main.cf |
編集内容
■96 行目あたりに追加 #myhostname = virtual.domain.tld myhostname = mail.<自ドメイン名> ■103 行目あたりに自ドメイン名を追加 #mydomain = domain.tld mydomain = <自ドメイン名> ■119 行目あたりに追加 #myorigin = $mydomain myorigin = $mydomain ■135 行目あたりに追加「inet_interfaces = localhost」の行頭に「#」を挿入し、その下に「inet_interfaces = all」を追加 #inet_interfaces = localhost inet_interfaces = all ■183 行目あたりに追加コメントアウトし、その下に追加 #mydestination = $myhostname, localhost.$mydomain, localhost mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ■241 行目あたりを確認 エラーメッセージ(550)を返すことを確認 unknown_local_recipient_reject_code = 550 ■287 行目あたりに追加 #mynetworks = hash:/etc/postfix/network_table mynetworks = 192.168.11.0/24, 127.0.0.0/8 [192.168.11.0/24は自環境に合わす・・・・] ■406 行目あたりを確認 alias_maps = hash:/etc/aliases ■440 行目あたりに追加 メールの格納形式の設定 #home_mailbox = Mailbox #home_mailbox = Maildir/ home_mailbox = Maildir/ ■447 行目あたりに追加 #mail_spool_directory = /var/mail #mail_spool_directory = /var/spool/mail mail_spool_directory = /var/spool/mail ■594 行目あたりに追加 #smtpd_banner = $myhostname ESMTP $mail_name #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) smtpd_banner = $myhostname ESMTP unknown ■以下の内容を最終行に追加 allow_percent_hack = no # smtp auth を利用 smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $mydomain smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,reject_unauth_destination broken_sasl_auth_clients = yes allow_min_user=yes message_size_limit = 10485760 disable_vrfy_command = yes virtual_maps = hash:/etc/postfix/virtual virtual_alias_maps = hash:/etc/postfix/virtual |
⑤submission ポート(587 番ポート) の設定
[root@Lepard ~]# vi /etc/postfix/master.cf 16 行目、19 行目の行頭にある「#」を削除 変更後は下記の通り |
⑥Postfix を起動
[root@Lepard ~]# postmap hash:/etc/postfix/virtual [root@Lepard ~]# systemctl start postfix.service |
1-4.Dovecot設定ファイルの編集
①dovecot.conf ファイルを編集
dovecot.conf ファイルをバックアップ [root@Lepard ~]# cp -p /etc/dovecot/dovecot.conf `date ‘+ /etc/dovecot/dovecot.conf.%Y%m%d’` [root@Lepard ~]# vi /etc/dovecot/dovecot.conf |
dovecot.confファイルの編集内容 ■25 行目あたりに追加 「# protocols = imap pop3 lmtp protocols = imap pop3 ■最終行に追加 !include_try local.conf disable_plaintext_auth = no mail_location = maildir:~/Maildir |
➁10-ssl.conf ファイルを編集
[root@Lepard ~]# vi /etc/dovecot/conf.d/10-ssl.conf ■ 8行目あたり 「ssl = required」の行頭に「#」を挿入し、その下行に「ssl = yes」を追加 |
➂dovecot をサービスに登録し、起動する
[root@Lepard ~]# systemctl enable dovecot.service [root@Lepard ~]# systemctl start dovecot.service |
2.Postfix + Clamav + Amavisd
①Amavisd および Clamav Server をインストール
[root@Lepard ~]# dnf –enablerepo=epel,powertools -y install amavisd-new clamd perl-Digest-SHA1 perl-IO-stringy |
➁設定ファイル編集
[root@Lepard ~]# vi /etc/clamd.d/scan.conf ■8行目:コメントにする #Example ■14行目:コメント解除 LogFile /var/log/clamd.scan ■77行目:コメント解除 PidFile /run/clamd.scan/clamd.pid ■81行目:コメント解除 TemporaryDirectory /var/tmp ■96行目:コメント解除 LocalSocket /run/clamd.scan/clamd.sock |
[root@Lepard ~]# touch /var/log/clamd.scan [root@Lepard ~]# chown clamscan. /var/log/clamd.scan [root@Lepard ~]# systemctl enable –now clamd@scan |
➂Amavisd を設定して起動
[root@Lepard ~]# vi /etc/amavisd/amavisd.conf |
amavisd.conf編集内容
■13 行目あたり行頭の「#」を削除 @bypass_spam_checks_maps = (1); # controls running of anti-spam code ■23行目:自ドメイン名に変更 $mydomain = ‘<自ドメイン>’; ■28 行目あたり 行頭に「#」を追加して無効化 #$QUARANTINEDIR = undef; # -Q ■125 行目あたり行頭に「#」を追加して無効化 # $virus_admin = undef; # notifications recip ■158行目:コメント解除して自ホスト名に変更 $myhostname = ‘mail.<自ドメイン>’; ■163 行目あたり行頭の「#」を削除 $notify_method = ‘smtp:[127.0.0.1]:10025’; $forward_method = ‘smtp:[127.0.0.1]:10025’; # set to undef with milter! |
[root@Lepard ~]# systemctl enable –now amavisd |
④Postfix の設定
[root@Lepard ~]# vi /etc/postfix/main.cf # 最終行に追記 content_filter=smtp-amavis:[127.0.0.1]:10024 |
[root@Lepard ~]# vi /etc/postfix/master.cf # 最終行に下表追記 |
smtp-amavis unix – – n – 2 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes 127.0.0.1:10025 inet n – n – – smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 |
[root@Lepard ~]# systemctl restart postfix |
3.スパム対策設定
①スパム対策としてSpamAssassin を導入
[root@Lepard ~]# dnf -y install –enablerepo=epel spamassassin spamass-milter-postfix [root@Lepard ~]# systemctl start spamassassin [root@Lepard ~]# systemctl enable spamassassin |
➁SpamAssassin の設定
[root@Lepard ~]# vi /etc/mail/spamassassin/v310.pre ■24 行目あたり行頭の#を削除してTextCat プラグインを有効化 |
➂SpamAssassin 設定ファイルを最新化するスクリプトを導入
[root@Lepard ~]# vi /opt/spamassassin-update.sh |
#!/bin/bash cd /etc/mail/spamassassin mv spamassassin_user_prefs-main/user_prefs . # スパム判断したメールを添付形式にしない # スパム判断したメールの件名に「***SPAM***」を付加する # SpamAssassin再起動 |
④spamassassin-update スクリプトに実行権限を付与し、実行
[root@Lepard ~]# chmod 700 /opt/spamassassin-update.sh [root@Lepard ~]# /opt/spamassassin-update.sh |
/etc/mail/spamassassin ディレクトリにSpamAssassin 設定ファイルが当日日付で
作成されていることを確認
[root@Lepard ~]# ls -l /etc/mail/spamassassin drwxr-xr-x 2 root root 59 6 月 7 20:02 channel.d -rw-r–r– 1 root root 1289 10 月16 2018 init.pre -rw-r–r– 1 root root 486543 9 月 11 20:24 local.cf ←実行日当日日付になっている事を確認します。 drwx—— 2 root root 6 10 月16 2018 sa-update-keys -rw-r–r– 1 root root 62 10 月16 2018 spamassassin-default.rc |
⑤Postfix にSpamAssassin を組み込む設定
[root@Lepard ~]# vi /etc/postfix/master.cf ■11 行目あたり行頭に「#」を追加し12 行目にSpamAssassin 設定を追加 spamassassin unix – n n – – pipe |
⑥/etc/postfix/main.cf ファイルの編集
[root@Lepard ~]# vi /etc/postfix/main.cf ■最終行へ下記内容を追加 postfix を再起動 |