2020年8月18日 星期二

Postfix + SPF + DKIM

現在自架的 Mail Server 若沒有簽章,寄出的信件有很大的機會被擋或歸類在垃圾信
所以 SPF + DKIM 已經是必要的設定
環境 CentOS + Postfix,文中的域名均以 yourdomain.com 作為範例

安裝所需套件
yum -y install pypolicyd-spf opendkim

在你的域名的 DNS 設定加一筆 TXT 指到 "v=spf1 a mx ~all"
這個設定已經可以符合大部份的狀況,若需要進階的設定,可以搜尋 SPF record generator

產生 DKIM Key
opendkim-genkey -t -b 2048 -d yourdomain.com

執行完後,會在產生兩個檔
default.private 私鑰
default.txt 需設定到域名 TXT 的資訊
把這兩個檔搬到 /etc/opendkim/keys 目錄
mv default.private default.txt /etc/opendkim/keys

在域名的 DNS 設定,新增一筆 default._domainkey TXT 內容是上面那個 default.txt 括號裡面的內容

編輯 /etc/opendkim.conf

Mode    sv

Uncomment 這幾行
KeyTable      /etc/opendkim/KeyTable
SigningTable  refile:/etc/opendkim/SigningTable
ExternalIgnoreList    refile:/etc/opendkim/TrustedHosts
InternalHosts refile:/etc/opendkim/TrustedHosts

編輯 /etc/opendkim/KeyTable
default._domainkey.yourdomain.com yourdomain.com:default:/etc/opendkim/keys/default.private

編輯 /etc/opendkim/SigningTable
*@yourdomain.com default._domainkey.yourdomain.com

編輯 /etc/opendkim/TrustedHosts 預設的 localhost IPv4、IPv6 需保留,再填上主機的 Public IP 及 Hostname
127.0.0.1
::1
Your_Public_IP
yourdomain.com

建立 policyd-spf user
useradd policyd-spf -s /bin/false

最後調整 postfix 設定
/etc/postfix/master.cf 加入
policyd-spf  unix  -       n       n       -       0       spawn
    user=policyd-spf argv=/usr/libexec/postfix/policyd-spf

/etc/postfix/main.cf 加入
policyd-spf_time_limit = 3600
smtpd_recipient_restrictions =
   permit_mynetworks,
   permit_sasl_authenticated,
   reject_unauth_destination,
   check_policy_service unix:private/policyd-spf

# OpenDKIM
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters

寄一封測試信到 Gmail,若沒有問題的話,收件方的 Mail 可以看到類似以下 Header
Authentication-Results: yourdomain.com;
        dkim=pass (2048-bit key) header.d=yourdomain.com header.i=@yourdomain.com header.b="WsyNs1qw"
        spf=pass (google.com: domain of root@yourdomain.com designates 167.xx.xx.xx as permitted sender) smtp.mailfrom=root@yourdomain.com
Received-SPF: pass
DKIM-Filter: OpenDKIM Filter
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yourdomain.com;

2020年8月10日 星期一

Taiwan to Google Compute Engine US area ping test

PING 10 次取平均,從 HiNet FTTH PING

理論上,西岸 PING 值會比較好,測試結果也是如此

us-west1 (奧勒岡州) 125ms 👍 最佳

us-west2 (洛杉磯) 133ms

us-west3 (鹽湖城) 145ms

us-west4 (拉斯維加斯) 140ms

us-central1 (愛荷華州) 157ms

us-east1 (南卡羅來納州) 191ms

us-east4 (北維吉尼亞州) 188ms

 

GCE 免費方案 有提供每月 1 個 f1-micro 執行個體 (僅限美國地區,北維吉尼亞州 [us-east4] 除外)

若要從台灣連過去快一點的,就選 us-west1 (奧勒岡州)

 

DNS negative cache

在查詢一個域名時,若當資料不存在,會出現 NXDOMAIN DNS 也會 cache 這個查不到的結果,其預設的 TTL 跟 DNS 及 Zone 的 SOA TTL 有關 例如 BIND 的 max-ncache-ttl 預設是 10800 秒 當 SOA 中的 TTL 小於 ...