您好,登錄后才能下訂單哦!
wget http://sourceforge.net/p
SMTP:(Simple Mail Transfer Protocol)即簡單郵件傳輸協議
POP3:郵局協議 IMAP4:internet mail access protocol 互聯網郵件訪問協議
SASL:simple Authentication Secure layer 簡單安全認證層 (版本v1,v2目前主流v2版本)
MDA:郵件投遞代理(procmail,maildrop)
MUA:郵件用戶代理(mutt)
mail relay: 郵件中繼
MTA:報文傳輸代理 (sendmail,postfix,qmail,exim)
Postfix的配置文件:
postfix模塊化:
master:/etc/postfix/master.cf 主進程配置文件
mail:/etc/postfix/main.cf 主配置文件(相關配置的主配置文件)
格式:參數 = 值:參數必須寫在絕對行首(即行首不能有空格),以空白開頭的行被認
為是上一行的延續(即行首有空白的行都是上一行沒有寫完的內容)。
postconfig: 可以直接配置修改postfix的主配置文件
-d: 顯示默認的配置
-n: 修改了的配置
-m: 顯示支持的查找表類型
-A:顯示支持的SASL客戶端插件類型
-e PARMATER=VALUE: 更改某參數配置信息,并保存至main.cf主配置文件中
-a: 服務器端支持的SASL插件類型
smtp狀態碼:
1xx:純信息
2xx:正確信息
3xx:上一步操作尚未完成,需要繼續補充
4xx:暫時性錯誤
5xx:永久性錯誤
smtp協議命令:
helo (smtp協議)
ehlo (esmtp協議)
mail from: 指定發件人
rcpt to:指定收件人
data 輸入正文
Subject: 郵件主題
郵件正文以.結束
quit退出郵件
[root@lamp ~]#ls
postfix-2.10.10.tar.gz
[root@lamp ~]# tar xf postfix-2.10.10.tar.gz #解壓postfix軟件
[root@lamp ~]# ls
postfix-2.10.10 postfix-2.10.10.tar.gz
[root@lamp ~]# cd postfix-2.10.10 #進入解壓目錄
[root@lamp postfix-2.10.10]# groupadd -g 2525 postfix #新建組postfix
[root@lamp postfix-2.10.10]# useradd -g postfix -u 2525 -M -s /sbin/nologin postfix
#新建用戶postfix -g指定所屬組,-u指定UID,-M不創建家目錄,-s指定登錄shell為不可登錄nologin.
[root@lamp postfix-2.10.10]# id postfix #查看postfix用戶信息
uid=2525(postfix) gid=2525(postfix) 組=2525(postfix)
[root@lamp postfix-2.10.10]# groupadd -g 2526 postdrop #新建組postdrop
[root@lamp postfix-2.10.10]# useradd -g postdrop -u 2526 -M -s /sbin/nologin postdrop
[root@lamp postfix-2.10.10]# id postdrop
uid=2526(postdrop) gid=2526(postdrop) 組=2526(postdrop)
[root@lamp postfix-2.10.10]# yum list all |grep sasl
#查看安裝的sasl,確保以下sasl組建已經安裝。
This system is not registered with RHN.
RHN support will be disabled.
cyrus-sasl.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-devel.x86_64 2.1.23-8.el6 @Server
cyrus-sasl-lib.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-md5.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-plain.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
開始執行編譯安裝:
[root@lamp postfix-2.10.10]# make
makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include
-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS
''AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm
-L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
[root@lamp postfix-2.10.10]# make && make install
#需指定相關的路徑,路徑可以不用更改,所有的都默認即可。
[root@lamp ~]# postfix start #啟動postfix進程
postfix/postfix-script: starting the Postfix mail system
[root@lamp ~]# netstat -tlnp #查看郵件服務25端口是否監聽
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1553/cupsd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 27814/master
tcp 0 0 :::111 :::* LISTEN 1385/rpcbind
tcp
0 0 :::80 :::* LISTEN 2001/httpd
tcp 0 0 :::22 :::* LISTEN 1659/sshd
[root@lamp ~]# tail /var/log/maillog #查看postfix郵件服務日志信息
Feb 28 13:29:01 lamp postfix/postfix-script[27811]: starting the Postfix mail system
Feb 28 13:29:01 lamp postfix/master[27814]: daemon started -- version 2.10.10, configuration /etc/postfix
[root@lamp ~]# telnet localhost 25 #給本機發送郵件
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 lamp.com ESMTP Postfix
helo localhost
250 lamp.com
mail from:root #發件人
250 2.1.0 Ok
rcpt to:donggen #收件人
250 2.1.5 Ok
data #郵件正文
354 End data with <CR><LF>.<CR><LF>
Subject:How are you these days? #郵件主題
Are you gua le ma?
. #.結束正文
250 2.0.0 Ok: queued as 01311413
quit #quit退出發送郵件
221 2.0.0 Bye
Connection closed by foreign host.
[root@lamp ~]# tail /var/log/maillog #查看日志文件
Feb 28 14:56:20 lamp postfix/master[28749]: daemon started -- version 2.10.10, configuration /etc/postfix
Feb 28 14:56:44 lamp postfix/smtpd[28763]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Feb 28 14:56:44 lamp postfix/smtpd[28763]: connect from localhost.localdomain[127.0.0.1]
Feb 28 14:57:27 lamp postfix/smtpd[28763]: 01311413: client=localhost.localdomain[127.0.0.1]
Feb 28 14:58:12 lamp postfix/cleanup[28766]: 01311413: message-id=<20170228065727.01311413@lamp.com>
Feb 28 14:58:12 lamp postfix/qmgr[28751]: 01311413: from=<root@lamp.com>, size=332, nrcpt=1 (queue active)
Feb 28 14:58:12 lamp postfix/local[28776]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Feb 28 14:58:12 lamp postfix/local[28776]: 01311413: to=<donggen@lamp.com>, orig_to=<donggen>, relay=local, delay=56, delays=56/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
Feb 28 14:58:12 lamp postfix/qmgr[28751]: 01311413: removed
Feb 28 14:58:17 lamp postfix/smtpd[28763]: disconnect from localhost.localdomain[127.0.0.1]
[donggen@lamp ~]$ mail #切換使用者,查看郵件。
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/donggen": 1 message 1 new
>N 1 root@lamp.com Tue Feb 28 14:58 14/452 "How are you these days?"
Status: R
Are you OK?
postfix服務啟動腳本:可以通過service postfix start|restart
腳本如下:vim /etc/init.d/postfix
1、編輯postfix服務啟動腳本
[root@lamp ~]# vim /etc/init.d/postfix
#!/bin/bash
#
#postfix Postfix Mail Transfer Agent
#
#description: Postfix is a Mail Transport Ageent,which is the progrom
# that moves mail from one mochine to another.
#processname:master
#pidfile:/var/spool/postfix/pid/master.pid
#config: /etc/postfix/main.cf
#config: /etc/postfix/master.cf
#Source function library.
. /etc/rc.d/init.d/functions
#Source networking configuretion.
. /etc/sysconfig/network
#Check that networking is up.
[ $NETWORKING = "NO" ] && exit 3
[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6
RETVAL=0
prog="postfix"
start() {
# start daemons.
echo -n $"Starting postfix: "
/usr/bin/newaliases >/dev/null 2>&1
/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
echo
return $RETVAL
}
stop() {
# stop daemons.
echo -n $"Shutting down postfix: "
/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
echo
return $RETVAL
}
reload() {
echo -n $"Reloading postfix: "
/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
RETVAL=$?
echo
return $RETVAL
}
abort() {
/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
return $?
}
flush() {
/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
return $?
}
check() {
/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
return $?
}
restart() {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
abort)
abort
;;
flush)
flush
;;
check)
check
;;
status)
status master
;;
condrestart)
[ -f /var/lock/subsys/postfix ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
exit 1
;;
esac
exit $?
# END
[root@lamp ~]# chmod +x /etc/init.d/postfix
[root@lamp ~]# chkconfig --add postfix #把postfix添加至開機啟動
[root@lamp ~]# chkconfig --list postfix #查看postfix開機是否自動啟動
[root@lamp ~]# service postfix restart
關閉 postfix: [確定]
啟動 postfix: [確定]
2、進行一些基本配置,測試啟動postfix并進行發信。
修改/etc/postfix/main.cf
修改以下幾項配置(紅色部分):
myhostname = mail.lamp.com
myorigin =
mydomain =
mydestination =
mynetworks =
說明:
myorigin參數用來指明發件人所在的域名,即做發件地址偽裝;
myhostname參數指定運行postfix郵件系統的主機的主機名,默認情況下,其值被設定為本地機器名;
mydomain參數指定自己的域名,默認情況下postfix將myhostname的第一部分刪除而作為mydomain的值;
mydestination參數指定postfix接收郵件時收件人的域名,即你的postfix系統要接受到那個域名的郵件
mynetworks參數指定你所在的網絡的網絡地址,postfix系統根據其值來區別用戶是遠程的還是本地的,
如果是本地網絡用戶則允許其訪問;
inet_interfaces參數指定postfix系統監聽的網絡接口;
注意:
1、在postfix的配置文件中,參數行和注釋行是不能處在同一行中的;
2、任何一個參數的值都不需要加引號,否則,引號將會被當做參數值的一部分來使用;
3、每修改參數及其值后執行postfix reload即可令其生效,但若修改了inet_interfaces;
則需重新啟動postfix;
4、如果一個參數的值有多個,可以將他們放在不同的行中,只需要在其后的每個行前多置一個空格
即可;postfix會把第一個字符為空格或tab的文本行視為上一行的延續;
3、修改主機名
[root@lamp ~]# hostname mail.lamp.com #臨時修改主機名,立即生效,重啟失效
[root@lamp ~]# hostname
mail.lamp.com
[root@lamp ~]# vim /etc/sysconfig/network #永久生效,修改主機名,重啟后生效
NETWORKING=yes
HOSTNAME=mail.lamp.com
[root@mail ~]# hostname
mail.lamp.com
4、安裝配置DNS服務器
[root@mail ~]# rpm -qa |grep bind #查看系統是否安裝過DNS
PackageKit-device-rebind-0.5.8-13.el6.x86_64
bind-libs-9.7.0-5.P2.el6.x86_64
samba-winbind-clients-3.5.4-68.el6.x86_64
bind-utils-9.7.0-5.P2.el6.x86_64
rpcbind-0.2.0-8.el6.x86_64
[root@mail ~]# rpm -e bind-libs bind-utils #先卸載已經安裝的bind
[root@mail ~]# yum install bind.x86_64 bind-libs bind-utils
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.7.0-5.P2.el6 set to be updated
---> Package bind-libs.x86_64 32:9.7.0-5.P2.el6 set to be updated
---> Package bind-utils.x86_64 32:9.7.0-5.P2.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================
Install 3 Package(s)
Upgrade 0 Package(s)
Total download size: 4.4 M
Installed size: 8.9 M
Is this ok [y/N]: y
Downloading Packages:
-----------------------------------------------------------------------------------------------------
Total 80 MB/s | 4.4 MB 00:00
Complete! #安裝完成
[root@mail ~]# vim /etc/named.conf #編輯DNS配置文件
[root@mail ~]# service named start #啟動DNS服務
啟動 named: [確定]
[root@mail ~]# netstat -tlnp #查看監聽的端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:56201 0.0.0.0:* LISTEN 1450/rpc.statd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1958/mysqld
tcp 0 0 10.109.134.237:53 0.0.0.0:* LISTEN 7794/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 7794/named
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2229/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1659/sshd
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 7794/named
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6341/master
[root@mail ~]# vim /etc/named.rfc1912.zones #編輯正向和反向代理設置,
在最末尾增加以下內容:
zone "lamp.com" IN {
type master;
file "lamp.com.zone";
allow-update { none; };
allow-transfer { none; };
};
zone "134.109.10.in-addr.arpa" IN {
type master;
file "10.109.134.zone";
allow-update { none; };
allow-transfer { none; };
};
[root@mail ~]# named-checkconf #檢查dns配置文件是否有語法錯誤
[root@mail ~]# named-checkconf /etc/named.conf #指定檢查那個DNS配置文件是否有語法錯誤
[root@mail ~]# cd /var/named/
[root@mail named]# vim lamp.com.zone #編輯正向代理文件,內容如下;
[root@mail named]# vim 10.109.134.zone #編輯反向代理文件,內容如下;
[root@mail named]# chgrp named lamp.com.zone 10.109.134.zone #更改組為named
[root@mail named]# chmod 640 10.109.134.zone lamp.com.zone #修改權限為640
[root@mail named]# ll
總用量 36
-rw-r-----. 1 root named 285 3月 1 11:46 10.109.134.zone
drwxrwx---. 2 named named 4096 3月 1 11:01 data
drwxrwx---. 2 named named 4096 3月 1 11:02 dynamic
-rw-r-----. 1 root named 292 3月 1 11:43 lamp.com.zone
-rw-r-----. 1 root named 1892 2月 18 2008 named.ca
-rw-r-----. 1 root named 152 12月 15 2009 named.empty
-rw-r-----. 1 root named 152 6月 21 2007 named.localhost
-rw-r-----. 1 root named 168 12月 15 2009 named.loopback
drwxrwx---. 2 named named 4096 5月 26 2010 slaves
[root@mail named]# named-checkzone "lamp.com" lamp.com.zone #檢查正向代理文件是否正確
zone lamp.com/IN: loaded serial 2017030101
OK
[root@mail named]# named-checkzone "134.109.10.in-addr.arpa" 10.109.134.zone #檢查反向代理配置文件是否正確
zone 134.109.10.in-addr.arpa/IN: loaded serial 2017030101
OK
[root@mail named]# service named restart #重啟named服務
停止 named: [確定]
啟動 named: [確定]
[root@mail named]# chkconfig named on #加入到開機啟動列表
[root@mail named]# dig -t MX lamp.com @10.109.134.237 #測試解析MX記錄是否正常
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> -t MX lamp.com @10.109.134.237
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46065
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; QUESTION SECTION:
;lamp.com.INMX
;; ANSWER SECTION:
lamp.com.600INMX10 mail.lamp.com.
;; AUTHORITY SECTION:
lamp.com.600INNSns.lamp.com.
;; ADDITIONAL SECTION:
mail.lamp.com.600INA10.109.134.237
ns.lamp.com.600INA10.109.134.237
;; Query time: 0 msec
;; SERVER: 10.109.134.237#53(10.109.134.237)
;; WHEN: Wed Mar 1 13:39:05 2017
;; MSG SIZE rcvd: 96
[root@mail named]# dig -t A mail.lamp.com @10.109.134.237 #測試郵件A記錄解析是否正常
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> -t A mail.lamp.com @10.109.134.237
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46985
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;mail.lamp.com.INA
;; ANSWER SECTION:
mail.lamp.com.600INA10.109.134.237
;; AUTHORITY SECTION:
lamp.com.600INNSns.lamp.com.
;; ADDITIONAL SECTION:
ns.lamp.com.600INA10.109.134.237
;; Query time: 0 msec
;; SERVER: 10.109.134.237#53(10.109.134.237)
;; WHEN: Wed Mar 1 13:46:39 2017
;; MSG SIZE rcvd: 80
[root@mail named]# cd /etc/postfix
[root@mail postfix]# vim main.cf #編輯postfix郵箱服務主配置文件,內容如下;
[root@mail postfix]# service postfix restart
關閉 postfix: [確定]
啟動 postfix: [確定]
[root@mail postfix]# vim /etc/resolv.conf #編輯DNS配置
[root@mail postfix]# telnet mail.lamp.com 25
Trying 10.109.134.237...
Connected to mail.lamp.com.
Escape character is '^]'.
220 mail.lamp.com ESMTP Postfix
helo mail.lamp.com
250 mail.lamp.com
mail from:test@test.com
250 2.1.0 Ok
rcpt to:admin@xuelinux.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello
.
250 2.0.0 Ok: queued as 2623AE31
quit
221 2.0.0 Bye
Connection closed by foreign host.
postfix2.10下載地址:
ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/index.html
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。