Dnsmasq

From Omnia
Revision as of 03:18, 4 December 2018 by Kenneth (talk | contribs) (→‎Clear Lease)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Dnsmasq

Dnsmasq - http://www.thekelleys.org.uk/dnsmasq/doc.html

"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/TFTP/PXE for network booting of diskless machines."

Installation

Manual Installation

mkdir -p ~/.src ; cd ~/.src
git clone git://thekelleys.org.uk/dnsmasq.git
cd dnsmasq
git checkout v2.63
make clean
make
# installs only two files: 'dnsmasq' and the man page
# sudo make install  # installs to /usr/local/sbin/
sudo make install PREFIX=/opt/dnsmasq
# configuration files directory
# sudo cp dnsmasq.conf.example /etc/dnsmasq.conf
TFILE=`mktemp`
cat > $TFILE <<EOF

#local-ttl=300
expand-hosts
domain=qa.onpar.net
#log-queries
conf-dir=/etc/dnsmasq.d
#resolv-file=/etc/resolv.conf

EOF
sudo cp $TFILE /etc/dnsmasq.conf
rm -f $TFILE
sudo mkdir -p /etc/dnsmasq.d
# startup, or use the init.d script following
./dnsmasq -s `dnsdomainname`

Set the localhost or loop device on the server as a nameserver so it can use the DNS service that it is running. Add the nameserver line below to the top of the list in /etc/resolv.conf.

# /etc/resolv.conf:
nameserver  127.0.0.1

Add the IP address of the DNS host to the /etc/hosts for reverse DNS lookup.

# /etc/hosts
10.10.10.1    fw

See dnsmasq-init.d

RPM Forge

yum install dnsmasq --enablerepo=rpmforge
service dnsmasq start

Configuration

Easy: just put what you want in /etc/hosts, and restart dnsmasq

config files go in /etc/dnsmasq.d/

Sample /etc/dnsmasq.conf:

# Log the results of DNS queries handled by dnsmasq
# NOTE: logs are logged to daemon.debug, make sure syslog captures that level.
log-queries

# Local domain TTL
local-ttl=60

# Never pass short names to the upstream DNS servers. 
# If the name is not in the local /etc/hosts file then "not found" will be returned.
domain-needed

# All reverse IP (192.168.x.x) lookups that are not found in /etc/hosts will be
# returned as "no such domain" and not forwarded to the upstream servers.
bogus-priv

# We can see our local hosts via our home domain without having to
# repeatedly specify the domain in our /etc/hosts file.
expand-hosts

# Your local domain name. It will tell the DHCP server which host to give out IP addresses for.
domain=example.com

# The range of IPs that DHCP will serve: 192.168.0.20 to 192.168.0.50, with a lease time
# of 24 hours. The lease time is how long that IP will be linked to a host.
dhcp-range=192.168.0.20,192.168.0.50,24h

References:

dhcp

/etc/dnsmasq.d/dhcpd.conf

dhcp-range = eth0, 10.10.10.150, 10.10.10.199, 12h
dhcp-host = 00:10:99:31:b7:09, 10.10.10.7, voip, 24h
#dhcp-host=00:10:99:31:b7:09,10.10.10.7,24h  # voip
dhcp-host=00:0C:29:64:3D:2A,10.10.10.30,24h  # plex

References:

Clear Lease

Edit the lease file and restart dnsmasq:

# centos
/var/lib/dnsmasq/dnsmasq.leases
# ubuntu
/var/lib/misc/dnsmasq.leases

Issues

Dynamic DNS

Dynamic DNS is not supported externally. [1]

keywords