Thursday, November 01, 2007

DNS cache issue

一般來說,DNS cache的值是以TTL來決定,而TTL也只對於DNS Server與Server之間才有用!如果對DNS Client來說它是不會去做DNS cache的,每查詢一次就update一次RR,但帽客今天發現到了一個非常有趣的現象,當你在DNS Client透過 host / nslookup /dig 來做名稱解析時,每問一次就update一次,這不難理解,合乎常規,但當你用ping時,此時就很怪異了,你會發現!被cache住了!比如我設定 server.example.com 對映到192.168.0.254 / 253, 當你用host查尋時,會每問一次就改變一次對映的IP,但ping確沒有唷!主要的原因是被nscd這隻daemon cache住囉!

nscd daemon就是用來設定DNS Client要cache住Name Server cache查尋的結果多久,這個跟TTL值一點關係也沒有,它也可以應用在LDAP,ypserver等等,以下是它的example config file:

enable-cache passwd yes
positive-time-to-live passwd 600
negative-time-to-live passwd 20
suggested-size passwd 211
check-files passwd yes
persistent passwd yes
shared passwd yes

enable-cache group yes
positive-time-to-live group 3600
negative-time-to-live group 60
suggested-size group 211
check-files group yes
persistent group yes
shared group yes

enable-cache hosts yes
positive-time-to-live hosts 5
negative-time-to-live hosts 0
suggested-size hosts 211
check-files hosts yes
persistent hosts no
shared hosts yes

hosts -> 就是針對DNS cache用的。 :)

No comments: