$linuxjunkies
>

dnsmasq(8)

A lightweight DNS forwarder and DHCP server for small networks and embedded systems.

UbuntuDebianFedoraArch

Synopsis

dnsmasq [OPTION]...

Description

dnsmasq is a small DNS and DHCP server designed for networks with up to 1000 clients. It can act as a caching DNS forwarder, DHCP server, TFTP server, and router advertisement daemon. Commonly used in home networks, embedded devices, and containerized environments.

The daemon reads its configuration from /etc/dnsmasq.conf and processes command-line options. It forwards DNS queries to upstream resolvers, caches results locally, and optionally provides DHCP address assignment and DNS names for local machines.

dnsmasq is particularly popular in projects like OpenWrt, Docker networks, and as a lightweight alternative to BIND and ISC DHCP on resource-constrained systems.

Common options

FlagWhat it does
-c, --conf-file=FILEread configuration from FILE instead of /etc/dnsmasq.conf
-d, --no-daemonrun in foreground (do not fork into background)
-q, --log-querieslog all DNS queries and replies to syslog
-C, --conf-dir=DIRinclude all .conf files in DIR
--port=PORTlisten on PORT for DNS queries (default 53)
--address=/domain/IPreturn IP for specified domain (local DNS override)
--dhcp-range=RANGEenable DHCP with address range (e.g., 192.168.1.100,192.168.1.150)
--dhcp-option=OPTIONsend DHCP option to clients (e.g., gateway, DNS servers)
--server=SERVERset upstream DNS server (default uses /etc/resolv.conf)
--listen-address=ADDRlisten only on specified IP address
-u, --user=USERrun as unprivileged user after startup
-g, --group=GROUPrun as unprivileged group after startup

Examples

start dnsmasq in foreground with custom config file

dnsmasq -d -c /etc/dnsmasq.conf

resolve internal.local to 192.168.1.10 and log all DNS queries

dnsmasq --address=/internal.local/192.168.1.10 --log-queries

assign DHCP addresses in range with 12-hour leases, forward DNS to Google

dnsmasq --dhcp-range=192.168.1.100,192.168.1.200,12h --server=8.8.8.8

listen only on localhost port 5053 (useful for containers)

dnsmasq --port=5053 --listen-address=127.0.0.1

load all configs from directory and run in foreground for debugging

dnsmasq -C /etc/dnsmasq.d/ --no-daemon

reload configuration without restarting the daemon

killall -HUP dnsmasq

run as authoritative DHCP server with specified range

dnsmasq --dhcp-authoritative --dhcp-range=10.0.0.50,10.0.0.150

run in foreground as unprivileged dnsmasq user

dnsmasq --user=dnsmasq --group=dnsmasq -d

Related commands