https://wiki.archlinux.org/api.php?action=feedcontributions&user=Tresende&feedformat=atomArchWiki - User contributions [en]2024-03-28T19:21:39ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Dnsmasq&diff=83285Dnsmasq2009-11-12T16:40:45Z<p>Tresende: /* Test DNS Caching */ removing "http://", see talk page</p>
<hr />
<div>[[Category:Networking (English)]]<br />
Dnsmasq is a DHCP server and Domain Name Server (DNS) cache program. It can be used to create a route to and from a LAN pc or/and as a DNS cache that will store Domain addresses that can help improve connection times to internet servers (e.g. queries to web servers). Dnsmasq is lightweight and designed for personal computer use or as a DHCP server on a network with less that 50 computers.<br />
<br />
==Installing==<br />
Dnsmasq is in the repository and can be added by:<br />
pacman -S dnsmasq<br />
<br />
==DHCP Server Setup==<br />
The dnsmasq configuration file needs to be configured. Edit {{Filename|/etc/dnsmasq.conf}}:<br />
<pre><br />
# Only listen to router LAN NIC, also opens up tcp/udp port 53 to localhost<br />
# and udp port 67 to world:<br />
interface=<LAN-NIC><br />
<br />
# dnsmasq will open tcp/udp port 53 and udp port 67 to world to help with<br />
# dynamic interfaces (assigning dynamic ips). Dnsmasq will discard world<br />
# requests to them, but the paranoid might like to close them and let the <br />
# kernel handle them:<br />
bind-interfaces<br />
<br />
# Dynamic range of IPs to make available to LAN pc<br />
dhcp-range=192.168.111.50,192.168.111.100,12h<br />
<br />
# If you’d like to have a static ip, bind the LAN computer's NIC MAC address:<br />
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.111.50<br />
</pre><br />
<br />
If you choose not to bind interfaces the domain port will need to be allowed in {{Filename|/etc/hosts.allow}}:<br />
domain ALL : ALLOW<br />
<br />
==DNS Cache Setup==<br />
If you're using dnsmasq on a router, dnsmasq is already setup to listen to DNS queries on localhost. If you're using dnsmasq on a client, edit {{Filename|/etc/dnsmasq}} and add:<br />
listen-address=127.0.0.1<br />
<br />
To be able to use DNS caching, the dhcp client must be directed to localhost for DNS queries. After you have configured you DHCP client, restart your network to have localhost (127.0.0.1) be prepended to the {{Filename|/etc/resolv.conf}} configuration.<br />
<br />
===dhcpcd===<br />
<br />
Dhcpcd has the ability to prepend or append nameservers to {{Filename|/etc/resolv.conf}} by creating {{Filename|/etc/resolv.conf.head}} and {{Filename|/etc/resolv.conf.tail}} respectively:<br />
echo "nameserver 127.0.0.1" > /etc/resolv.conf.head<br />
<br />
===dhclient===<br />
<br />
If you use dhclient, add to {{Filename|/etc/dhcp/dhclient.conf}}:<br />
prepend domain-name-servers 127.0.0.1;<br />
<br />
==Start the Daemon==<br />
Dnsmasq needs to run as a daemon. To start it:<br />
/etc/rc.d/dnsmasq start<br />
<br />
To have dnsmasq to load upon startup, add dnsmasq to your daemons array in {{Filename|/etc/rc.conf}}:<br />
DAEMONS=(network dnsmasq ...)<br />
<br />
To see if dnsmasq started properly, look at the log. Dnsmasq sends it's log to {{Filename|/var/log/messages.log}}.<br />
<br />
==Test DHCP Server==<br />
From the LAN client make sure you have the network set up to detect a route with DHCP and attempt to connect to the network.<br />
<br />
==Test DNS Caching==<br />
<br />
Do a DNS lookup and measure the time response: (dig is part of the dnsutils package)<br />
dig archlinux.org | grep "Query time"<br />
<br />
Try it again and compare the result.</div>Tresendehttps://wiki.archlinux.org/index.php?title=Talk:Dnsmasq&diff=83284Talk:Dnsmasq2009-11-12T16:39:48Z<p>Tresende: Created page with '== Testing without "http://" == In the test section it is recommended that the reader tries dig http://archlinux.org | grep "Query time" However, on both my systems running dnsm…'</p>
<hr />
<div>== Testing without "http://" ==<br />
In the test section it is recommended that the reader tries<br />
dig http://archlinux.org | grep "Query time"<br />
However, on both my systems running dnsmasq-2.50, querying anything prefixed with a "http://" causes dnsmasq to automatically forward the query and not to cache the reply:<br />
% dig "http://archlinux.org" | grep "Query time"; !#<br />
;; Query time: 493 msec<br />
;; Query time: 485 msec<br />
The daemon logs<br />
dnsmasq: forwarded query to 208.67.220.220<br />
dnsmasq: forwarded query to 208.67.220.220<br />
This might lead the reader to think dnsmasq is not working, when it actually works fine with:<br />
% dig "archlinux.org" | grep "Query time"; !#<br />
;; Query time: 508 msec<br />
;; Query time: 0 msec<br />
The daemon logs<br />
dnsmasq: query[A] archlinux.org from 127.0.0.1<br />
dnsmasq: forwarded archlinux.org to 208.67.222.222<br />
dnsmasq: forwarded archlinux.org to 208.67.220.220<br />
dnsmasq: reply archlinux.org is 66.211.214.131<br />
dnsmasq: query[A] archlinux.org from 127.0.0.1<br />
dnsmasq: cached archlinux.org is 66.211.214.131<br />
So, I'm removing the "http://" prefix. -- [[User:Tresende|Tresende]] 11:39, 12 November 2009 (EST)</div>Tresende