「FreeBSD 10.0 - 送信メールサーバ Postfix インストール」についての記録です。
(旧バージョンでの個人の作業記録を更新しました。興味がなければスルーしてください)
0. 前提条件
以下の作業は、リモート接続して行う。(リモートから ssh vbox
で接続)
リモート端末は、 Linux Mint 17 マシンを想定しているが、 Unix 系 OS なら同じ。
設定ファイル等のテキストファイルの編集には vi
コマンドを使用。
作業はリモート接続で一般ユーザから root になって行う。
ドメインは “mk-mode.com” を想定。
主にFreeBSDサーバー構築マニュアル を参照。
1. Procmail インストール
メール振り分けに Procmail を使用するのでインストール。
1
2
3
# cd /usr/ports/mail/procmail
# make BATCH=yes install clean
# cd
2, pkgtools.conf 編集
make
実行時に常時設定するパラメータを設定しておく。
/usr/local/etc/pkgtools.conf 1
2
3
4
5
MAKE_ARGS = {
'security/cyrus-sasl2' = > 'WITHOUT_OTP=yes' , # <= 追加
'security/cyrus-sasl2-saslauthd' = > 'WITH_BDB=yes' , # <= 追加
'mail/postfix' = > 'WITH_SASL2=yes WITH_TLS=yes' , # <= 追加
}
3. Cyrus SASL2 インストール
SASL 認証に Cyrus SASL2 を使用するのでインストール。
1
2
3
# cd /usr/ports/security/cyrus-sasl2
# make BATCH=yes WITHOUT_OTP=yes WITH_BDB=yes install clean
# rehash
4. Cyrus saslauthd インストール
Cyrus SASL2 認証用デーモンをインストール。
1
2
# cd /usr/ports/security/cyrus-sasl2-saslauthd
# make BATCH=yes WITH_BDB=yes install clean
5. Postfix インストール
1
2
3
4
5
# cd /usr/ports/mail/postfix
# make WITH_SASL2=yes WITH_TLS=yes WITH_BDB=yes install clean
Would you like to activate Postfix in /etc/mail/mailer.conf [n]? # <= エンター応答(mailer.conf は後で手動で書き換えるので "n" 応答)
# rehash
# cd
6. main.cf 編集
/usr/local/etc/postfix/main.cf 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
myhostname = mail.mk-mode.com # <= コメント解除&変更(自ホスト名)
mydomain = mk-mode.com # <= コメント解除&変更(自ドメイン名)
myorigin = $mydomain # <= コメント解除(送信元メール)
inet_interfaces = all # <= コメント解除(待ち受けるネットワークアドレス)
mydestination = $myhostname , localhost.$mydomain , localhost, $mydomain # <= コメント解除(ローカル受信ドメイン)
relay_domains = $mydestination # <= コメント解除(リレー許可ドメイン)
alias_maps = hash :/etc/aliases # <= コメント解除(エイリアス設定)
alias_database = hash :/etc/aliases # <= コメント解除(エイリアス設定)
home_mailbox = Maildir/ # <= コメント解除(メールボックスを Maildir 形式に)
mailbox_command = /usr/local/bin/procmail # <= コメント解除&変更(procmail のパス)
# 最終行に以下を追記(SASL による SMTP 認証)
# Cyrus-SASL configuration
smtpd_sasl_auth_enable = yes # <= SASL による SMTP-Auth の許可
smtpd_sasl_local_domain = $mydomain # <= リレーの許可
smtpd_sasl_security_options = noanonymous # <= 匿名ログイン拒否
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination # <= リレー許可設定
broken_sasl_auth_clients = yes # <= AUTH コマンド認識不可のメールソフトに対応
7. saslauthd 自動起動設定
/etc/rc.conf 1
2
saslauthd_enable = "YES" # <= 追加
saslauthd_flags = "-a sasldb" # <= 追加
8. saslauthd 起動
1
2
# /usr/local/etc/rc.d/saslauthd start
Starting saslauthd.
9. SMTP AUTH 設定
以下の内容のファイルを作成。
/usr/local/lib/sasl2/smtpd.conf 1
pwcheck_method: auxprop
10. SMTP AUTH ユーザ追加
(user_name
は実際のユーザ名に置き換えること)
1
2
3
4
5
# saslpasswd2 -c -u mk-mode.com user_name
Password: XXXXXXXXXX # <= メールユーザのパスワード
Again (for verification): XXXXXXXXXX # <= パスワード確認入力
[root@freebsd ~]# sasldblistusers2 # <= メールユーザ確認
user_name@mk-mode.com: userPassword
11. /usr/local/etc/sasldb2 所有権変更
1
2
# chown cyrus:mail /usr/local/etc/sasldb2
# chmod 640 /usr/local/etc/sasldb2
12. Sendmail 停止
デフォルトで起動している Sendmail を停止。(依存する他の起動中サービスも停止される)
1
2
3
4
# /etc/rc.d/sendmail stop
Stopping sendmail.
sendmail_submit not running? (check /var/run/sendmail.pid).
Stopping sendmail_msp_queue.
13. Sendmail 自動起動解除
/etc/rc.conf 1
2
3
4
sendmail_enable = "NO" # <= 追加
sendmail_submit_enable = "NO" # <= 追加
sendmail_outbound_enable = "NO" # <= 追加
sendmail_msp_queue_enable = "NO" # <= 追加
その他、以下の作業も必要。
/etc/periodic.conf 1
2
3
4
daily_clean_hoststat_enable = "NO" # <= 新規追加
daily_status_mail_rejects_enable = "NO" # <= 新規追加
daily_status_include_submit_mailq = "NO" # <= 新規追加
daily_submit_queuerun = "NO" # <= 新規追加
1
# mv /etc/mail/mailer.conf /etc/mail/mailer.conf.org
/etc/mail/mailer.conf 1
2
3
4
sendmail /usr/local/sbin/sendmail # <= 新規追加
send-mail /usr/local/sbin/sendmail # <= 新規追加
mailq /usr/local/sbin/sendmail # <= 新規追加
newaliases /usr/local/sbin/sendmail # <= 新規追加
/etc/make.conf 1
2
NO_MAILWRAPPER = YES # <= 新規追加
NO_SENDMAIL = YES # <= 新規追加
14. Postfix 自動起動設定
/etc/rc.conf 1
postfix_enable = "YES" # <= 追加
15. Postfix 起動
1
2
# /usr/local/etc/rc.d/postfix start
postfix/postfix-script: starting the Postfix mail system
以上。