来自Ubuntu:HervéFache的提示: 你可以在 UbuntuWirelessRouter 上找到更多关于怎么设置dnsmasq的信息。
首先我们要做一些看起来并不相关的事── 我们将创建一个新的resolv.conf文件并命名为 '/etc/nameservers'（文件名是任意的，但这各名字更好些）。
[email protected]:~$ host ns1.on.net ns1.on.net has address 18.104.22.168 [email protected]:~$ host ns2.on.net ns2.on.net has address 22.214.171.124 [email protected]:~$ host ns3.on.net ns3.on.net has address 126.96.36.199 [email protected]:~$ host ns4.on.net ns4.on.net has address 188.8.131.52
sudo nano /etc/nameservers
nameserver 184.108.40.206 nameserver 220.127.116.11 nameserver 18.104.22.168 nameserver 22.214.171.124
sudo apt-get update sudo apt-get install dnsmasq
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.
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/126.96.36.199
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