OpenWrt Forum Archive

Topic: static ip with dnsmasq

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

this is a quick guide to use dnsmasq's dhcp server to hand out static ip addresses based on mac or hostname.

for example if you have a laptop and you alternate between wireless and wired then you want it to get its ip based on hostname.

by default dnsmasq read /etc/dnsmasq.conf and that file overrides any command line options.

# file: /etc/dnsmasq.conf
#
# Interfaces to serve
#interface=lo
#interface=eth0
# Return this host as the MX mail handler
selfmx
localmx
#filter bogus win2k and winxp requests
filterwin2k
#dont take this one out or it will start 100 or so  dnsmasqs
no-daemon
#this will make it read /etc/ethers
read-ethers
#user=root
# DHCP range to handle out with a 48 hour lease.
#dhcp-range=192.168.10.0,192.168.10.20,192.168.10.200,255.255.255.0,48h
#only give out addresses to macs or hostnames in the list
dhcp-range=192.168.10.0,static,static,255.255.255.0,48h

# dnsmasq.leases is a plain text file 
dhcp-leasefile=/tmp/dnsmasq.leases

#these are set by default to the machine running dnsmasq
#dhcp-option=dns,192.168.10.1
#dhcp-option=subnet,255.255.255.0
#dhcp-option=router,192.168.10.1


domain=millernet.lnx
#
# Static DHCP hosts
#example: dhcp-host=00:03:1b:00:15:5a,netdj850,infinite
#example:dhcp-host=192.168.10.20,johnscomuter

/etc/ethers is just <mac><space or tab><ip>

alternatively, you can set up /etc/ethers using

<mac>:whitespace:<hostname>

and then setup your /etc/hosts file to map hostnames to ips.

this will not only assign the correct ip to each mac, but should also "do the right thing" as far as dns goes.

The discussion might have continued from here.