加入書籤 facebook twiter plurk google Yahoo! My Web
 

SPF 設定格式教學

 

1. 定義使用的 SPF 版本
例如: v=spf1

2. 設定內容
例如: 授權6.6.6.6及7.7.7.7兩台郵件伺服器,設定內容如下:
ip4:6.6.6.6 ip4:7.7.7.7 ~all

設定內容可授權一到多組網路位址(IPv4 / IPv6),網路位址也能是網段(CIDR)。授權網路位址之後通常會加上all設定、include設定。

  1. all 機制為測試結果總是為符合(match) 。
  2. include 機制為觸發遞迴執行 check_host()。

例如:v=spf1 include:example.com include:example.org -all

符號        check_host()結果    處理結果
"+"           Pass                         match
"-"            Fail                          not match
"~"           SoftFail                    not match
"?"           Neutral                     not match

關於all使用 “-” 或 “~”,需視需求使用。若只想將信件標註為未授權主機發送,並不想拒絕接收信件,請使用 “~”。

常用的設定

一、設定兩筆 SPF 設定
錯誤的設定
v=spf1 ip4:6.6.6.6 ~all
v=spf1 ip4:7.7.7.7 ~all

以上的設定將導致SPF檢查失敗. 請改為
v=spf1 ip4:6.6.6.6 ip4:7.7.7.7 ~all

二、設定網段
v=spf1 ip4:6.6.6.0/24 ~all

三、匯入其他網段設定
v=spf1 include:_spf.goodsender.com.tw ~all

_spf.goodsender.com.tw SPF 設定為 v=spf1 ip4:6.6.6.6 ~all

四、參考GMail設定
使用 dig 指令查詢網域的SPF設定,查詢資料類型請使用TXT。
(1) # dig @8.8.8.8 gmail.com TXT
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @8.8.8.8 gmail.com TXT
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48488
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;gmail.com.                     IN      TXT

;; ANSWER SECTION:
gmail.com.              299     IN      TXT     "v=spf1 redirect=_spf.google.com"

;; Query time: 15 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Aug 19 10:35:05 2014
;; MSG SIZE  rcvd: 71

可以看到 Gmail 轉向使用 google.com 的設定

(2) # dig @8.8.8.8 _spf.google.com TXT
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @8.8.8.8 _spf.google.com TXT
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22749
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;_spf.google.com.               IN      TXT

;; ANSWER SECTION:
_spf.google.com.        279     IN      TXT     "v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"

;; Query time: 11 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Aug 19 10:35:21 2014
;; MSG SIZE  rcvd: 149

可以看到 google.com 匯入三組設定 _netblocks.google.com、 _netblocks2.google.com、_netblocks3.google.com,選擇 _netblocks.google.com 看看其中的設定。

(3) # dig @8.8.8.8 _netblocks.google.com TXT
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @8.8.8.8 _netblocks.google.com TXT
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17859
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;_netblocks.google.com.         IN      TXT

;; ANSWER SECTION:
_netblocks.google.com.  3599    IN      TXT     "v=spf1 ip4:216.239.32.0/19 ip4:64.233.160.0/19 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:209.85.128.0/17 ip4:66.102.0.0/20 ip4:74.125.0.0/16 ip4:64.18.0.0/20 ip4:207.126.144.0/20 ip4:173.194.0.0/16 ~all"

;; Query time: 12 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Aug 19 10:36:20 2014
;; MSG SIZE  rcvd: 254

可以看到 _netblocks.google.com 設定授權多組網段。

TWNIC 如何設定 SPF

1. DNS設定使用代管
(1) 登入 RS 網站選擇DNS 設定/代管

(2) 選擇進階模式,輸入主機名稱、設定型態及IP/名稱。

(3) 填寫完成,等候DNS設定生效。

2. DNS設定自行架設主機管理
請至 DNS 服務供應商網站或DNS伺服器設定檔加上一筆TXT設定,設定內容請參考代管設定。

參考資料

1. RFC 1035 DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION
2. RFC 1464 Using the Domain Name System To Store Arbitrary String Attributes
3. RFC 4408 Sender Policy Framework (SPF) for Authorizing Use of Domains in E-Mail, Version 1
4. Google Apps SPF 紀錄設定
5. Microsoft 設定 DNS、MX 和 SPF 記錄和設定