个人工具

UbuntuHelp:Dnsmasq/zh-hans

来自Ubuntu中文

Daviszhao讨论 | 贡献2008年2月18日 (一) 14:18的版本 (新页面: {{Translation}}  {{From|https://help.ubuntu.com/community/Dnsmasq}}{{Translator|DavisZhao}} {{Languages|UbuntuHelp:Dnsmasq}} ==== Worth a note here: ==== I didn't use dnsmasq for i...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索
 


Worth a note here:

I didn't use dnsmasq for its dhcp - I used it for its dns. If dhcp help added would be A Good Thing, just let me know and I'll work it out :) Note from Ubuntu:HervéFache: you can find additional information on how to setup Dnsmasq on the UbuntuWirelessRouter page.

Preparation

First we are going to do something seemingly unrelated - we will make a new resolv.conf, but call it '/etc/nameservers' (the filename is arbitary, but seemed like a good choice). To do this, open a terminal, and run 'host' on your ISP's nameservers (mine are just below)

kgoetz@server:~$ host ns1.on.net
ns1.on.net has address 216.200.145.64
kgoetz@server:~$ host ns2.on.net
ns2.on.net has address 192.231.203.2
kgoetz@server:~$ host ns3.on.net
ns3.on.net has address 192.83.231.19
kgoetz@server:~$ host ns4.on.net
ns4.on.net has address 192.231.203.3

Now takes those lines, and add them to /etc/nameservers In a terminal

sudo nano /etc/nameservers

and in that file paste lines like to these, but using the output you got above.

nameserver 216.200.145.64
nameserver 192.231.203.2
nameserver 192.83.231.19
nameserver 192.231.203.3

If you dont have 4 thats fine, but more nameservers=less chance of failure. Having done that, we can move on to the actual install

Setup for dnsmasq

Like much of the Ubuntu packages, dnsmasq is in universe. Make sure its enabled, then run these commands

sudo apt-get update
sudo apt-get install dnsmasq

dnsmasq can be configured by editing the file

/etc/dnsmasq.conf

On the first page of options is one to "... filter useless windows-originated DNS requests which can trigger dial-on-demand links needlessly." If your in that situation, you might want to uncomment `filterwin2k`. How about making use of that file we made before? Uncomment the next option in the config file, and add your nameserver file to the end. `resolv-file=/etc/nameservers` Now we can be sure our nameserver is getting its dns from a trusted upstream source, and isnt going to go walkabout. Now we dont need to really worry about any settings untill we get down to "# Add domains which you want to force to an IP address here.". This one is fun, as we can point any dns request that comes in to any ip we want. In the mood to spread Ubuntu love? How about all requests to Microsoft.com go... astray? All we need is this option and an ip to redirect to.

address=/microsoft.com/82.211.81.158

With this line added to your dnsmasq, visits to Microsoft are a thing of the past. ( Its now pointing to ubuntulinux.org ;) ) Heres my current list, perhaps it will grow as needed:

address=/doubleclick.net/192.168.0.2
address=/googlesyndication.com/192.168.0.2
address=/google-analytics.com/192.168.0.2
address=/googleadservices.com/192.168.0.2
address=/decideinteractive.com/192.168.0.2

# Not blocking redirects (google.com -> google.com.au)
address=/google.com/216.239.39.104

Its a short list, mainly because with stuff like privoxy installed there isn't much call for a long one. This is just to weed out servers that privoxy misses, you dont want people visiting, or to put in simple redirects :) Heading down a few lines and we are looking at the interface line. This specifies which Ethernet device to bind to (`eth0`, `eth1` etc), or if you would rather you can use the bind-address just below it and bind it to an IP instead (`127.0.0.1`, `192.168.0.1`, 10.0.1.254`, etc).

Guess what? We just finished!

Save and exit the file, restart the daemon and you should be running.

sudo /etc/init.d/dnsmasq restart

The last thing that has to be done is editing your /etc/resolv.conf to point to the IP address of dnsmasq - this is the last option you set, so I hope you still remember it :) To your local dns cache address being overwritten in /etc/resolv.conf, you can add the line

prepend domain-name-servers 127.0.0.1

to /etc/dhcp3/dhclient.conf