DKIM(DomainKeys Identified Mail),電子郵件驗證標準——域名密鑰識別郵件標準。html
採用DKIM能有效的提升信件發送的成功率。一般結合spf使用。vim
系統:rhel 6.3bash
郵件服務器:postfix 2.6.6, dovecot 2.0.9,cyrus-sasl 2.1.23服務器
DKIM 版本:2.8.3dom
IP:10.40.212.8(內),210.10.166.166(外)tcp
域名:mx.zhangdh.comide
cd /etc/yum.repos.d/post
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo測試
vim CentOS6-Base-163.repo將文件裏面的$releasever全替換爲版本號6,保存退出。this
yum install sendmail-milter #解決dkim的libmilter依賴問題
wget ftp://ftp.sunet.se/pub/Linux/distributions/fedora/epel/6/x86_64/dkim-milter-2.8.3-8.el6.x86_64.rpm
rpm -ivh dkim-milter-2.8.3-8.el6.x86_64.rpm
注:若是是Centos6.5及其以上版本能夠直接使用yum安裝,安裝方法以下:
yum -y install sendmail-milter dkim-milter
遇到的坑:2014-12-11日,163鏡像因系統硬件故障而服務暫停,因此不能使用yum方式進行安裝,如何解決?
下載sendmail-milter-8.14.4-8.el6.x86_64.rpm,而後使用rpm的方式便可完成安裝。
vim /etc/mail/dkim-milter/dkim-filter.conf
===========
AutoRestart yes
AutorestartRate 10/1h
AlwaysAddARHeader yes
Canonicalization relaxed/relaxed
Domain mx.zhangdh.com
Mode sv
KeyList /etc/mail/dkim-milter/keys/keylist
ExternalIgnoreList /etc/mail/dkim-milter/trusted-hosts
InternalHosts /etc/mail/dkim-milter/trusted-hosts
LogWhy yes
Subdomains no
Selector default
SignatureAlgorithm rsa-sha256
#Socket local:/var/run/dkim-milter/dkim-milter.sock
KeyFile /etc/mail/dkim-milter/keys/mx.zhangdh.com/default
Background yes
Socket inet:8891
Syslog yes
SyslogSuccess yes
UserID dkim-milter:dkim-milter
X-Header yes
注:遇到的坑有下面幾個
1) 忘記建立文件:/etc/mail/dkim-milter/trusted-hosts
touch /etc/mail/dkim-milter/trusted-hosts
chown -R dkim-milter:dkim-milter/etc/mail/dkim-milter
2) 使用 Socket local:/var/run/dkim-milter/dkim-milter.sock遇到權限問題,「permission denied」,解決的辦法就是:Socket inet:8891[@localhost]
3) 第二步的修改,也須要同步更新/etc/postfix/main.cf
4) 不一樣之處是:生成的密鑰的命令裏default._domainkey改爲了default.domainkey;
現象是:mail postfix/smtpd[1827]:warning: connect to Milter service inet:8891: No route to host?
解決辦法?
============
vim /etc/mail/dkim-milter/trusted-hosts #設置信任的發送主機
127.0.0.1
mx.zhangdh.com
#10.40.212.0/8
a) 建立一個腳本並命名爲create_dkim,內容以下:
#!/bin/bash
usage() {
echo"Usage:"
echo" $0 <domain.com> [selector name]"
echo" default selector name =default"
exit 1
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
KEYDIR=/etc/mail/dkim-milter/keys/$1
sel=${2-default}
mkdir -p $KEYDIR
[[ $? -ne 0 ]] && exit 127
/usr/sbin/dkim-genkey -D $KEYDIR-r -d $1 -s $sel
mv $KEYDIR/${sel}.private$KEYDIR/$sel
chmod 700 $KEYDIR
chmod 600 $KEYDIR/${sel}*
chown -R dkim-milter:dkim-milter$KEYDIR
echo"*@$1:$1:/etc/mail/dkim-milter/keys/$1/$sel" >>/etc/mail/dkim-milter/keys/keylist
echo "Add this lines to $1DNS zone file"
cat $KEYDIR/$sel.txt
echo '_ssp._domainkey IN TXT"t=y; dkim=unknown"'
echo '_adsp._domainkey IN TXT"dkim=unknown"'
b) 執行腳本生成key
./create_dkim mx.zhangdh.com #mx.zhangdh.com爲郵件的域,即@後面的內容。
Add thislines to mx.zhangdh.com DNS zone file
default._domainkeyIN TXT "v=DKIM1; g=*; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDxP3g41Uf1jeCDp/slrzCuxs0vmaO7+Zgc1JC0NBDDxCirlPspz74kXettu8b2H/xE20gkjwsEIx2xgUcfzLnP3IgJETe5w1uc6fC91euaMtXNSRsOfkMKjjixCPnpy6TeYxFt6RhmJrERRCrRIaMFLusOKptd7WRFZ8WBhAWzXQIDAQAB"; ----- DKIM default for mx.zhangdh.com
_ssp._domainkeyIN TXT "t=y; dkim=unknown"
_adsp._domainkeyIN TXT "dkim=unknown"
pwd
/etc/mail/dkim-milter/keys
cat keylist
# sender-pattern:signing-domain:keypath
# *:example.com:selector
*@mx.zhangdh.com:mx.zhangdh.com:/etc/mail/dkim-milter/keys/mx.zhangdh.com/default
執行完以上腳本同時默認會在/etc/mail/dkim-milter/keys/下生成一個目錄mx5.love21cn.net。
ll
total 8
-rw------- 1dkim-milter dkim-milter 887 Dec 8 18:26default
-rw------- 1dkim-milter dkim-milter 310 Dec 8 18:26default.txt
1)default._domainkey.mx.zhangdh.com IN TXT "v=DKIM1; g=*; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDxP3g41Uf1jeCDp/slrzCuxs0vmaO7+Zgc1JC0NBDDxCirlPspz74kXettu8b2H/xE20gkjwsEIx2xgUcfzLnP3IgJETe5w1uc6fC91euaMtXNSRsOfkMKjjixCPnpy6TeYxFt6RhmJrERRCrRIaMFLusOKptd7WRFZ8WBhAWzXQIDAQAB"
2)_ssp._domainkey.mx.zhangdh.com IN TXT "t=y;dkim=unknown"
3)_adsp._domainkey.mx.zhangdh.com IN TXT"dkim=unknown"
4)mx.zhangdh.com IN TXT "v=spf1 +a +mx -all" #for spf
注:若是設置錯誤,將會出現相似下面的錯誤:
echo 'non_smtpd_milters = inet:8891' >>/etc/postfix/main.cf
echo 'smtpd_milters = inet:8891' >>/etc/postfix/main.cf
echo'milter_protocol = 2' >> /etc/postfix/main.cf
echo'milter_default_action = accept' >> /etc/postfix/main.cf
下面的兩行在postfix調用的時候會遇到權限問題,因此不採用:
echo 'smtpd_milters= local:/var/run/dkim-milter/dkim.sock' >> /etc/postfix/main.cf
echo'non_smtpd_milters = local:/var/run/dkim-milter/dkim.sock' >>/etc/postfix/main.cf
a) method1:
dig +short default._domainkey.mx.zhangdh.com txt @8.8.8.8
dig -ttxt default._domainkey.mx.zhangdh.com @8.8.8.8
dig -ttxt _ssp._domainkey.mx.zhangdh.com @8.8.8.8
dig -ttxt _adsp._domainkey.mx.zhangdh.com @8.8.8.8
b) method2:
host -ttxt default._domainkey.mx.zhangdh.com
c) method3:
http://dkimcore.org/tools/keycheck.html
https://metacpan.org/pod/Mail::DKIM::Verifier
1)設置自啓動:chkconfig--level 2345 dkim-milter on
2)啓動:/etc/init.d/dkim-milterstart
3)關閉:/etc/init.d/dkim-milterstop
這裏假設使用的是foxmail客戶端,如何查看DKIM和SPF是否定證成功,步驟以下:
第一步:打開收到的郵件。
第二步:點擊文件菜單並選擇屬性,會彈出一個對話框。
第三步:在對話框中選擇「詳細信息」->「郵件原信息(M)」,會彈出另外一個對話框。
第四步:從原始信息的對話框中查找有關DKIM和SPF相關的信息,你會看到如:
「spf=pass」和「dkim=pass」的信息,則表示認證成功。
問題1. Dec 31 10:53:21 mail postfix/smtpd[29209]: warning: connect toMilter service inet:8891: No route to host
緣由:因爲開啓了防火牆,致使postfix服務沒法連到dkim-milter的8891端口
解決辦法:
-A INPUT -p tcp -m state --state NEW -m tcp--dport 8891 -j ACCEPT
注:以上域名mx.zhangdh.com請用你真實的域名替代。