Differences between revisions 16 and 17
Revision 16 as of 2007-04-14 11:57:47
Size: 3183
Comment:
Revision 17 as of 2009-02-10 01:10:34
Size: 5504
Editor: ?Celejar
Comment:
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:

First things first, lets install the package:
First things first, let's install the package:
Line 11: Line 10:
Line 18: Line 16:
Line 21: Line 20:
Line 27: Line 25:
Line 33: Line 30:
Line 40: Line 36:
Line 44: Line 39:
Line 52: Line 46:
Line 61: Line 54:
Line 67: Line 59:

=== Local Caching ===
Using dnsmasq to cache DNS queries for the local machine is a bit tricky, since all DNS queries from the local machine need to go to dnsmasq, while as the same time, dnsmasq must be configured to forward all those queries to upstream DNS servers.

The [http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html dnsmasq man page] suggests the following:

In order to configure dnsmasq to act as cache for the host on which it is running, put "nameserver 127.0.0.1" in /etc/resolv.conf to force local processes to send queries to dnsmasq. 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. This second technique allows for dynamic update of the server addresses by PPP or DHCP.

There is, however, as simpler method; simply ensure that the machine's list of nameservers contains the line

{{{nameserver 127.0.0.1}}}

as the ''first'' line, followed by the upstream nameservers. dnsmasq is smart enough to ignore this line and forward all queries appropriately, while all other applications will send all their queries to dnsmasq.

Exaclty how to do this depends on the method(s) of network configuration in use. If you're manually hardcoding the nameservers (either in {{{/etc/resolv.conf}}} or elsewhere, such as a stanza in {{{/etc/network/interfaces}}} or in the Wicd GUI), then just add a reference to {{{127.0.0.1}}} as the first entry in the list. If you're using DHCP, then instruct your client to prepend {{{127.0.0.1}}} to the DHCP servers it receives. E.g., with dhclient, include the line

{{{
prepend domain-name-servers 127.0.0.1;
}}}

in the dhclient configuration file ({{{/etc/dhcp3/dhclient.conf}}}). [On my Sid system, the default configuration file shipped with the package contains that line, but commented out.]

Note that if you plan to use dnsmasq for the local system only, you should lock it down by adding the line

{{{
listen-address=127.0.0.1
}}}

to the dnsmasq configuration file ({{{/etc/dnsmasq.conf}}}).

Further reading:

 * http://ubuntu.wordpress.com/2006/08/02/local-dns-cache-for-faster-browsing/
 * http://news.softpedia.com/news/Local-DNS-Cache-for-Faster-Browsing-43341.shtml

Dnsmasq is a lightweight, easy to configure, DNS forwarder and DHCP server. It is designed to provide DNS and optionally, DHCP, to a small network. It can serve the names of local machines which are not in the global DNS. The DHCP server integrates with the DNS server and allows machines with DHCP-allocated addresses to appear in the DNS with names configured either in each host or in a central configuration file. Dnsmasq supports static and dynamic DHCP leases and BOOTP for network booting of diskless machines.

Basic DNS Setup

First things first, let's install the package:

aptitude update
aptitude install dnsmasq

If your goal was to set up a simple DNS server, you just succeeded. To test it, use your favorite DNS lookup tool pointed at localhost.

dig debian.org @localhost

or

nslookup debian.org localhost

By default, DNS is configured to forward all requests to your system's default DNS settings. In case you didn't know, these are stored in the /etc/resolv.conf file. (See ["HowTo/networking"] or type "man resolv.conf" for more details.

Now, if you want to add some names for your DNS server to resolve for your clients, simply add them to your /etc/hosts file.

Choosing Your Interfaces

One you will probably want to do is tell dnsmasq which ethernet interface it can and cannot listen on, as we really don't want it listening on the internet. Around line 69 of the /etc/dnsmasq.conf file, you will see:

#interface=

Uncomment the line and specify which ethernet interface(s) you want it server IPs to. For example, if I want it to listen on eth1 (my DMZ) and eth2 (my local network), then it should look like:

interface=eth1
interface=eth2

If I didn't edit this line, it would also listen on eth0, my internet connection. I personally wouldn't recommend this, as it gives those evil guys a few doors to try to break into.

Basic DHCP Setup

By default, DHCP is turned off. This is a good thing, as you could bring down whatever network you are connected to if you are not careful.

To enable it, there is at least one line will need to edit in the /etc/dnsmasq.conf file. Around line 143, you will see:

#dhcp-range=192.168.0.50,192.168.0.150,12h

To enable the DHCP server, you will need to give it a range of IP addresses to hand out. In the example above, this server would hand out 101 address starting at 192.168.0.50 and ending at 192.168.0.150. The last number is how long the DHCP leases are good for. In this example, they would be good for twelve hours.

Since I have two different networks that need DHCP, I'm going to change that line to:

dhcp-range=eth1,192.168.100.100,192.168.100.199,4h
dhcp-range=eth2,192.168.200.100,192.168.200.199,4h

Notice the "eth1" and "eth2" labels in the lines above? The aren't necessary, but definately help once you start playing with more advance configurations. It also helps me remember which range is which. Now restart your dnsmasq server, connect up a few clients, and see if they autoconfigure themselves.

/etc/init.d/dnsmasq restart

Local Caching

Using dnsmasq to cache DNS queries for the local machine is a bit tricky, since all DNS queries from the local machine need to go to dnsmasq, while as the same time, dnsmasq must be configured to forward all those queries to upstream DNS servers.

The [http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html dnsmasq man page] suggests the following:

In order to configure dnsmasq to act as cache for the host on which it is running, put "nameserver 127.0.0.1" in /etc/resolv.conf to force local processes to send queries to dnsmasq. 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. This second technique allows for dynamic update of the server addresses by PPP or DHCP.

There is, however, as simpler method; simply ensure that the machine's list of nameservers contains the line

nameserver 127.0.0.1

as the first line, followed by the upstream nameservers. dnsmasq is smart enough to ignore this line and forward all queries appropriately, while all other applications will send all their queries to dnsmasq.

Exaclty how to do this depends on the method(s) of network configuration in use. If you're manually hardcoding the nameservers (either in /etc/resolv.conf or elsewhere, such as a stanza in /etc/network/interfaces or in the Wicd GUI), then just add a reference to 127.0.0.1 as the first entry in the list. If you're using DHCP, then instruct your client to prepend 127.0.0.1 to the DHCP servers it receives. E.g., with dhclient, include the line

prepend domain-name-servers 127.0.0.1;

in the dhclient configuration file (/etc/dhcp3/dhclient.conf). [On my Sid system, the default configuration file shipped with the package contains that line, but commented out.]

Note that if you plan to use dnsmasq for the local system only, you should lock it down by adding the line

listen-address=127.0.0.1

to the dnsmasq configuration file (/etc/dnsmasq.conf).

Further reading: