|
|
|
Other Tips, Tricks and Tutorials |
|
Local DNS Cache for Faster BrowsingHow to setup a DNS forwarder for your computer or a small network. |
By Mihai Marinof, Linux Editor
2nd of January 2007, 09:12 GMT
Adjust text size: 
|
| |
Domain names have been made available to allow people to easily remember Internet sites, while the IP addresses enable computers to communicate and transfer data between them. A DNS server turns domain names into IP addresses that are usually provided by the same firm that provides the Internet access but you can, if you want, set up your own DNS server. This is, however, a more difficult process to complete. Moreover, if your ISP provides a rather slow DNS server, you can solve both problems with one solution: dnsmasq. dnsmasq is an easy to configure DNS forwarder, also known as a DNS cache application. This application will speed up the domain names look-up process with about 30-60ms per request by listening to the sent requests and saving the responses locally. This way, the next time a past request will be sent, dnsmasq will provide the response in a much shorter time than an usual DNS server.
dnsmasq can also be used for a small network. You can do this by using the computer's running dnsmasq IP as the DNS IP for all computers in the network.
Installing
dnsmasq is a rather popular application, so you might find it in repositories for many distributions. To install it, you should first try using your distribution's package manager. The package used for caching nameserver lookups is called simple, dnsmasq.
For Ubuntu:
CODE sudo apt-get install dnsmasq
(If you can't find it, make sure you have Universe in your repositories list.)
For Fedora:
- Login as root and type:
Others:
- Download the latest source package from SOFTPEDIA. - Uncompress the archive:
CODE tar xfz dnsmasq-version.tar.gz
- Compile and install dnsmasq:
CODE cd dnsmasq-version make install
Configuring
The basic configuration method that will quickly get dnsmasq up and running is:
- Open /etc/dnsmasq.conf with your favorite text editor. - Search for the line:
- And replace it with ( also remove the "#"):
CODE listen-address=127.0.0.1
(for a single computer)
CODE listen-address=write.computers.network.IP.here
(for a small network)
NOTE: The secret for DNS caching to work is the /etc/resolv.conf file which must contain a nameserver 127.0.0.1.or.network.IP. However, if you're computer gets its IP address using DHCP, the /etc/resolv.conf file will be overwritten and dnsmasq will no longer work properly. If you enter your network IP addresses manually, you can skip this next step.
To make sure that specific line will be automatically added to /etc/resolv.conf, you should:
- Ubuntu: Open the /etc/dhcp3/dhclient.conf file in your favorite text editor, remove all its contents and paste these directives: - Fedora: Create a new file called dhclient.conf in /etc/ directory, open it with your favorite directory and paste these directives:
CODE prepend domain-name-servers 127.0.0.1; request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, host-name; require subnet-mask, domain-name-servers; timeout 60; retry 60; reboot 10; select-timeout 5; initial-interval 2;
NOTE: If you're setting dnsmasq as a DNS server for a small network, you should replace the 127.0.0.1 IP with the computer's network IP.
Starting
- First of all, if you're not using DHCP or you do but your computer hasn't gotten a new lease since you've installed dnsmasq, you have to manually add the following line to /etc/resolv.conf
(again, replace this IP with the computer's network IP if you're running dnsmasq for a local network)
- Start dnsmasq (start this command with sudo for Ubuntu):
CODE /etc/init.d/dnsmasq restart
Testing
- Open a terminal and type this command for a domain name you haven't visited since dnsmasq's installation:
The first time you'll see something like: ;; Query time: 72 msec but if you run a dig again for the same domain name, you'll notice that the Query time has decreased to 1 or 2 msec. Multiply that difference by the number of websites you visit per day and you'll get an estimated speed improvement.
|
|
| Rating: |
|
Good (3.1/5) |
13 vote(s) so far |
|

|
|
|
User opinions: |
| Comment #1 by: TRON on 06 May 2008, 17:31 GMT | reply to this comment | This is by far the easiest guide for configuring a DNS cache on a Linux-based LAN server I've ever seen. The only thin I miss is a comment on how (end where exactly) dnsmasq caches the DNS resolve temporary data and which additional dnsmasq settings might be recommended. |
|
|
|