关于 CNAME 和 MX 冲突的问题解决

自己弄了个博客,然后还申请了个域名邮箱,但是使用裸域的时候 CNAME 和 MX 有冲突

➜  ~ dig awen.me

; <<>> DiG 9.9.7-P3 <<>> awen.me
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40667
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;awen.me.            IN    A

;; ANSWER SECTION:
awen.me.        575    IN    CNAME    awenme.b0.aicdn.com.
awenme.b0.aicdn.com.    248    IN    CNAME    nm.ctn.aicdn.com.
nm.ctn.aicdn.com.    166    IN    A    183.158.35.59

;; Query time: 56 msec
;; SERVER: 192.168.130.33#53(192.168.130.33)
;; WHEN: Fri Nov 10 16:03:12 CST 2017
;; MSG SIZE  rcvd: 106

➜  ~ dig awen.me MX

; <<>> DiG 9.9.7-P3 <<>> awen.me MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39112
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;awen.me.            IN    MX

;; ANSWER SECTION:
awen.me.        364    IN    CNAME    awenme.b0.aicdn.com.
awenme.b0.aicdn.com.    37    IN    CNAME    nm.ctn.aicdn.com.

;; AUTHORITY SECTION:
aicdn.com.        80    IN    SOA    ns1.ialloc.com. wtzhu182.163.com. 2015102101 3600 180 1209600 10800

;; Query time: 60 msec
;; SERVER: 192.168.130.33#53(192.168.130.33)
;; WHEN: Fri Nov 10 16:06:43 CST 2017
;; MSG SIZE  rcvd: 150

正常的邮件设置应该是这样

➜  ~ dig awen.me MX @114.114.114.114

; <<>> DiG 9.9.7-P3 <<>> awen.me MX @114.114.114.114
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3250
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;awen.me.            IN    MX

;; ANSWER SECTION:
awen.me.        600    IN    MX    10 mxbiz2.qq.com.
awen.me.        600    IN    MX    5 mxbiz1.qq.com.

;; Query time: 1086 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Fri Nov 10 16:07:30 CST 2017
;; MSG SIZE  rcvd: 77

解决办法

1.不要用裸域去做cname 解析,比如 awen.me 如果希望用 MX ,这个域名就不适合做 CNAME 解析
2.如果一定要用裸域,那也只能用 A 记录代替了。比如你用 CDN, 你可以拿到 CDN 的 IP 地址去做A记录解析,博主目前就是这么干的,缺点就是你需要针对不同运营商单独做A记录解析,而且 CDN 厂商可能会变更 IP 地址,要针对性的定期做替换。