| 「はじ
めに」(2009/01/03修正) 私のISPの回線
は
Outbound Port25
Blocking がかっていました。
それを知らずに自宅SMTPサーバを postfixで構築したものの何度テストしても動作しないため、 かなり悩みました。 Outbound port 25 Blocking(以下、OP25B)とは、外向きのTCP 25番ポートをブロックする事です。 プロバイダー加入者パソコンがウイルスに感染、乗っ取られたりして迷惑メールを配信するために利用されるのを防止するた めのものです。 OP25Bが導入された場合であっても、加入プロバイダーのSMTPサーバを加入プロバイダーのドメインを利用してメール送信しているユーザには全く影響 がありません。しかし自宅サーバで独自ドメインを使用してSMTPサーバを 動かしている場合は対策が必要になります。 OP25Bに対する自宅SMTPサーバでの完全対策としては2つの対策が必要です。
自分が契約しているプロバイダーがOP25Bが導入した場合です。1.自宅SMTPサーバから外部へ送信する場合の対策 2.外部から自宅SMTPサーバに接続する場合の対策 自宅SMTPサーバを自宅以外の外部から使用する場合で、かつクライアントが接続されているISP側がOP25Bを導入 した場合です。 どちらもOP25Bにより25番ポートが使用できないという点では同じです。 |
| インストール時にレポジトリの設定はFC6 の場合はextora base updateのみですべて揃うようになりました。 |
| # yum install postfix dovecot ←これを実行するときのレポジトリはcoreとupdate,extoraのみ # yum install clamav-* clamav-update amavisd-new ←レポジトリ はcore,update,extoraのみ |
| 設定に入る前に「mxレコ−ドが登録されていて正引き
ができること。」をクリアしてから次へ進んでください。逆引きはプロバイダー名でも動作するようです。 |
| $ host -t mx hoge.sytes.net hoge.sytes.net mail is handled by 5 hoge.sytes.net. ← mxレコ−ドが登録されている $ dig hoge.sytes.net ; <<>> DiG 9.2.3 <<>> hoge.sytes.net ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13679 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;hoge.sytes.net. IN A ;; ANSWER SECTION: hoge.sytes.net. 38 IN A 219.106.6.254 ← 正引ができる状態である ;; Query time: 120 msec ;; SERVER: 192.168.11.1#53(192.168.11.1) ;; WHEN: Fri Jun 17 00:06:35 2005 ;; MSG SIZE rcvd: 49 $ dig -x 219.106.6.254 ; <<>> DiG 9.2.3 <<>> -x 219.106.6.254 ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60584 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;254.6.106.219.in-addr.arpa. IN PTR ;; ANSWER SECTION: 254.6.106.219.in-addr.arpa. 25 IN PTR hoge.sytes.net. ← 逆引ができる状態である ;; Query time: 108 msec ;; SERVER: 192.168.11.1#53(192.168.11.1) ;; WHEN: Fri Jun 17 00:17:07 2005 ;; MSG SIZE rcvd: 73 |
| これから設定するのは postfix + Auth + clamd + spamassassin +
amavisd-new の環境です。設定ファイルと概要を下に書いてみます。 これからrelayhost + sasl auth で ISPのMTAを経由した送信を行う設定を行います。 設定の際には最悪の場合に元に戻せるように各段階ごとに設定ファイルを別名でコピーした後に行ってくださ い。 |
| #alternatives
--config mta ←メ−ルサ−バ−の切り替え There are 3 programs which provide 'mta'. Selection Command ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail 2 /usr/sbin/sendmail.postfix 3 /usr/sbin/sendmail.exim Enter to keep the current selection[+], or type selection number:2 ← postfixを選択する #alternatives --config mta ←メ−ルサ −バ−の確認 There are 3 programs which provide 'mta'. Selection Command ----------------------------------------------- * 1 /usr/sbin/sendmail.sendmail + 2 /usr/sbin/sendmail.postfix ←postfix が選択されている。 3 /usr/sbin/sendmail.exim Enter to keep the current selection[+], or type selection number: |
| ここからはmain.cfの設定です。以下を参考に設定してください。 |
| $ grep -v "#"
/etc/postfix/main.cf
| sed '/^$/ d' ←
/etc/postfix/main.cfの設定内容を確認 queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix mail_owner = postfix myhostname = hoge.sytes.net mydomain = hoge.sytes.net myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain unknown_local_recipient_reject_code = 550 mynetworks_style = subnet mynetworks = 192.168.1.0/24, 127.0.0.0/8 relay_domains = $mydestination relayhost = [smtp.provider.ne.jp] ←契約ISPの送信メー ルサーバー alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases home_mailbox = Maildir/ debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin xxgdb $daemon_directory/$process_name $process_id & sleep 5 sendmail_path = /usr/sbin/sendmail.postfix newaliases_path = /usr/bin/newaliases.postfix mailq_path = /usr/bin/mailq.postfix setgid_group = postdrop html_directory = no manpage_directory = /usr/share/man sample_directory = /usr/share/doc/postfix-2.2.8/samples readme_directory = /usr/share/doc/postfix-2.2.8/README_FILES ここから追加分 #クライアント自宅サーバー間 #SMTP Authを有効にする。 smtpd_sasl_auth_enable = yes #TLSの設定 smtpd_use_tls = yes smtpd_tls_cert_file = /etc/postfix/certs/server.pem smtpd_tls_key_file = /etc/postfix/certs/server.key smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache smtpd_tls_loglevel = 1 #リレ-制限の設定 smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination #------------------------------------------------------------------------ #自宅サーバーISP間 #SMTP Authを有効にする。 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/saslpass smtp_sasl_type = cyrus #ISP のSMTPサーバ側のSASLメカニズムと自宅サーバ側のSASLメカニズムを合わせる #smtp_sasl_mechanism_filter = cram-md5, plain, login #------------------------------------------------------------------------ #その他 #OutLookなどのためにLOGIN認証を使用する broken_sasl_auth_clients = yes #postfix amavis連携 content_filter = smtp-amavis:[127.0.0.1]:10024 #特定ドメイン・IPアドレス受信拒否 smtpd_client_restrictions = permit_mynetworks check_client_access hash:/etc/postfix/reject_list, permit #------------------------------------------------------------------------ |
| ここからはmaster.cfの設定です。以下を参考 に設定してください。 |
| $ cat
/etc/postfix/master.cf # # Postfix master process configuration file. For details on the format # of the file, see the Postfix master(5) manual page. # # ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (yes) (never) (100) # ========================================================================== smtp inet n - n - - smtpd submission inet n - n - - smtpd -o smtpd_etrn_restrictions=reject # -o smtpd_client_restrictions=permit_sasl_authenticated,reject smtps inet n - n - - smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes #submission inet n - n - - smtpd # -o smtpd_etrn_restrictions=reject # -o smtpd_enforce_tls=yes -o smtpd_sasl_auth_enable=yes #628 inet n - n - - qmqpd pickup fifo n - n 60 1 pickup cleanup unix n - n - 0 cleanup qmgr fifo n - n 300 1 qmgr #qmgr fifo n - n 300 1 oqmgr tlsmgr unix - - n 1000? 1 tlsmgr rewrite unix - - n - - trivial-rewrite bounce unix - - n - 0 bounce defer unix - - n - 0 bounce trace unix - - n - 0 bounce verify unix - - n - 1 verify flush unix n - n 1000? 0 flush proxymap unix - - n - - proxymap smtp unix - - n - - smtp # When relaying mail as backup MX, disable fallback_relay to avoid MX loops relay unix - - n - - smtp -o fallback_relay= # -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 showq unix n - n - - showq error unix - - n - - error discard unix - - n - - discard local unix - n n - - local virtual unix - n n - - virtual lmtp unix - - n - - lmtp anvil unix - - n - 1 anvil scache unix - - n - 1 scache # # ==================================================================== # Interfaces to non-Postfix software. Be sure to examine the manual # pages of the non-Postfix software to find out what options it wants. # # Many of the following services use the Postfix pipe(8) delivery # agent. See the pipe(8) man page for information about ${recipient} # and other message envelope options. # ==================================================================== # # maildrop. See the Postfix MAILDROP_README file for details. # Also specify in main.cf: maildrop_destination_recipient_limit=1 # maildrop unix - n n - - pipe flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient} # # The Cyrus deliver program has changed incompatibly, multiple times. # old-cyrus unix - n n - - pipe flags=R user=cyrus argv=/usr/lib/cyrus-imapd/deliver -e -m ${extension} ${user} # Cyrus 2.1.5 (Amos Gouaux) # Also specify in main.cf: cyrus_destination_recipient_limit=1 cyrus unix - n n - - pipe user=cyrus argv=/usr/lib/cyrus-imapd/deliver -e -r ${sender} -m ${extension} ${user} # # See the Postfix UUCP_README file for configuration details. # uucp unix - n n - - pipe flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) # # Other external delivery methods. # ifmail unix - n n - - pipe flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) bsmtp unix - n n - - pipe flags=Fq. user=foo argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient ############################################################################## ここから追加分 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 |
その他設定ファイルを編集します。
|
| ユ−ザ−アカウントを作成します。 |
| #
saslpasswd2 -u hoge.sytes.net hoge ← ユーザ追加 Password: Again (for verification): # sasldblistusers2 ← SMTP-Auth用ユーザ/パスワード確認 hoge@hoge.sytes.net: userPassword # chgrp postfix /etc/sasldb2 ← 所属 グループをpostfixに変更 ※SMTP-Auth用ユーザ/パスワードを削除する場合 # saslpasswd2 -d hoge -u hoge.hoge.sytes.net |
| あとはル−タ−で25番、110番、587番、465番、995番のポ
−トを開けてテストで
す。
ルーターでのポ−トの開け方はメ−カー機種によって違いますので取扱説明書に従ってください。
ポートが開いたかどうか確認する方法としてポ−トスキャンをしてくれるサイトがあります。 https://image.grc.com/に行ってShieldsUP!の
ボタンをクリックして 次に Proceedのボタンをクリック、次にALL Service Portのボタンをクリックすると 開いているポートを表示してくれます。ルーターを設定したのにポ−トが開いていない場合は システム設定ーセキュリティーレベルを確認してください。 たぶんファイヤーウオールが有効になっているはずなので無効にすればいけるはずです。 |
| Copyright©2005-2006 熊の巣 All Right Reserved. 管理人へメール |