postfix安裝和簡單配置

tonykorn97發表於2008-10-21

一,安裝:
[root@station10 ~]# yum install -y postfix

[@more@]

二,postconf工具介紹

Display defaults: postconf -d
Display current non-default settings: postconf -n
Modify main.cf:postconf -e key=value
Show supported map types: postconf -m

三,Incomming Postfix Configuration
修改/etc/postfix/main.cf檔案
1,監聽所有埠:
inet_interfaces = all
2,specify each name and alias by which the server may be referred (監聽主機)
mydestination = $myhostname,localhost,mydomain,localhot,$mydomain

3,把預設的配置inet_interfaces = localhost 修改成:
inet_interfaces = all

4,監聽主機預設可以不用改。

四,outgoing postfix configuration
配置/etc/postfix/main.cf檔案

myorigin = $mydomain
masquerade_exceptions = root

此次配置成:
myorigin = $myhostname
masquerade_exceptions = root

測試上面兩步:
5,station10用的是postfix傳送到郵件,station12是用sendmail接收的。
station10傳送郵件:
[root@station10 ~]# mail
Subject: test
postfix
.
Cc:
[root@station10 ~]#


station12接收郵件:
[root@station12 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 Wed Oct 22 08:13 15/629 "test"
& 1
Message 1:
From Wed Oct 22 08:13:25 2008
To:
Subject: test
Date: Wed, 22 Oct 2008 01:00:25 +0800 (CST)
From: (root)

postfix

& q
Saved 1 message in mbox
[root@station12 ~]#

6,更改outgoing postfix 配置:
此次配置成:
myorigin = $mydomain
masquerade_exceptions = root

測試傳送:
[root@station10 ~]# mail
Subject: test
myorigin
.
Cc:
[root@station10 ~]#

接收檢視資訊:
[root@station12 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 Wed Oct 22 08:19 15/600 "test"
& 1
Message 1:
From Wed Oct 22 08:19:01 2008
To:
Subject: test
Date: Wed, 22 Oct 2008 01:06:00 +0800 (CST)
From: (root)

myorigin

& q
Saved 1 message in mbox
[root@station12 ~]#


五,inbound postfix aliases
1,本地別名配置和sendmail配置一樣,都是修改/etc/aliases檔案
如果讓修改直接生效,執行:
[root@station10 ~]# postalias /etc/aliases

2,虛擬配置:
(1),編輯/etc/postfix/mail.cf檔案
virtual_alias_maps = hash:/etc/postfix/virtual
(2),/etc/postfix/mail.cf的格式和sendmail一樣
(3),rehash the file: postmap /etc/postfix/virtual

3, 實際配置:
(1),在/etc/postfix/mail.cf檔案末尾新增:
virtual_alias_maps = hash:/etc/postfix/virtual
(2), 在/etc/postfix/virtual檔案末尾新增:

(3),[root@station10 ~]# postmap /etc/postfix/virtual

4, 測試:
本地別名測試:
[root@station10 ~]# mail xxx
Subject: test
send to xxx
.
Cc:
[root@station10 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 1 message 1 unread
>U 1 Wed Oct 22 01:34 15/487 "test"
& 1
Message 1:
From Wed Oct 22 01:34:57 2008
X-Original-To: xxx
Delivered-To:
To:
Subject: test
Date: Wed, 22 Oct 2008 01:34:57 +0800 (CST)
From: (root)

send to xxx

& q
Saved 1 message in mbox
[root@station10 ~]#

虛擬別名測試:
[root@station10 ~]# mail
Subject: test
send to station10.example.com
.
Cc:
[root@station10 ~]#

在另外一臺機器上收到郵件:
[root@station12 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 2 messages 2 new
>N 1 Wed Oct 22 08:43 15/609 "test"
N 2 Wed Oct 22 08:49 15/651 "test"
& 2
Message 2:
From Wed Oct 22 08:49:10 2008
To:
Subject: test
Date: Wed, 22 Oct 2008 01:36:09 +0800 (CST)
From: (root)

send to station10.example.com

& q
Saved 1 message in mbox
Held 1 message in /var/spool/mail/root
[root@station12 ~]#

六,outbound address rewriting
1, Enable in /etc/postfix/main.cf
smtp in the key name indicates SMTP only (not LMTP)

smtp_generic_maps = hash:/etc/postfix/generic

2, define in /etc/postfix/generic


3,Rehash the file: postmap /etc/postfix/generic


測試:
[root@station10 ~]# mail
Subject: test
from to station12.example.com
.'
.
Cc:
[root@station10 ~]#


[root@station12 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 2 messages 1 new 2 unread
U 1 Wed Oct 22 08:43 16/619 "test"
>N 2 Wed Oct 22 09:04 16/621 "test"
& 2
Message 2:
From Wed Oct 22 09:04:55 2008
To:
Subject: test
Date: Wed, 22 Oct 2008 01:51:53 +0800 (CST)
From: (root)

from to station12.example.com
.'

& q
Saved 1 message in mbox
Held 1 message in /var/spool/mail/root
[root@station12 ~]#


七,Postfix SMTP Restrictions
1,Create /etc/postfix/access
untagged version of Sendmail access file
rehash using postmap /etc/postfix/access

2,Edit main.cf

smtpd_TAG_restrictions =
check_TAG_access hash:/etc/postfix/access,...

TAG is one of sender,recipient,or client
Example:

smtpd_recipient_restrictions =
check_recipient_access hash:/etc/postfix/access,permit_mynetworks,reject_unauth_destination


八,postfix Operation
main.cf settings
Server names:mydestination must contain server's name and aliases
Listning interfaces:inet_interfaces = all
Archive all messages:always_bcc = address

View SMTP exchange: mail -v
檢視佇列:postqueue -p
清空佇列:postqueue -f
日誌資訊:tail -f /var/log/maillog


例子:
[root@station10 ~]# postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
865B8306C9 101 Wed Oct 22 01:25:43 root
xxx

76670306C8 156 Wed Oct 22 01:24:15 root

-- 0 Kbytes in 2 Requests.
[root@station10 ~]# postqueue -f

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-1012222/,如需轉載,請註明出處,否則將追究法律責任。

相關文章