Postfix配置文件和命令
熟悉postfix中的一些命令,對于今后的維護是很必要的。接下來會分析其中一些重要的配置文件和相關(guān)命令.
一、總體說明
引用
/etc/postfix/main.cf
這是postfix的主配置文件,幾乎所有的配置都在這里設(shè)定。設(shè)定完畢后,需要用reload或restart重新讀取配置信息。(涉及網(wǎng)絡(luò)的配置,需要使用restart)
引用
/etc/postfix/master.cf
這個是postfix子程序的運行狀態(tài)設(shè)置,例如是否使用chroot等。
引用
/etc/postfix/access
類似黑白名單的作用,設(shè)置完畢后,需要在main.cf中激活,并使用postmap生成相關(guān)的數(shù)據(jù)庫。
引用
/etc/aliases
別名的設(shè)置目錄,同樣,需要在main.cf中激活,并使用postalias生成相關(guān)數(shù)據(jù)庫。
二、main.cf文件
該文件的配置比較規(guī)范,文件中也帶了很詳細的幫助說明。其主要包括幾部分:
1、“#”號開頭,表示改行是注釋;
2、可以使用下面的形式給變量定義:
引用
變量 = 值
請注意等號兩邊需要留一空格。并且變量最好符合Bash的規(guī)范。
3、可以使用“$變量”來引用該變量的值;
例如 myorigin = $myhostname,會等于 myorigin = linuxfly.org;
4、如果變量使用兩個以上的數(shù)據(jù),可以用空格符或逗號來分隔,設(shè)置跨行也可以;
例如:
引用
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
也可以寫為:
引用
mydestination = $myhostname localhost.$mydomain localhost $mydomain
或:
引用
mydestination = $myhostname,
localhost.$mydomain,
localhost,
$mydomain
結(jié)果是相同的。
5、可以使用hash等格式進行更規(guī)范的設(shè)定;
例如:
引用
alias_maps = hash:/etc/aliases
那么,相關(guān)的值就可以寫入/etc/aliases文件中。
6、若重復(fù)設(shè)定某一變量的設(shè)定,則以最后出現(xiàn)的設(shè)定值為準~!
三、/etc/postfix/access文件
1、需要在main.cf中打開
引用
/etc/postfix/main.cf:
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
2、設(shè)定值
例如:
引用
/etc/postfix/access:
192.168.228.10 REJECT
192.168.228.1 OK
linuxfly.org OK
3、生成數(shù)據(jù)庫
# postmap hash:/etc/postfix/access
四、/etc/aliases文件
1、同樣需要在main.cf中打開
引用
/etc/postfix/main.cf:
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
2、設(shè)定值
引用
/etc/aliases:
mailer-daemon: postmaster
postmaster: root
root: linuxing,root
前面是鍵值,后面是真實的值。真實的值不要求是本地郵件,也可以是外面的郵箱,例如:linuxing@163.com等。
3、生成數(shù)據(jù)庫
# postalias hash:/etc/aliases
※這會生成類似.db的數(shù)據(jù)庫文件,主要是為了讓postfix能快速的讀取。其他可以使用多值的地方也可以該方式定義。默認會自動識別,但也可以用“hash:文件”指定格式。
4、若是個人用戶,可以設(shè)置主目錄下的~/.forward文件,也可以設(shè)置別名,一行一個Email地址,例如:
引用
[linuxing@dc5test ~]$ cat .forward
test
test@test.com
[linuxing@dc5test ~]$ chmod 644 .forward
權(quán)限不要搞錯了!
五、postfix主要命令
1、查看配置信息
引用
[root@dc5test postfix]# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = $myhostname, localhost
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydomain = linuxfly.cn
mynetworks = 192.168.218.0/24, 127.0.0.0/8
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.1.5/README_FILES
relay_domains = $mydestination
sample_directory = /usr/share/doc/postfix-2.1.5/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
unknown_local_recipient_reject_code = 550
2、查看隊列信息
引用
# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
DB7678DA5 289 Wed Aug 22 16:46:28 root@linuxfly.org
(Host or domain name not found. Name service error for name=linuxfly.org type=MX: Host not found, try again)
root@linuxfly.org
-- 0 Kbytes in 1 Request.
或
引用
# postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
DB7678DA5 289 Wed Aug 22 16:46:28 root@linuxfly.org
(Host or domain name not found. Name service error for name=linuxfly.org type=MX: Host not found, try again)
root@linuxfly.org
-- 0 Kbytes in 1 Request.
結(jié)果是一樣的。
3、強制發(fā)出郵件
# postfix flush
或
# postqueue -f
這會把隊列中的郵件再發(fā)一次??梢蕴幚硪恍┡R時的錯誤問題。
4、查看在發(fā)郵件信息
在發(fā)的郵件會放在/var/spool/postfix/deferred目錄中,但其中含有一些postfix特定字符,可通過postcat查看:
引用
# postcat DB7678DA5
*** ENVELOPE RECORDS DB7678DA5 ***
message_size: 289 163 1 0
message_arrival_time: Wed Aug 22 16:46:28 2007
named_attribute: message_origin=local
sender_fullname: root
sender: root@linuxfly.org
original_recipient: root@linuxfly.org
recipient: root@linuxfly.org
*** MESSAGE CONTENTS DB7678DA5 ***
Received: by dc5test.linuxfly.org (Postfix, from userid 0)
id DB7678DA5; Wed, 22 Aug 2007 16:46:28 +0800 (CST)
To: root@linuxfly.org
Subject: test
Message-Id: <20070822084628.DB7678DA5@dc5test.linuxfly.org>
Date: Wed, 22 Aug 2007 16:46:28 +0800 (CST)
From: root@linuxfly.org (root)
*** HEADER EXTRACTED DB7678DA5 ***
*** MESSAGE FILE END DB7678DA5 ***
5、一些Email測試用命令
◎mail,字符下的客戶端
$ mail -s 'subject' linuxing < ~/file
把file中的內(nèi)容作為郵件內(nèi)容,以subject做標題,發(fā)給本地的linuxing用戶。
引用
$ mail -s 'subject' linuxing
test
Ctrl-D保存退出
Cc: root
●mail直接回車
則是作為本地的郵件接收客戶端,可以用d刪除,回車查看,序號查看,help幫助或q退出等操作。
引用
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 2 messages 2 unread
>U 1 root@linuxfly.org Tue Aug 21 11:56 94/2251 "LogWatch for dc5test"
U 2 root@linuxfly.org Tue Aug 21 11:57 23/846 "Anacron job 'cron.daily'"
●使用mail發(fā)送附件
# uuencode /root/install.log install.log|mail -s 'install log' linuxing
uuencode后第一個參數(shù)的本地文件,第二個參數(shù)是郵件中的附件名稱。
●字符下收信:
引用
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/linuxing": 1 message 1 new
>N 1 root@linuxfly.org Wed Aug 22 17:10 853/52344 "install log"
& s 1 install.log
"install.log" [New file]
& exit
會保存為install.log文件,然后再解壓出來:
$ uudecode install.log -o install.log
uudecode: install.log: Short file
◎telnet,測試smtp和pop3服務(wù)
●smtp服務(wù)
引用
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 dc5test.linuxfly.org ESMTP Postfix
ehlo localhost
250-dc5test.linuxfly.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 NTLM LOGIN GSSAPI PLAIN
250-AUTH=DIGEST-MD5 CRAM-MD5 NTLM LOGIN GSSAPI PLAIN
250 8BITMIME
mail from:"root"
250 Ok
rcpt to:
250 Ok
data
354 End data with
A test mail.
.
250 Ok: queued as A27B38DAF
quit
221 Bye
Connection closed by foreign host.
※內(nèi)容后的“.”號表示內(nèi)容的終結(jié)符。
●pop3服務(wù)
引用
# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK dovecot ready.
user linuxing
+OK
pass password
+OK Logged in.
list
+OK 1 messages:
1 576
retr 1
+OK 576 octets
Return-Path:
X-Original-To: linuxing
Delivered-To: linuxing@linuxfly.org
Received: by dc5test.linuxfly.org (Postfix, from userid 0)
id D6D728DB4; Wed, 22 Aug 2007 17:28:33 +0800 (CST)
To: linuxing@linuxfly.org
Subject: subject
Message-Id: <20070822092833.D6D728DB4@dc5test.linuxfly.cn>
Date: Wed, 22 Aug 2007 17:28:33 +0800 (CST)
From: root@linuxfly.org (root)
X-IMAPbase: 1187497071 28
Status: O
X-UID: 28
Content-Length: 13
X-Keywords:
A test mail.
quit
+OK Logging out.
Connection closed by foreign host.
【編輯推薦】