I tested this on debian wheezy and jessie and the OP confirmed it working on stretch as well. Stretch and jessie do use resolvconf, wheezy does not.
Just put all your fixed IP-addresses into the
/etc/hosts file local to the host running dnsmasq. You here add hosts with fixed addresses on your local network (domain
192.168.0.xxx in this example) or hosts you want to override locally for some reason or another:
# the local host
# provide fixed addresses used by dnsmasq for the local network
192.168.0.100 host0.local.net host0
192.168.0.101 host1.local.net host1
192.168.0.102 host2.local.net host2
# map a fancy service to the same address as above (e.g. on host2)
192.168.0.102 imap.local.net imap
192.168.0.102 mediaserver.local.net mediaserver
# overwrite an external host with address 22.214.171.124
# map unwanted external hosts to localhost
Dnsmasq reads the hosts file preferably to calling external resolvers. So all IPs in that file should be available before any of those hosts ask for a lease (or even runs). Make sure that the following is outcommented in your
# If you don't want dnsmasq to read /etc/hosts, uncomment the
# following line.
If your domain
local.net is not a publically available domain, put it into the following clause to prevent dnsmaq from querying upstream resolvers on non-existant domains:
# Add local-only domains here, queries in these domains are answered
# from /etc/hosts or DHCP only.
You might want to check out some more options regarding the
/etc/hosts file in the
/etc/dnsmasq.conf. The surrounding comments are quite informative.
Now you want to map your physical hosts to those IP-addresses. If not present, create the file
/etc/ethers. In this file you put the MAC-adresses of all hosts that should get a fixed IP-Address, followed by their appropriate dns-name:
You only need your physical hosts, not the additional service names you defined in the
/etc/hosts file above. Go back to your
/etc/dnsmasq.conf and check that reading of
/etc/ethers is enabled:
# If this line is uncommented, dnsmasq will read /etc/ethers and act
# on the ethernet-address/IP pairs found there just as if they had
# been given as --dhcp-host options. Useful if you keep
# MAC-address/host mappings there for other purposes.
Again there are more options regarding
/etc/ethers. You might want to skim through them, if you look for additional features.
As a third step, you must convince resolveconf to use the local dnsmasq as the first resolver. Otherwise the resolving won't work correctly for dynamic leases (not the fixed ones configured above) on the very host running dnsmasq. This is how my
/etc/resolvconf.conf looks like:
# Configuration for resolvconf(8)
# See resolvconf.conf(5) for details
# If you run a local name server, you should uncomment the below line and
# configure your subscribers configuration files below.
# Mirror the Debian package defaults for the below resolvers
# so that resolvconf integrates seemlessly.
The key line here is:
It tells the resolver to use the local host as a first resolver. The problem here is that dnsmasq uses resolvconf as well, to resolve unknown addresses. But don't worry, dnsmasq is smart enough to avoid calling itself in recursive loops.
One last (probably obvious) thing: If you define a dynamic IP range as well, e.g. for guests, mobile devices etc., make sure that it does not collide with the addresses given in
# Uncomment this to enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# this range must not include above addresses given in /etc/hosts
Now dnsmaq get's the IP-addresses from the
/etc/hosts file, regardless of an existing lease. DHCP requests resolve the MAC-adress using
/etc/ethers to a domain-name which again is resolved to an IP using
So you can configure hosts and ethers neatly in separate files and don't need to put every host into your
/etc/dnsmaq.conf with the