Postfixでメール送信サーバを作ろう!
ここでは、Postfixのインストール手順を掲載しています。
メール送受信の仕組み
手紙を出すとき、通常[ポスト]→[最寄りの郵便局]→[宛先最寄りの郵便局]→[宛先郵便受け]の順に手紙が配送されます。
電子メールも同様に、[送信]→[送信用サーバ(SMTPサーバ)]→[受信用サーバ(POP/IMAPサーバ)]→[受信]の流れとなります。

つまり、電子メールの送受信には、送信用と受信用それぞれのサーバが必要です。
今回は送信用サーバにPostfix、受信用サーバにDovecotを使いたいと思います。
Postfixとは…?
Postfixはオープンソースで開発されている送信用サーバ(SMTPサーバ)です。
SMTPとはSimple Mail Transfer Protocolの略で、メール送信のときに使われるルールのことです。SMTPではメールの送信に認証作業がありません。なので、SMTP-AUTHを利用して送信前に認証を行い、不正中継を防止します。
Postfixのインストール
[root@co ~]# yum -y install postfix
Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
base | 1.1 kB 00:00
extras | 2.1 kB 00:00
updates | 1.9 kB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postfix.x86_64 2:2.3.3-6.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
postfix x86_64 2:2.3.3-6.el5 base 3.8 M
Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 3.8 M
Downloading Packages:
postfix-2.3.3-6.el5.x86_64.rpm | 3.8 MB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : postfix 1/1
Installed:
postfix.x86_64 2:2.3.3-6.el5
Complete!
Postfixの設定
インストールが終わったら、Postfixの設定を行います。
[root@co ~]# vi /etc/postfix/main.cf
#myhostname = host.domain.tld
↓
myhostname = co.kimamabi.mydns.jp
#mydomain = domain.tld
↓
mydomain = kimamabi.mydns.jp
#myorigin = $mydomain
↓
myorigin = $mydomain (@以下にドメインを付加する)
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
↓
inet_interfaces = all (外部からのメール受信を許可する)
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost
mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
↓
#mydestination = $myhostname, localhost.$mydomain, localhost (ドメイン宛てのメール受信を許可する)
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#home_mailbox = Maildir/
↓
home_mailbox = Maildir/ (メールの保存形式をMaildirに設定)
#smtpd_banner = $myhostname ESMTP $mail_name
↓
smtpd_banner = $myhostname ESMTP unknown (メールサーバ名を非表示に設定)
また、最後尾にSMTP-AUTH用の設定を書き込みます。
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
SMTP-AUTHの有効化
SMTP-AUTHに必要なsaslauthdを起動します。
今回はCentOSのユーザアカウントを使って認証を行うこととします。もし送信用ユーザを別に設定をしたい場合はこちらを参考にしてください。
[root@co ~]# /etc/rc.d/init.d/saslauthd start
saslauthd を起動中: [ OK ]
[root@co ~]# chkconfig saslauthd on
[root@co ~]# chkconfig --list saslauthd
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Sendmailの停止
CentOS 5にはSendmailというSMTPサーバがあらかじめインストールされています。Postfixと競合するので、まずはSendmailを停止します。
[root@co ~]# /etc/rc.d/init.d/sendmail stop
sm-client を停止中: [ OK ]
sendmail を停止中: [ OK ]
[root@co ~]# chkconfig sendmail off
[root@co ~]# chkconfig --list sendmail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
メールサーバの切り替え
Sendmailに設定されていたサーバをPostfixに切り替えます。
[root@co ~]# alternatives --config mta
2 プログラムがあり 'mta' を提供します。
選択 コマンド
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2
Postfixの起動
[root@co ~]# /etc/rc.d/init.d/postfix start
postfix を起動中: [ OK ]
[root@co ~]# chkconfig postfix on
[root@co ~]# chkconfig --list postfix
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
OP25B対策について
OP25B(Outbound Port 25 Blocking)についてはこちらを参考に設定してください。
Dovecotの設定へと続きます。
今回新しく登場したコマンド
[広告]

トップページ
Rocky Linux 8
CentOS 7
Scientific Linux 6
CentOS 5
○準備
○VMware Player
○Hyper-V(Win Proのみ)
○導入
○セキュリティ対策
○Dynamic DNS
○NTPサーバ
○データベース
○WEBサーバ
○FTPサーバ
○メールサーバ
○DNSサーバ
○ファイルサーバ
○ブログシステム
○その他
ブログ
[広告]