Dnsmasq

From ArchWiki
Revision as of 03:25, 7 March 2009 by Gen2ly (Talk | contribs) (Created page with '=Description= Dnsmasq can be used on a to create a route to and from a LAN pc as a DHCP server and can also be configured as a DNS cacher. Dnsmasq is lightweight and designed f...')

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Description

Dnsmasq can be used on a to create a route to and from a LAN pc as a DHCP server and can also be configured as a DNS cacher. Dnsmasq is lightweight and designed for networks with less that 50 computers.

Install Dnsmasq

Dnsmasq is in the repository and can be added by:

pacman -S dnsmasq

Dnsmasq as a DHCP Server

The dnsmasq configuration file needs to be configured. Edit /etc/dnsmasq.conf:

# Only listen to router LAN NIC, also opens up tcp/udp port 53 to localhost
# and udp port 67 to world:
interface=<LAN-NIC>

# dnsmasq will open tcp/udp port 53 and udp port 67 to world to help with
# dynamic interfaces. Dnsmasq will discard world requests to them, but the 
# paranoid might like to close them and let the kernel handle them:
bind-interfaces

# Dynamic range of IPs to make available to LAN pc
dhcp-range=192.168.111.50,192.168.111.100,12h

# If you’d like to have a static ip, bind the LAN computer's NIC MAC address:
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.111.22

Dnsmasq as a DNS Cacher

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 /etc/dnsmasq and add:

listen-address=127.0.0.1

To be able to use DNS caching the dhcp client must be directed to localhost for DNS queries.

dhcpcd

Dhcpcd has the ability to prepend or append nameservers to /etc/resolv.conf by creating /etc/resolv.conf.head and /etc/resolv.conf.tail respectively:

echo "127.0.0.1" > /etc/resolv.conf.head

dhclient

If you use dhclient (NetworkManager uses dhclient) add to /etc/dhcp/dhclient.conf:

prepend domain-name-servers 127.0.0.1;

Start Dnsmasq

Dnsmasq runs as a daemon and can be started by:

/etc/rc.d/dnsmasq start

To add dnsmasq to run at boot add dnsmasq to your /etc/rc.conf:

DAEMONS=(network dnsmasq ...)

Test Dnsmasq

To see if dnsmasq is working as a DHCP server and/or a DNS cacher. Dnscache logs are sent to /var/log/messages.

Test Dnsmasq as a DHCP Server

From the LAN pc make sure you have the network to set up a route with dhcp and start the network.

Test Dnsmasq as a DNS Cacher

First restart the network so that localhost gets prepended to /etc/resolv.conf:

/etc/rc.d/network restart

Then do a DNS lookup (dig is part of dnsutils):

dig http://archlinux.org | grep "Query time"

Do it again to test for a DNS cache query.