ubuntu 6.10 でMailサーバ

   

ubuntu 6.10 でPostfixによるMailサーバを構築

Mailサーバの構築

各プログラムのインストール

Postfixのインストール
teckumo@teckumo_server:~$ sudo apt-get install postfix
Ubuntu の設定

 ┌────────────┤ Postfix Configuration  ├────────────┐
 │                                                                            │
 │  ここで、一般的な設定のいくつかの選択肢があります。debconf の優先度を '低  │
 │  ' または '標準' に設定している場合には、より多くの質問をあとで尋ねられま  │
 │  す。これらの質問を再び見たければ、"dpkg-reconfigure --priority=low        │
 │  postfix" をあとでいつでも実行できます。                                   │
 │                                                                            │
 │  設定しない - *あなたの設定をそのままにしておきたいのであれば、このオプシ  │
 │  ョンを選択してください。* 設定変更を何も行いません。Postfix を設定済みで  │
 │  ない場合には、メールシステムは不完全で、利用できないでしょう。            │
 │  /usr/share/postfix/main.cf.dist を編集し、etc/postfix/main.cf として変更  │
 │  を保存する、という設定をあなた自身で行うか、あるいは dpkg-reconfigure     │
 │  Postfix を実行する必要があります。main.cf は Postfix のインストール手順   │
 │  では変更されません。                                                      │
 │                                                                            │
 │  インターネットサイト - メールは SMTP を使って直接送受信されます。いずれ   │
 │  のカテゴリもあなたのニーズにぴったりとは当てはまらない場合には、おそらく  │
 │  これを選んで開始し、それから手で設定ファイルを編集するのがよいでしょう。  │
 │                                                                            │
 │  スマートホスト付きインターネットサイト - SMTP で直接、または fetchmail    │
 │  のようなユーティリティを実行して、このマシンでインターネットメールを受信  │
 │  します。外に送られるメールは、スマートホストを使って、任意のアドレスに書  │
 │  き換えられて送信されます。これはおそらくダイアルアップシステムで望まれる  │
 │  ものです。                                                                │
 │                                                                            │
 │  サテライトシステム - すべてのメールは配信用の「スマートホスト」と呼ばれ   │
 │  る別のマシンに送られます。ローカルではメールを受信しません。              │
 │                                                                            │
 │  ローカル配信のみ - あなたはネットワークに接続していません。ローカルユー   │
 │  ザ向けのメールが配信されます。                                            │
 │                                                                            │
 │                                   <了解>                                   │
 │                                                                            │
 └──────────────────────────────────────┘

Ubuntu の設定

                   ┌───┤ Postfix Configuration  ├───┐
                   │  設定の一般的なタイプはどれですか?     │
                   │                                        │
                   │    設定しない                          │
                   │    インターネットサイト                │
                   │    スマートホスト付きインターネット    │
                   │    サテライトシステム                  │
                   │    ローカルのみ                        │
                   │                                        │
                   │                                        │
                   │         <了解>          <取消>         │
                   │                                        │
                   └────────────────────┘

Ubuntu の設定

 ┌────────────┤ Postfix Configuration  ├────────────┐
 │  `メール名' は、送出されるニュースおよびメールのメッセージ (ユーザ名と @   │
 │  記号のあとに付く) で表示されるアドレスのホスト名部分です。                │
 │                                                                            │
 │  この名前は Postfix だけでなくほかのプログラムによっても使われます。これ   │
 │  は、メールがそこから送出されることになる単一の完全修飾ドメイン名 (FQDN)   │
 │  にすべきです。                                                            │
 │                                                                            │
 │  メール名は?                                                               │
 │                                                                            │
 │ mail.teckumo.net.________________________________________________________ │
 │                                                                            │
 │                     <了解>                      <取消>                     │
 │                                                                            │
 └──────────────────────────────────────┘

teckumo@teckumo_server:~$ sudo apt-get install postfix
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
Reading state information... 完了
提案パッケージ:
  procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin
  resolvconf
以下のパッケージが新たにインストールされます:
  postfix
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
1067kB のアーカイブを取得する必要があります。
展開後に追加で 2494kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com edgy/main postfix 2.3.3-1 [1067kB]
1067kB を 0s で取得しました (2144kB/s)
パッケージを事前設定しています ...
未選択パッケージ postfix を選択しています。
(データベースを読み込んでいます ... 現在 89832 個のファイルとディレクトリがインストールされています。)
(.../postfix_2.3.3-1_i386.deb から) postfix を展開しています...
postfix (2.3.3-1) を設定しています ...
Adding group `postfix' (115)...
終了。
Adding system user `postfix' with uid 110...
Adding new user `postfix' (110) with group `postfix'.
Not creating home directory `/var/spool/postfix'.
Creating /etc/postfix/dynamicmaps.cf
Adding tcp map entry to /etc/postfix/dynamicmaps.cf
Adding group `postdrop' (116)...
終了。
setting myhostname: teckumo_server
setting alias maps
setting alias database
changing /etc/mailname
setting myorigin
setting destinations: mail.teckumo.net., teckumo_server, localhost.localdomain, localhost
setting relayhost:
setting mynetworks: 127.0.0.0/8
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all

Postfix is now set up with a default configuration.  If you need to make
changes, edit
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
values, see postconf(1).

After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.

Running newaliases
 * Stopping Postfix Mail Transport Agent postfix                         [ ok ]
 * Starting Postfix Mail Transport Agent postfix                         [ ok ]

qpopperのインストール
teckumo@teckumo_server:~$ sudo apt-get install qpopper
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
Reading state information... 完了
以下のパッケージが新たにインストールされます:
  qpopper
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
407kB のアーカイブを取得する必要があります。
展開後に追加で 659kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com edgy/universe qpopper 4.0.5-4.1 [407kB]
407kB を 0s で取得しました (654kB/s)
未選択パッケージ qpopper を選択しています。
(データベースを読み込んでいます ... 現在 89989 個のファイルとディレクトリがインストールされています。)
(.../qpopper_4.0.5-4.1_i386.deb から) qpopper を展開しています...
qpopper (4.0.5-4.1) を設定しています ...

teckumo@teckumo_server:~$

xinetdのインストール
teckumo@teckumo_server:~$ sudo apt-get install xinetd
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
Reading state information... 完了
以下のパッケージが新たにインストールされます:
  xinetd
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
131kB のアーカイブを取得する必要があります。
展開後に追加で 365kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com edgy/main xinetd 1:2.3.14-1 [131kB]
131kB を 0s で取得しました (559kB/s)
未選択パッケージ xinetd を選択しています。
(データベースを読み込んでいます ... 現在 90007 個のファイルとディレクトリがインストールされています。)
(.../xinetd_1%3a2.3.14-1_i386.deb から) xinetd を展開しています...
xinetd (2.3.14-1) を設定しています ...
Stopping internet superserver: xinetd.
Adding `diversion of /etc/init.d/inetd to /etc/init.d/inetd.real by xinetd'
Starting internet superserver: xinetd.
teckumo@teckumo_server:~$

sasl2のインストール
teckumo@teckumo_server:/etc/xinetd.d$ sudo apt-get install sasl2-bin libsasl2-modules
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
Reading state information... 完了
libsasl2-modules はすでに最新バージョンです。
以下のパッケージが新たにインストールされます:
  sasl2-bin
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
115kB のアーカイブを取得する必要があります。
展開後に追加で 315kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com edgy/main sasl2-bin 2.1.19.dfsg1-0.2ubuntu3 [115kB]
115kB を 0s で取得しました (440kB/s)
未選択パッケージ sasl2-bin を選択しています。
(データベースを読み込んでいます ... 現在 90036 個のファイルとディレクトリがインストールされています。)
(.../sasl2-bin_2.1.19.dfsg1-0.2ubuntu3_i386.deb から) sasl2-bin を展開しています...
sasl2-bin (2.1.19.dfsg1-0.2ubuntu3) を設定しています ...

teckumo@teckumo_server:/etc/xinetd.d$

Mailサーバの設定

xinetdのpop3設定
teckumo@teckumo_server:~$ cd /etc/xinetd.d
teckumo@teckumo_server:/etc/xinetd.d$ sudo vi pop3
service pop3
{
  disable = no
  socket_type =stream
  wait = no
  user = root
  server = /usr/sbin/in.qpopper
  server_args = -s
}
teckumo@teckumo_server:/etc/xinetd.d$ sudo /etc/init.d/xinetd restart
Stopping internet superserver: xinetd.
Starting internet superserver: xinetd.
teckumo@teckumo_server:/etc/xinetd.d$

PostfixをSMTP AUTHのクライアント側にする設定
 main.cfに「smtp_sasl_password_maps = hash:/etc/postfix/saslpass」を指定しているので、saslpassを作っておく。
teckumo@teckumo_server:/etc/xinetd.d$ cd /etc/postfix
teckumo@teckumo_server:/etc/postfix$ sudo touch saslpass
teckumo@teckumo_server:/etc/postfix$ sudo vi saslpass
teckumo.net     teckumo:*****
teckumo@teckumo_server:/etc/postfix$ sudo postmap saslpass
teckumo@teckumo_server:/etc/postfix$

パーミッションの変更
 saslのユーザとパスワードを登録後、Postfixで使用できるようにパーミッションを変更します。
teckumo@teckumo_server:~$ cd /etc/postfix
teckumo@teckumo_server:/etc/postfix$ sudo saslpasswd2 -u teckumo.net teckumo
Password: *****
Again (for verification): *****
teckumo@teckumo_server:/etc/postfix$ cd ..
teckumo@teckumo_server:/etc$ sudo chgrp postfix sasldb2
teckumo@teckumo_server:/etc$ sudo chmod 640 sasldb2
teckumo@teckumo_server:/etc$ ls -l sasldb2
-rw-r----- 1 root postfix 12288 2006-12-11 09:32 sasldb2
teckumo@teckumo_server:/etc$ sudo mv /etc/sasldb2 /var/spool/postfix/etc/sasldb2
teckumo@teckumo_server:/etc$ sudo ln -s /var/spool/postfix/etc/sasldb2 /etc/sasldb2
teckumo@teckumo_server:/etc$

saslauthdの調整
teckumo@teckumo_server:/etc$ sudo vi /etc/default/saslauthd
# This needs to be uncommented before saslauthd will be run automatically
# START=yes
START=yes

# You must specify the authentication mechanisms you wish to use.
# This defaults to "pam" for PAM support, but may also include
# "shadow" or "sasldb", like this:
# MECHANISMS="pam shadow"

MECHANISMS="pam"
teckumo@teckumo_server:/etc$ sudo /etc/init.d/saslauthd start
Starting SASL Authentication Daemon: saslauthd.
teckumo@teckumo_server:/etc$

SSL認証のサーバ鍵インストール(Outlookの不具合対応)
teckumo@teckumo_server:~$ cd /etc/postfix
teckumo@teckumo_server:/etc/postfix$ sudo mkdir ssl
teckumo@teckumo_server:/etc/postfix$ sudo chown teckumo:teckumo ssl
teckumo@teckumo_server:/etc/postfix$
 wwwサーバ(CA)で作成した/etc/postfix/ssl以下をコピー。
teckumo@teckumo_server:/etc/postfix$ sudo chown -R root:root ssl
teckumo@teckumo_server:/etc/postfix$

main.cfの設定
 スパムメール対策もあわせて、Postfixの設定を行います。スパムメール対策は、 浅見秀雄氏のホームページより スパム対策技術「阻止率99%のスパム対策方式の研究報告」を 参考に、というより丸ごとイタダキでの設定です。 ただ、この設定のままだとODNユーザーのメールが拒否されることがあるので、必要に応じてホワイトリストに登録しなくては いけないようです。
teckumo@teckumo_server:/etc/postfix$ sudo cp main.cf main.cf.org
teckumo@teckumo_server:/etc/postfix$ vi main.cf
 コメントを含めると長いので、設定した項目のみリストします。
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
mail_owner = postfix
myhostname = mail.teckumo.net
virtual_maps = hash:/etc/postfix/virtual
mydomain = teckumo.net
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, teckumo-mail.$mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 50.50.50.0/24, 127.0.0.0/8
relay_domains = $mydestination
alias_maps = hash:/etc/aliases
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
debugger_command =
  PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
  xxgdb $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
manpage_directory = /usr/share/man
masquerade_domains = $mydomain
smtpd_client_restrictions =
  permit_mynetworks,
  permit_sasl_authenticated,
  reject_rbl_client relays.ordb.org,
  reject_rbl_client all.rbl.jp,
  reject_rbl_client bl.spamcop.net,
  reject_rbl_client list.dsbl.org,
  reject_rbl_client sbl-xbl.spamhaus.org,
  check_client_access regexp:/etc/postfix/client_restrictions,
  permit

smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_recipient_restrictions =
  permit_mynetworks,
  permit_sasl_authenticated,
  reject_unauth_destination
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = no
smtp_sasl_password_maps = hash:/etc/postfix/saslpass
smtp_sasl_auth_enable = yes
smtpd_helo_required = yes

smtpd_helo_restrictions =
  permit_mynetworks,
  reject_invalid_hostname,
  check_helo_access regexp:/etc/postfix/helo_restrictions

smtpd_sender_restrictions =
  permit_mynetworks,
  reject_non_fqdn_sender,
  reject_unknown_sender_domain

smtpd_tls_cert_file = /etc/postfix/ssl/teckumo.crt
smtpd_tls_key_file = /etc/postfix/ssl/teckumo.key
smtpd_use_tls = yes
allow_mail_to_commands = alias,forward,include

client_restrictionsの設定
 先ほどの浅見秀雄氏のホームページより 「阻止率99%のスパム対策方式の研究報告」を 参照してください。

helo_restrictionsの設定
 同じく、「阻止率99%のスパム対策方式の研究報告」を 参照してください。

master.cfの設定
teckumo@teckumo_server:/etc/postfix$ sudo cp master.cf master.cf.org
teckumo@teckumo_server:/etc/postfix$ sudo vi master.cf
#smtps     inet  n       -       -       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
smtps inet n - n - - smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes


動作確認

SMTP試験
teckumo@teckumo_server:~$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.teckumo.net ESMTP Postfix (Ubuntu)
EHLO localhost
250-mail.teckumo.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN NTLM LOGIN DIGEST-MD5 CRAM-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
teckumo@teckumo_server

POP試験
teckumo@teckumo_server:~$ telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Qpopper (version 4.0.5) at teckumo_server starting.  <7002.1165794914@teckumo_server>
USER teckumo
+OK Password required for teckumo.
PASS *****
+OK teckumo has 0 visible messages (0 hidden) in 0 octets.
LIST
+OK 0 visible messages (0 octets)
.
quit
+OK Pop server at teckumo_server signing off.
Connection closed by foreign host.
teckumo@teckumo_server:~$

リレーチェック
 http://www.abuse.net/relay.htmlなどのリレーチェックサービスを利用して、 このメールサーバが転送を悪用されないか、チェックします。


コラボリンク

(同)コラボノット
ぎゃらりーぶる
(有)ケイズネットワーク
(有)マルコハウス
西田重和事務所
タケヤ環境計画研究所

スポンサードリンク

ぎゃらりーぶる通販
(株)菊竹金文堂
(有)東和自動車工場

フレンドリンク

(株)シーライズ
Copyright © 2010 TECKUMO All rights reserved.