Linux中通過緩衝DNS的解析來提高上網的響應速度!

來源:互聯網
上載者:User

這幾天好不容易細心了一下,發現在用Firefox瀏覽網頁的時候,一開始總會看到左下角有一行提示:

     “正在解析主機 xxx ...”   

看上去是等待DNS伺服器對網域名稱的解析,閑來無事,於是決定做個DNS Cache來提高上網速度!

找了找,發現有一個軟體符合要求:

[xport@ubuntu ~] $ apt-cache search "dns" | fgrep "cach"
dnsmasq - A small caching DNS proxy and DHCP server

去翻翻資料,設定的步驟如下:

1. 安裝dnsmasq:


# 安裝dnsmasq的軟體包
[xport@ubuntu ~] $ sudo apt-get install "dnsmasq"

2.設定dnsmasq接管原生DNS解析請求:


# 修改dnsmasq的設定檔
[xport@ubuntu ~] $ sudo gedit /etc/dnsmasq.conf

# 找到下面的內容,並進行修改
# If you want dnsmasq to listen for DHCP and DNS requests only on
# specified interfaces (and the loopback) give the name of the
# interface (eg eth0) here.
# Repeat the line for more than one interface.
# interface=
# Or you can specify which interface _not_ to listen on
# except-interface=
# Or which to listen on by address (remember to include 127.0.0.1 if
# you use this.)
listen-address=127.0.0.1  # 把這一行前面的注釋去掉

3.修改dhclient的配置:


# 修改dnsmasq的設定檔
[xport@ubuntu ~] $ sudo gedit /etc/dhcp3/dhclient.conf

# 找到下面的內容,並進行修改
prepend domain-name-servers 127.0.0.1; # 把這一行前面的注釋去掉
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, host-name,
        netbios-name-servers, netbios-scope;

4.修改resolv.conf的配置:


[xport@ubuntu ~] $ sudo gedit /etc/resolv.conf

# 注意:我的resolv.conf檔案的內容不會因為ADSL撥號而被改寫
# 因為dnsmasq會接管原生DNS解析請求,所以把127.0.0.1的地址放在最前面
nameserver 127.0.0.1
nameserver xxx.xxx.xxx.xxx
nameserver xxx.xxx.xxx.xxx
search lan

5. 重新開啟dnsmasq的服務:


[xport@ubuntu ~] $ sudo /etc/init.d/dnsmasq restart

6. 看看DNS的解析需要的時間,前後2次的資料對比:


[xport@ubuntu ~] $ dig baidu.com #首次執行
... 省略輸出資訊若干 ...
;; Query time: 8 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Feb 19 20:43:32 2007
;; MSG SIZE  rcvd: 229
 
[xport@ubuntu ~] $ dig baidu.com #再次運行
... 省略輸出資訊若干 ...
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Feb 19 20:45:27 2007
;; MSG SIZE  rcvd: 59

好了,打完收工~~~!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.