Hawkes Blog
Windows reboot | Linux be root
Hawkes Blog

dnsmasq a local dns/dhcp server on raspberry pi

Short How-To: dnsmasq on raspbian

install dnsmasq

apt-get update
apt-get install dnsmasq

my /etc/dnsmasq.conf

######### dns ########
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces
bogus-priv
# dont read resolv.conf   use the defined servers instead
no-resolv
server=8.8.8.8
server=8.8.4.4
# increase dns cache form 512 to 4096
cache-size=4096


######### dhcp ##########
# Add local-only domains here, queries in these domains are answered
# from /etc/hosts or DHCP only
local=/home/
# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
expand-hosts
# adds my localdomain to each dhcp host
domain=home
# my private dhcp range + subnetmask + 14d lease time
dhcp-range=192.168.178.10,192.168.178.99,255.255.255.0,14d
# set route to my local network router
dhcp-option=option:router,192.168.178.1
#windows 7 float fix
#http://brielle.sosdg.org/archives/522-Windows-7-flooding-DHCP-server-with-DHCPINFORM-messages.html
dhcp-option=252,"\n"

###### logging ############
# own logfile
log-facility=/var/log/dnsmasq.log
log-async
# log dhcp infos
log-dhcp
# debugging dns
#log-queries

/etc/hosts
with some static ips and their dns names i want to use
... snip

#IP               default name    alias1        alias2
#-----------------------------------------------------
192.168.178.1     speedport.ip    speedport
192.168.178.200   raspberrypione  rpone         rp1
192.168.178.245   htpc
192.168.178.253   wlan            ap            wrt

restart and testing

/etc/init.d/dnsmasq restart

first dhcp client connected

Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 available DHCP range: 192.168.178.10 -- 192.168.178.99
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 client provides name: kasekuchen
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 DHCPREQUEST(eth0) 192.168.178.60 28:e0:ff:ff:4d:90
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 tags: eth0
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 DHCPACK(eth0) 192.168.178.60 28:e0:ff:ff:4d:90 kasekuchen
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 requested options: 1:netmask, 3:router, 6:dns-server, 15:domain-name,
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 requested options: 119:domain-search, 252
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 next server: 192.168.178.200
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  1 option: 53 message-type  5
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option: 54 server-identifier  192.168.178.200
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option: 51 lease-time  1209600
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option: 58 T1  604800
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option: 59 T2  1058400
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option:  1 netmask  255.255.255.0
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option: 28 broadcast  192.168.178.255
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option:  6 dns-server  192.168.178.200
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option: 15 domain-name  home
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  1 option:252   0a
Apr  5 07:08:26 dnsmasq-dhcp[13501]: 3338073803 sent size:  4 option:  3 router  192.168.178.1

and the client could be resolved
with and without my local domain

# host kasekuchen.home
kasekuchen.home has address 192.168.178.60

# host kasekuchen
kasekuchen has address 192.168.178.60

host 192.168.178.60
60.178.168.192.in-addr.arpa domain name pointer kasekuchen.home.

if log-queries is enabled, you will see something like

Apr  4 21:06:58 dnsmasq[29519]: query[A] heise.de from 192.168.178.200
Apr  4 21:06:58 dnsmasq[29519]: forwarded heise.de to 8.8.8.8
Apr  4 21:06:58 dnsmasq[29519]: forwarded heise.de to 8.8.4.4
Apr  4 21:06:58 dnsmasq[29519]: reply heise.de is 193.99.144.80


dns stats

run:
killall -s USR1 dnsmasq

logfile output

Apr  4 21:40:38 dnsmasq[13501]: time 1365104438
Apr  4 21:40:38 dnsmasq[13501]: cache size 4096, 0/442 cache insertions re-used unexpired cache entries.
Apr  4 21:40:38 dnsmasq[13501]: queries forwarded 205, queries answered locally 43
Apr  4 21:40:38 dnsmasq[13501]: server 8.8.8.8#53: queries sent 120, retried or failed 1
Apr  4 21:40:38 dnsmasq[13501]: server 8.8.4.4#53: queries sent 109, retried or failed 0

MfG Hawkes


comments powered by Disqus