日期:2014-05-16  浏览次数:20858 次

linux下安装dns本地缓存
linux的版本是gentoo

写爬虫不用dns缓存很容易就
Error:6 - Couldn't resolve host 'rss.news.yahoo.com'

装一个缓存也很简单 摘抄如下 赞美D前辈
http://electrostorm.net/archive/2007/10/enabling-dns-cache-dnsmasq-gentoo
""""
# emerge -av dnsmasq

Then insert 'nameserver 127.0.0.1' into the first (important!) line in /etc/resolv.conf

nameserver 127.0.0.1
...

Then start dnsmasq
# /etc/init.d/dnsmasq start

You can test your local DNS cache by typing 这个工具在bind-tools中
dig google.de

Have a look at the query time (must be something higher than 50ms in most cases). Query google again.
Now that's amazing, isn't it? 0msec!

Let dnsmasq start at boot (otherwise you can't resolve any DNS names because you've edited the /etc/resolv.conf)
# rc-update add dnsmasq default

""""



~ $ sudo dig blogbus.com

; <<>> DiG 9.4.2-P2 <<>> blogbus.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38631
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 8

;; QUESTION SECTION:
;blogbus.com. IN A

;; ANSWER SECTION:
blogbus.com. 3600 IN A 210.51.44.249

;; AUTHORITY SECTION:
blogbus.com. 78 IN NS ns1.dns.com.cn.
blogbus.com. 78 IN NS ns2.dns.com.cn.

;; ADDITIONAL SECTION:
ns1.dns.com.cn. 667 IN A 124.42.122.8
ns1.dns.com.cn. 667 IN A 124.42.122.9
ns1.dns.com.cn. 667 IN A 122.70.138.5
ns1.dns.com.cn. 667 IN A 122.70.138.6
ns2.dns.com.cn. 2477 IN A 124.42.122.6
ns2.dns.com.cn. 2477 IN A 122.70.138.8
ns2.dns.com.cn. 2477 IN A 122.70.138.9
ns2.dns.com.cn. 2477 IN A 124.42.122.5

;; Query time: 9 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Apr 12 11:56:16 2009
;; MSG SIZE  rcvd: 219

~ $ sudo dig blogbus.com

; <<>> DiG 9.4.2-P2 <<>> blogbus.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2017
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;blogbus.com. IN A

;; ANSWER SECTION:
blogbus.com. 3597 IN A 210.51.44.249

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Apr 12 11:56:19 2009
;; MSG SIZE  rcvd: 45

~ $ sudo dig rss.news.yahoo.com

; <<>> DiG 9.4.2-P2 <<>> rss.news.yahoo.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13933
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 3, ADDITIONAL: 3

;; QUESTION SECTION:
;rss.news.yahoo.com. IN A

;; ANSWER SECTION:
rss.news.yahoo.com. 300 IN CNAME geoycs-p.gy1.b.yahoodns.net.
geoycs-p.gy1.b.yahoodns.net. 1476 IN CNAME l1.ycs.glb.cn.yahoo.com.
l1.ycs.glb.cn.yahoo.com. 186 IN A 203.209.246.249

;; AUTHORITY SECTION:
glb.cn.yahoo.com. 1853 IN NS gtm1.glb.cnh.yahoo.com.
glb.cn.yahoo.com. 1853 IN NS gtm1.glb.cn2.yahoo.com.
glb.cn.yahoo.com. 1853 IN NS gtm1.glb.cnb.yahoo.com.

;; ADDITIONAL SECTION:
gtm1.glb.cn2.yahoo.com. 6692 IN A 202.160.176.148
gtm1.glb.cnb.yahoo.com. 1651 IN A 202.165.98.16
gtm1.glb.cnh.yahoo.com. 6692 IN A 203.209.251.160

;; Query time: 7 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Apr 12 11:58:49 2009
;; MSG SIZE  rcvd: 250

~ $ sudo dig rss.news.yahoo.com

; <<>> DiG 9.4.2-P2 <<>> rss.news.yahoo.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY