環境
- CentOS 7
- KUSANAGI Version 8.0.1-2
Postfix
Postfixの導入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # postfixのインストール(既にインストール済みなら必要ありません) yum install postfix # バージョン確認 postconf mail_version mail_version = 2.10.1 # デフォルトMTAの切り替え alternatives --config mta 1 プログラムがあり 'mta' を提供します。 選択 コマンド ----------------------------------------------- *+ 1 /usr/sbin/sendmail.postfix # postfixが選択されているか確認 |
Postfixの設定をする
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # ディレクトリ移動 cd /etc/postfix # コピー作成 cp main.cf main.cf.org # 編集 vim main.cf myhostname = mail.example.com mydomain = example.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain home_mailbox = Maildir/ smtpd_banner = $myhostname ESMTP unknown # ページ下部に追加 smtpd_sasl_auth_enable = yes broken_sasl_auth_clients = yes smtp_tls_security_level = may smtpd_sasl_security_options = noanonymous smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination # postfixの設定確認 postconf -n alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases broken_sasl_auth_clients = yes command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5 home_mailbox = Maildir/ html_directory = no inet_interfaces = all inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq.postfix manpage_directory = /usr/share/man mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mydomain = example.com myhostname = mail.example.com myorigin = $mydomain newaliases_path = /usr/bin/newaliases.postfix queue_directory = /var/spool/postfix readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES sample_directory = /usr/share/doc/postfix-2.10.1/samples sendmail_path = /usr/sbin/sendmail.postfix setgid_group = postdrop smtp_tls_security_level = may smtpd_banner = $myhostname ESMTP unknown smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous unknown_local_recipient_reject_code = 550 |
master.cfの編集
1 2 3 4 5 6 7 8 9 10 | # 設定ファイルのバックアップ cp -a master.cf master.cf.org # 変更 vim master.cf submission inet n - n - - smtpd -o smtpd_sasl_auth_enable=yes -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination |
SMTP-Auth設定
1 2 3 4 5 6 7 | yum install cyrus-sasl # 起動 systemctl start saslauthd # 自動起動設定 systemctl enable saslauthd |
Dovecotの導入
1 2 3 4 5 6 | # dovecotのインストール(既にインストール済みなら必要ありません) yum install dovecot # バージョン確認 dovecot --version 2.2.10 |
10-mail.confの設定
1 2 3 4 5 6 7 8 9 10 11 | # ディレクトリ移動 cd /etc/dovecot/conf.d # 設定ファイルのバックアップ cp -a 10-mail.conf 10-mail.conf.org # 設定変更 vim 10-mail.conf - #mail_location = + mail_location = maildir:~/Maildir |
10-auth.confの設定
1 2 3 4 5 6 7 8 | # 設定ファイルのバックアップ cp -a 10-auth.conf 10-auth.conf.org # 設定変更 vim 10-auth.conf - #disable_plaintext_auth = yes + disable_plaintext_auth = no |
10-ssl.confの設定
1 2 3 4 5 6 7 8 | # 設定ファイルのバックアップ cp -a 10-ssl.conf 10-ssl.conf.org # 設定変更 vim 10-ssl.conf - ssl = required + ssl = no |
Dovocotの起動+自動起動設定
1 2 3 4 5 | # Dovecotの起動 systemctl start dovecot # Dovecotの自動起動設定 systemctl enable dovecot |
メールアカウント用システムユーザーの作成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # 自動でMaildir形式のメールボックスが作成されるように mkdir -p /etc/skel/Maildir/{new,cur,tmp} # パーミッション変更 chmod -R 700 /etc/skel/Maildir/ # ユーザー作成(メールアカウント用なのでSSH接続はさせない) useradd -s /sbin/nologin info # パスワード設定 passwd info ユーザー info のパスワードを変更。 新しいパスワード: #パスワードを入力してエンター 新しいパスワードを再入力してください: #パスワードを入力してエンター passwd: すべての認証トークンが正しく更新できました。 |
ポートの開放
1 2 3 4 5 6 7 8 9 10 11 | # 現在利用可能なサービス(ポート)を確認します。 firewall-cmd --list-services # 現在利用可能なポートを確認します。 firewall-cmd --list-ports firewall-cmd --zone=public --add-service=smtp --permanent firewall-cmd --zone=public --add-port=25/tcp --permanent firewall-cmd --zone=public --add-port=587/tcp --permanent firewall-cmd --zone=public --add-port=110/tcp --permanent firewall-cmd --zone=public --add-port=143/tcp --permanent |
レコードの設定
私の場合はAWSのRoute53で設定しました。
1 2 3 4 5 6 7 8 | # `mail.example.com`にAレコードでIPアドレスを登録 mail.example.com. A 000.00.000.000 # サーバーのIPアドレス # `example.com`にMXレコードで`10 mail.example.com.`を設定 example.com. MX 10 mail.example.com. # `example.com`にTXTレコードで`"v=spf1 ip4:000.00.000.000 -all"`を設定 example.com. IN TXT "v=spf1 ip4:000.00.000.000 -all" |
以上でメールの送受信の設定は完了です。
後はメールアカウントの追加などを行ってください。