dproxy
dproxy is a caching name server for use on dial-up gateway machines designed to behave nicely when the gateway is not connected. This prevents programs like Netscape from locking up when the try and do dns lookups but there is no connection.
dproxy keeps it cache, in human readable form, on disk and so the cache is not lost when dproxy is restarted or stopped. Cache entries older that a set limit are flushed from the cache.
How dproxy works
+---------------------------------------+
/| /|
+---------+ +---------------------------------------+ |
/ /| | | Gateway machine | | +---------+
+---------+ | | | | | / /|
| | | | | +--------+ +-----------------+ | | +---------+ |
| | <--+--|-->| dproxy |---->| gethostbyname() |--|--->| DNS | |
| Local | | | | | | |<----| and | | | | Server | |
| host1 | | | | | +--------+ | gethostbyaddr() |<-|----| on | |
| |/ | | | | ^ +-----------------+ | | | Internet|/
+---------+ | | | V | | ^ | | +---------+
| | | +--------+ V | | |
+----------+ | | | | Cache | +------------------+ | |
/ /| | | | | file | | /etc/resolv.conf | | |
+----------+ | | | | +--------+ | or | | |
| | | | | |________________| /etc/hosts |_|_|
| | <--+ |/ +------------------+ |/
| Local | | | +---------------------------------------+
| host2 | | |
| |/ |
+----------+ |
~
dproxy doesn't query the upstream DNS server directly. Instead it calls the libc functions gethostbyname() and gethostbyaddr(). These libc calls usually look for the name in /etc/hosts first then if it is not found they query the DNS pointed to in /etc/resolv.conf
This method has the advantage of being able to use dproxy and the /etc/hosts file as the local DNS server for local names as well. The disadvantage is that the gateway machine doent not consult dproxy and so none of its own DNS queries get cached (not a real problem).
Configuring
Most configuration options can be set at both compile time and run time. dproxy can be made to generate its own configuration file, and when this is done the compile time defaults are put into this configuration file.
The compile time defaults are set acording to your distribution and can be found in both dproxy.h and the Makefile. The Makefile defaults over ride those in dproxy.h
Read the comments inside dproxy.conf to see the parameters that can be set.
Installing dproxy
First edit the Makefile to set your distribution type:
{RedHat, Debian, SuSE, Slackware} Note: Mandrake users should use the Red Hat settings.
Then build and install dproxy.
make
make install
You have to kill any existing named services on you gateway, then update your /etc/resolv.conf file to point to the nameservers you want dproxy to query. For example /etc/resolv.conf might look like this:
search myisp.com
nameserver 203.123.221.112
nameserver 203.123.221.113
Additionally you may want to add all the local machines to your /etc/hosts file.
The Makefile will have installed the init script in /etc/rc.d/init.d/ on
Red Hat machines.
Run "/sbin/chkconfig --del named" (to remove named service), then
"/sbin/chkconfig --level 345 dproxy reset" to let dproxy start in runlevels 3,
4 and 5 (this works for RedHat 6.1, untested on other distributions.)
Shut down your named (if running) with "/etc/rc.d/init.d/named stop".
Then start dproxy on the gateway machine. (using "/etc/rc.d/init.d/dproxy start".)
Next configure all the clients nameservers to point to the machine with dproxy on it.
Next time you start your connection dproxy will pass all requests onto the nameservers in /etc/resolv.conf and store the results of any queries before passing the result back to the requesting client.
dproxy will also return cached entries when offline, but this usually wont serve much purpose as the hosts will be unreachable anyway.
Acknowledgements
Two other open source programs helped my immensely to write this program even though I didn't end up using much code from them.
- Ethereal network analyser
The best packet sniffer / analyser out there. It actully disassembles the DNS packets and displays the contents. http://ethereal.zing.org
- Dents, dns server
Well written and documented code. Wish mine was as good.
Thanx to people involved in both those projects.
Individuals who have contributed bug fixes, patches, bugs reports, or thanks can be found in the CREDITS file.
Matthew Pratt <mattpratt@yahoo.com>
