歡迎您光臨本站 註冊首頁

問 :為什麼需要 CNAME 記錄?

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

問 :為什麼需要 CNAME 記錄?

例如 :


dns    IN    A  192.168.1.1

mail  IN   CNAME dns.bob.com.


我們可以改成


dns    IN   A  192.168.1.1

mail  IN   A  192.168.1.1


當查詢 mail 時,第二種配置可以比第一種配置少一次 A query ,為什麼不一律使用 A 記錄來代替 CNAME 記錄呢?

1、這兩種做法有什麼區別嗎?

2、Canonical Name 和 Alias(es) 有什麼「本質上的區別」?

3、一台主機可以有多個 'Canonical Name' 嗎?

4、像上面的第2種配置,那個才是 'Canonical Name' ?

5、那種配置更適合於 Sendmail 呢?

[ 本帖最後由 ailms 於 2006-1-18 18:57 編輯 ]
《解決方案》

$TTL    86400
$ORIGIN siyongc.domain.
@ IN  SOA  rh71.siyongc.domain. root.rh71.siyongc.domain. (
2001111601 28800 14400 3600000 86400 )
       IN  NS     rh71.siyongc.domain.
       IN  NS     lp64.dmz.domain.
       IN  MX  10 rh71.siyongc.domain.
       IN  MX  20 lp64.dmz.domain.

;; -- default address
@       IN  A      192.168.100.23

;; -- linux servers --
rh71    IN  A      192.168.100.23
       IN  MX  0  rh71.siyongc.domain.
       IN  MX  10 lp64.dmz.domain.
       IN  HINFO  "Petium II 266""Redhat 7.1"
       IN  TXT    "The internet gateway."

mdk     IN  A      192.168.100.24
       IN  MX  0  mdk.siyongc.domain.
       IN  MX  10 rh71.siyongc.domain.
       IN  HINFO  "Petium II 266 dell""Mandrak 8.0"

;; -- Windows desktops --
acer    IN  A      192.168.100.20
       IN  MX  0  mdk.siyongc.domain.
       IN  HINFO  "Petium III 800 acer""Windows ME"

emilie  IN  A      192.168.100.11
       IN  MX  0  mdk.siyongc.domain.
       IN  HINFO  "Petium II 300""Windows 98"

;; -- cnames --
gw      IN  CNAME  rh71
www     IN  CNAME  rh71
ftp     IN  CNAME  rh71
mail    IN  CNAME  rh71



CNAME 也是一個常見的記錄類別,它是一個別名記錄( Canonical Name )。當 DNS 系統在查詢 CNAME 左面的名稱的時候,都會轉向 CNAME 右面的名稱再進行查詢,一直追蹤到最後的 PTR 或 A 名稱,成功查詢後才會做出回應,否則失敗。例如,在正解查詢中,一個 IP 通常(當然也有例外),只會對應一個 A 記錄,但 我們可以使用 CNAME 在 A 名稱之上賦予該 IP 更多的名稱。也就是說:所有關 於『www.siyongc.domain』、『ftp.siyongc.domain』、『mail.siyongc.domain』這些名稱的查詢,實際上都會再查詢一 次『rh71.siyongc.domain.』這個記錄,直到找到它的 IP 位址為止。有些朋友或許會設定多層的 CNAME 查詢,例如:


C    CNAME    B
B    CNAME    A

這樣的話,會一層一層的逐級 CNAME 下去... 但是,這很浪費 DNS 資源!因為每一個 CNAME 都一定會產生另外一個查詢 動作,如果層級越多,那就產生越多的重複查詢。所以,精明的 DNS 管理員,都會盡量的減少查詢次數的發生,他會將 CNAME 變成這樣子:


C    CNAME    A
B    CNAME    A

這樣就用心多了!

[ 本帖最後由 microchu 於 2006-1-18 21:45 編輯 ]
《解決方案》

樓上並沒有指出為什麼使用 CNAME 記錄

CNAME 記錄可以給一個IP多個名稱,A 記錄也可以。

為什麼早期在制定 DNS specification 時要定義一個 CNAME 類型,這才是我想知道的問題。

況且從表面上,CNAME 比 A 在效率上還低,為什麼還要用 CNAME 記錄呢?

[ 本帖最後由 ailms 於 2006-1-18 23:10 編輯 ]
《解決方案》

我也不很確定.
不過, 我覺得在正反解的一致上, 若都用 A 的話, 那也要想對多的 PTR .
若用 CNAME, 我會用一個 PTR 就好了.

不知其他前輩的見解如何?
《解決方案》

謝謝 netman 。的確書上有提到這個。我還是把原文貼出來比較好

[ 本帖最後由 ailms 於 2006-1-19 01:41 編輯 ]
《解決方案》

下面是 <<dns & bind>> 一書 4.2 節的部分


"Is it okay to use address records instead of CNAME records in all cases?" Well, using address records instead of CNAME records doesn't cause problems with most applications, since most applications care only about finding IP addresses. There is one application -- sendmail -- whose behavior changes, though. sendmail usually replaces aliases in mail headers with their canonical names; this canonicalization happens only if the names in the mail header have CNAME data associated with them.

If you don't use CNAME records for aliases, your sendmail will have to understand all the possible aliases your host might be known by, which will require extra sendmail configuration on your part


問 :第二段的「extra configuration」指的是什麼?


In addition to the problem with sendmail, users might be confused when they try to figure out the canonical name to enter in their .rhosts file. Looking up a name that has CNAME data leads them to the canonical name, whereas address data won't. In this case, users should instead be looking up the IP address to get the canonical name, as rlogind does, but users like these never seem to be on systems we administer


問 :最後一句怎麼理解?
《解決方案》

大家幫忙想一下啊!!
《解決方案》

顯然,當主機IP地址改變時,使用別名的只需修改一處,直接用A記錄的有多少名稱就修改多少個。

還有:

如下的zone(domain.tld)片斷:

foo  A 1.2.3.4
       MX  x.domain.tld.
bar  CNAME foo
        MX y.domain.tld.
x    A 1.2.3.5
y     A 1.2.3.6

當查詢bar.domain.tld.的MX記錄,就會得到 x A 1.2.3.5而不是 y A 1.2.3.6。記憶有點模糊了,不知道說的對不對。
《解決方案》

哦... 看來對 sendmail 的影響是有的.

若用 A RR 的話, 有 3 個 A 那 sendmail 就的設 3 個 local-host-names .
若用 2 CNAME + 1 A 的話, 那 sendmail 就設一個 local-host-names 就行了.

關於 sendmail 的 local 判斷, 請參考其他文件.
《解決方案》

原帖由 r2007 於 2006-1-19 14:29 發表
顯然,當主機IP地址改變時,使用別名的只需修改一處,直接用A記錄的有多少名稱就修改多少個。

還有:

如下的zone(domain.tld)片斷:

foo  A 1.2.3.4
       MX  x.domain.tld.
bar  CNAME foo
       ...

多謝r2007,但這個例子同上面的問題之間有什麼關係嗎?

[火星人 ] 問 :為什麼需要 CNAME 記錄?已經有1627次圍觀

http://coctec.com/docs/service/show-post-17247.html