マックの趣味

FreeBSDでpostfix

1.Postfix のインストール

# cd /usr/ports/mail/postfix
# make install; make clean; rehash;

xqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Options for postfix 2.3.2_1,1 x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x[X] PCRE Perl Compatible Regular Expressions x x
x x[ ] SASL Cyrus SASLv1 (Simple Auth. and Sec. Layer) x x
x x[X] SASL2 Cyrus SASLv2 (Simple Auth. and Sec. Layer) x x
x x[ ] DOVECOT Dovecot SASL authentication method x x
x x[ ] SASLKRB If your SASL req. Kerberos select this option x x
x x[ ] SASLKRB5 If your SASL req. Kerberos5 select this option x x
x x[ ] SASLKMIT If your SASL req. MIT Kerberos5 select this optionx x
x x[X] TLS Enable SSL and TLS support x x
x x[X] BDB Berkeley DB (choose version with WITH_BDB_VER) x x
x x[ ] MYSQL MySQL maps (choose version with WITH_MYSQL_VER) x x
x x[ ] PGSQL PostgreSQL maps (choose with DEFAULT_PGSQL_VER) x x
x x[ ] OPENLDAP OpenLDAP maps (choose ver. with WITH_OPENLDAP_VER) x x
x x[ ] CDB CDB maps lookups x x
x x[ ] NIS NIS maps lookups x x
x x[ ] VDA VDA (Virtual Delivery Agent) x x
tqmqqqqv(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjqu
x [ OK ] Cancel x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

こんな感じで選択しました。Berkeley DBは4.1がインストールされたようです。
インストールされたものは
perl-5.8.8
pcre-6.7
cyrus-sasl-2.1.22
db41-4.1.25_3
postfix-2.3.2_1,1


途中でアカウントを追加するか聞いてくるので y を選択する。
 
2.sendmail を止める

/etc/rc.conf に以下を記載して sendmail 関係を動かないようにする。

sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

/etc/periodic.conf 以下を記載して sendmail 関係を動かないようにする。

daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"

/etc/rc.conf に以下を記載してpostfix が動くようにする。

postfix_enable="YES"

/etc/mail/mailer.conf を以下のように修正して sendmail 関係のコマンドを postfix にする。
書き換えないと sendmail の  newaliaes が動いて postfix から aliases.dbが読めません。
はまりました。
完全に sendmail を止める方法は /usr/ports/mail/postfix/pkg-message に書いてあります


# $FreeBSD: src/etc/mail/mailer.conf,v 1.3 2002/04/05 04:25:12 gshapiro Exp $
#
# Execute the "real" sendmail program, named /usr/libexec/sendmail/sendmail
#
#sendmail /usr/libexec/sendmail/sendmail
#send-mail /usr/libexec/sendmail/sendmail
#mailq /usr/libexec/sendmail/sendmail
#newaliases /usr/libexec/sendmail/sendmail
#hoststat /usr/libexec/sendmail/sendmail
#purgestat /usr/libexec/sendmail/sendmail

#
# Execute the Postfix sendmail program, named /usr/local/sbin/sendmail
#
sendmail /usr/local/sbin/sendmail
send-mail /usr/local/sbin/sendmail
mailq /usr/local/sbin/sendmail
newaliases /usr/local/sbin/sendmail

3.postfixの設定
  以下のように運用するつもり
  (1)dracを使用して pop before smtp をする
  (2)クライアントに submission port を提供する
  (3)プロバイダのsmtpサーバーにsubmission port smtp auth で relay する。
  (4)Clam AntiVirusでウイルスをチェックする
  (5)spamassassinでスパムチェック
  (6)Maildir

4.Maildirの作成
  各ユーザーが受信するメールディレクトリを作成します。
  ユーザーでログインして、

  $ maildirmake Maildir

  と入力します。maildirmakeコマンドは自動的にメール受信用のフォルダを
  作成してくれるコマンドで、 courier-imap をインストールした際に、
  一緒にインストールされます。

  新規にユーザーを作成するときに、自動的にこの Maildir ディレクトリを
  作成できるように設定することができます。、 

maildirmake /usr/share/skel/Maildir
maildirmake /usr/share/skel/Maildir
echo ./Maildir/ > /usr/share/skel/dot.qmail
chmod 600 /usr/share/skel/dot.qmail

 etc/login.confの
 setenv=MAIL=/var/mail/$ ,BLOCKSIZE=K,FTP_PASSIVE_MODE=YES:
となっているのを
:setenv=MAIL=/home/$/Maildir/,BLOCKSIZE=K,FTP_PASSIVE_MODE=YES:
に変更します。

  これで新規ユーザーにも自動的に Maildir ディレクトリが作成されます。


4.main.cf の編集

参考URL
    http://www.asi.co.jp/techinfo/unix/postfix.html

myhostname = svr.sample.com
mydomain = sample.com
myorigin = $mydomain
inet_interfaces = all
mynetworks_style = subnet
mynetworks = 192.168.1.0/24, 127.0.0.0/8
alias_maps = hash:/etc/mail/aliases
alias_database = hash:/etc/mail/aliases
smtpd_recipient_restrictions = permit_mynetworks,   #許可するクライアント
check_client_access btree:/usr/local/etc/dracd,
check_relay_domains

content_filter = smtp-amavis:[127.0.0.1]:10024 # amavis ウイルスチェック

smtpd_sasl_auth_enable = yes       # smtp_auth 用
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes

smtpd_client_restrictions = permit_mynetworks,
# check_client_access hash:/etc/postfix/bad_sender,
# reject_rbl_client relays.ordb.org,
reject_rbl_client spamcop.net,
reject_rbl_client dynablock.wirehub.net,
reject_rbl_client opm.blitzed.org,
# reject_invalid_hostname,
permit

smtpd_recipient_restrictions = permit_mynetworks,
permit_auth_destination,
check_policy_service inet:127.0.0.1:10026,
check_client_access regexp:/usr/local/etc/postfix/header_checks,
# check_client_access regexp:/usr/local/etc/postfix/body_checks,
check_client_access regexp:/usr/local/etc/postfix/check_client_fqdn,
check_client_access hash:/usr/local/etc/postfix/reject_sender,
check_relay_domains,
# reject_rbl_client relays.ordb.org,
reject_rbl_client spamcop.net,
reject_rbl_client dynablock.wirehub.net,
reject_rbl_client opm.blitzed.org,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unknown_senmder_domain,
permit

#smtpd_restriction_classes = check_greylist

check_greylist = check_policy_service inet:127.0.0.1:10026
127.0.0.1:10026_time_limit = 3600

smtpd_snder_restrictions =
permit_mynetworks,
reject_non_fqdn_sender,
reject_unknown_sender_domain,
# reject_unknown_client,
reject_unknown_sender_domain,
reject_spf_invalid_sender,
permit


5.キュー
amavisd.conf が writable になっていたせいでキューにいっぱいメールがたまってしまった。ググッてみると postfix flush とすれば出ていくらしい。
だけど、postfix.sh flush とすると
Usage: ./postfix.sh [fast|force|one](start stop restart rcvar reload status poll)

とflush は受け付けてくれない。これはそのうち直すとして、
/usr/local/sbin/postfix flush として対処した。このとき、一回では全部のキューが出て行かなかったので結構な数コマンドを打ちました。
ちなみに、キューの全削除は
postsuper -d ALL

*修正
意外とちゃんとしたメールなのに、hostname unknown ではねられるメールが意外と多いことに気がついた、仕方ないのでこの拒否設定を止めてみることにしました。
reject_unknown_client を削除です。

ランキングに参加中、クリックをお願いします。

名前:
コメント:

※文字化け等の原因になりますので顔文字の投稿はお控えください。

コメント利用規約に同意の上コメント投稿を行ってください。

 

  • Xでシェアする
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

最新の画像もっと見る

最近の「FreeBSD」カテゴリーもっと見る

最近の記事
バックナンバー
人気記事