適用版本:ubuntu fasty & hardy
安裝 dnsmasq
sudo apt-get install dnsmasq
配置 dnsmasq
看dnsmasq説明
man dnsmasq
其中有這麼一段描述: In order to configure dnsmasq to act as cache for the host on which it is running, put "HTTP://www.aliyun.com/z ixun/aggregation/11696.html">nameserver 127.0.0.1" in /etc/resolv.conf to force local processes to send queries to dnsm asq. Then either specify the upstream servers directly to dnsmasq using --server options or put their addresses real in another file, say /etc/resolv.dnsmasq and run dnsmasq with the -r /etc/resolv.dnsmasq option.
大意是如果想讓dnsmasq作為dns緩存,需要將「nameserver 127.0.0.1」放到/etc/resolv.conf檔中,通常是第一條非注釋語句,然後將真正的dns伺服器資訊放到另外一個檔中,如「/etc /resolv.dnsmasq」,最後執行命令:
dnsmasq -r /etc/resolv.dnsmasq
第一步按照説明文檔的提示,需要修改/etc/resolv.conf檔。 可以手動修改,如使用vi,可以將原有的內容全部注釋,然後在第一行寫上
nameserver 127.0.0.1;
也可以使用ubuntu的網路管理小程式「Network Manager」在桌面右上角有一個它的圖示,右鍵點擊該圖示,選擇「編輯連接」,選擇你所使用的連接,點擊編輯,在「IPv4設置」標籤的「DNS伺服器」輸入框中, 把原有的DNS伺服器刪除,輸入
127.0.0.1。
第二步在/etc目錄下新建resolv.dnsmasq檔。 檔的內容為DNS伺服器的位址,是真正的DNS伺服器,如我的檔內容是:
nameserver 210.47.0.1
nameserver 202.98.5.68
第三步可以不按説明文檔所說的執行「dnsmasq -r /etc/resolv.dnsmasq」命令,如果這樣,豈不是每次都得在命令列裡輸入,非常麻煩,當然,可以考慮把這個命令寫入「/etc/rc.local」檔中, 讓系統每次啟動時幫你運行。 我所使用的方法是編輯「/etc/dnsmasq.conf」檔。 找到下面這一項
#resolv-file=
用下面的一條語句替換
resolv-file=/etc/resolv.dnsmasq
其實也就是執行dnsmasq命令中-r參數後面的內容。
編輯 /etc/dhcp3/dhclient.conf
找到下面這一項
#prepend domain-name-servers 127.0.0.1;