Ubuntu打開網頁緩慢一直是一個比較嚴重的問題,和DNS的解析有着直接的關係,以前也寫過一個相關的文章:爲什麼個人Ubuntu瀏覽網頁這麼卡?替換ubuntu的dns不解釋!,但後來發現問題遠遠不止於這一個。html
ubuntu太純真了,沒有作假……windows在這個問題上作了緩存機制,即解析以後會把ip保存到本地作緩存,下次使用的時候就不用繼續解析了,而是從緩存裏面找。在ubuntu上用firefox或者google chrome訪問網頁時,常常會看見 正在鏈接:www.example.com
,正在解析:www.example.com
之類的東西,這就是問題所在了。linux
何須如此天真,效率最高才是最重要的。模仿windows的優化機制,作本地緩存,映射,訪問url時先映射本地緩存,找不到的狀況下再使用其餘DNS服務器。chrome
PDNSD
ubuntu
PDNSD(8) System Administration Commands PDNSD(8) NAME pdnsd - dns proxy daemon SYNOPSIS pdnsd [-h] [-V] [-s] [-d] [-g] [-t] [-p file] [-vn] [-mxx] [-c file] [-4] [-6] [-a] This man page is an extract of the documentation of pdnsd. For com‐ plete, current documentation, refer to the HTML (or plain text) docu‐ mentation (which you can find in the doc/ subdirectory of the source or in a standard documentation directory, typically /usr/share/doc/pdnsd/ if you are using a binary package). DESCRIPTION pdnsd is a IPv6 capable proxy domain name server (DNS) which saves the contents of its DNS cache to the disk on exit. OPTIONS -4 enables IPv4 support. IPv6 support is automatically dis‐ abled (should it be available). On by default.
1)安裝pdnsdwindows
sudo apt-get install pdnsd
緩存
sudo gedit /etc/pdnsd.conf
服務器
server { label=」resolvconf」; }
爲dom
server { label="resolvconf"; ip=223.5.5.5; ip=223.6.6.6; timeout=30; interval=30; uptest=ping; ping_timeout=50; purge_cache=off; }
sudo gedit /etc/default/pdnsd
工具
sudo gedit /etc/resolv.conf
測試
在最前面加入nameserver 127.0.0.1
sudo gedit /etc/dhcp/dhclient.conf
去掉#prepend domain-name-servers 127.0.0.1;
前面的#
sudo /etc/init.d/pdnsd start
dig www.baidu.com | grep time
結果展現:
rccoder@rccoder-Lenovo-IdeaPad-Y400:~$ dig baidu.com | grep time ;; Query time: 445 msec rccoder@rccoder-Lenovo-IdeaPad-Y400:~$ dig baidu.com | grep time ;; Query time: 0 msec rccoder@rccoder-Lenovo-IdeaPad-Y400:~$ dig baidu.com | grep time ;; Query time: 0 msec rccoder@rccoder-Lenovo-IdeaPad-Y400:~$ dig baidu.com | grep time ;; Query time: 0 msec
此文寫在大物考試以前,純屬做死……