DNSMASQ(8)

๐Ÿ‘‘ DNSMASQ(8) โ€” bestie edition ๐Ÿ‘‘

okay so this is the DNSMASQ(8) page from the System Manager's Manual, and we're gonna get you fluent in it. no cap. ๐Ÿ’–


โœจ NAME โœจ

dnsmasq โ€” a lightweight DHCP and caching DNS server. iconic behavior ๐Ÿฆ‹

๐ŸŒธ SYNOPSIS ๐ŸŒธ

dnsmasq [OPTION]...

๐Ÿ’… DESCRIPTION ๐Ÿ’…

dnsmasq is a lightweight DNS, TFTP, PXE, router advertisement and DHCP server. It is intended to provide coupled DNS and DHCP service to a LAN.

Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. It loads the contents of /etc/hosts so that local hostnames which do not appear in the global DNS can be resolved and also answers DNS queries for DHCP configured hosts. It can also act as the authoritative DNS server for one or more domains, allowing local names to appear in the global DNS. It can be configured to do DNSSEC validation.

The dnsmasq DHCP server supports static address assignments and multiple networks. It automatically sends a sensible default set of DHCP options, and can be configured to send any desired set of DHCP options, including vendor-encapsulated options. It includes a secure, read-only, TFTP server to allow net/PXE boot of DHCP hosts and also supports BOOTP. The PXE support is full featured, and includes a proxy mode which supplies PXE information to clients whilst DHCP address allocation is done by another server.

The dnsmasq DHCPv6 server provides the same set of features as the DHCPv4 server, and in addition, it includes router advertisements and a neat feature which allows naming for clients which use DHCPv4 and stateless autoconfiguration only for IPv6 configuration. There is support for doing address allocation (both DHCPv6 and RA) from subnets which are dynamically delegated via DHCPv6 prefix delegation.

Dnsmasq is coded with small embedded systems in mind. It aims for the smallest possible memory footprint compatible with the supported functions, and allows unneeded functions to be omitted from the compiled binary.

โœจ OPTIONS โœจ

okay before we dive in: in general, missing parameters are allowed and they switch off functions. for instance, --pid-file disables writing a PID file. on BSD, unless the GNU getopt library is linked, the long form of the options does not work on the command line; it is still recognised in the configuration file.

  • --test โ€” read and syntax check configuration file(s). exit with code 0 if all is OK, or a non-zero code otherwise. do not start up dnsmasq.
  • -w, --help โ€” display all command-line options. --help dhcp will display known DHCPv4 configuration options, and --help dhcp6 will display DHCPv6 options.
  • -h, --no-hosts โ€” don't read the hostnames in /etc/hosts.
  • -H, --addn-hosts=<file> โ€” additional hosts file. read the specified file as well as /etc/hosts. if --no-hosts is given, read only the specified file. this option may be repeated for more than one additional hosts file. if a directory is given, then read all the files contained in that directory in alphabetical order.
  • --hostsdir=<path> โ€” read all the hosts files contained in the directory. new or changed files are read automatically and modified and deleted files have removed records automatically deleted.
  • -E, --expand-hosts โ€” add the domain to simple names (without a period) in /etc/hosts in the same way as for DHCP-derived names. note that this does not apply to domain names in cnames, PTR records, TXT records etc.
  • -T, --local-ttl=<time> โ€” when replying with information from /etc/hosts or configuration or the DHCP leases file dnsmasq by default sets the time-to-live field to zero, meaning that the requester should not itself cache the information. this is the correct thing to do in almost all situations. this option allows a time-to-live (in seconds) to be given for these replies. this will reduce the load on the server at the expense of clients using stale data under some circumstances.
  • --dhcp-ttl=<time> โ€” as for --local-ttl, but affects only replies with information from DHCP leases. if both are given, --dhcp-ttl applies for DHCP information, and --local-ttl for others. setting this to zero eliminates the effect of --local-ttl for DHCP.
  • --neg-ttl=<time> โ€” negative replies from upstream servers normally contain time-to-live information in SOA records which dnsmasq uses for caching. if the replies from upstream servers omit this information, dnsmasq does not cache the reply. this option gives a default value for time-to-live (in seconds) which dnsmasq uses to cache negative replies even in the absence of an SOA record.
  • --max-ttl=<time> โ€” set a maximum TTL value that will be handed out to clients. the specified maximum TTL will be given to clients instead of the true TTL value if it is lower. the true TTL value is however kept in the cache to avoid flooding the upstream DNS servers.
  • --max-cache-ttl=<time> โ€” set a maximum TTL value for entries in the cache.
  • --min-cache-ttl=<time> โ€” extend short TTL values to the time given when caching them. note that artificially extending TTL values is in general a bad idea, do not do it unless you have a good reason, and understand what you are doing. Dnsmasq limits the value of this option to one hour, unless recompiled.
  • --auth-ttl=<time> โ€” set the TTL value returned in answers from the authoritative server.
  • --fast-dns-retry=[<initial retry delay in ms>[,<time to continue retries in ms>]] โ€” under normal circumstances, dnsmasq relies on DNS clients to do retries; it does not generate timeouts itself. setting this option instructs dnsmasq to generate its own retries starting after a delay which defaults to 1000ms. if the second parameter is given this controls how long the retries will continue for otherwise this defaults to 10000ms. retries are repeated with exponential backoff. using this option increases memory usage and network bandwidth. if not otherwise configured, this option is activated with the default parameters when --dnssec is set.
  • -k, --keep-in-foreground โ€” do not go into the background at startup but otherwise run as normal. this is intended for use when dnsmasq is run under daemontools or launchd.
  • -d, --no-daemon โ€” debug mode: don't fork to the background, don't write a pid file, don't change user id, generate a complete cache dump on receipt on SIGUSR1, log to stderr as well as syslog, don't fork new processes to handle TCP queries. note that this option is for use in debugging only, to stop dnsmasq daemonising in production, use --keep-in-foreground.
  • -q, --log-queries โ€” log the results of DNS queries handled by dnsmasq. enable a full cache dump on receipt of SIGUSR1. if the argument "extra" is supplied, ie --log-queries=extra then the log has extra information at the start of each line. this consists of a serial number which ties together the log lines associated with an individual query, and the IP address of the requestor. if the argument "proto" is supplied, this shows everything that "extra" does and also the network protocol used to communicate the queries. logging of only queries to the authoritative server can be configured with --log-queries=auth and logging only failed replies (Error, NXDOMAIN or NODATA) can be configured with --log-queries=only_failed
  • -8, --log-facility=<facility> โ€” set the facility to which dnsmasq will send syslog entries, this defaults to DAEMON, and to LOCAL0 when debug mode is in operation. if the facility given contains at least one / character, it is taken to be a filename, and dnsmasq logs to the given file, instead of syslog. if the facility is '-' then dnsmasq logs to stderr. (Errors whilst reading configuration will still go to syslog, but all output from a successful startup, and all output whilst running, will go exclusively to the file.) when logging to a file, dnsmasq will close and reopen the file when it receives SIGUSR2. this allows the log file to be rotated without stopping dnsmasq.
  • --log-debug โ€” enable extra logging intended for debugging rather than information.
  • --log-malloc โ€” enable logging of memory allocation and release, for debugging.
  • --log-async[=<lines>] โ€” enable asynchronous logging and optionally set the limit on the number of lines which will be queued by dnsmasq when writing to the syslog is slow. Dnsmasq can log asynchronously: this allows it to continue functioning without being blocked by syslog, and allows syslog to use dnsmasq for DNS queries without risking deadlock. if the queue of log-lines becomes full, dnsmasq will log the overflow, and the number of messages lost. the default queue length is 5, a sane value would be 5-25, and a maximum limit of 100 is imposed.
  • -x, --pid-file=<path> โ€” specify an alternate path for dnsmasq to record its process-id in. normally /var/run/dnsmasq.pid.
  • -u, --user=<username> โ€” specify the userid to which dnsmasq will change after startup. Dnsmasq must normally be started as root, but it will drop root privileges after startup by changing id to another user. normally this user is "nobody" but that can be over-ridden with this switch.
  • -g, --group=<groupname> โ€” specify the group which dnsmasq will run as. the default is "dip", if available, to facilitate access to /etc/ppp/resolv.conf which is not normally world readable.
  • -v, --version โ€” print the version number.
  • -p, --port=<port> โ€” listen on <port> instead of the standard DNS port (53). setting this to zero completely disables DNS function, leaving only DHCP and/or TFTP.
  • -P, --edns-packet-max=<size> โ€” specify the largest EDNS.0 UDP packet which is supported by the DNS forwarder. defaults to 1232, which is the recommended size following the DNS flag day in 2020. only increase if you know what you are doing.
  • -Q, --query-port=<query_port> โ€” bestie, this one makes dnsmasq send its outbound DNS queries from one specific UDP port (<query_port>) and listen for the replies right there too, instead of doing the random-port thing. It's a whole vibe, but...
Lowkey important: this makes dnsmasq less secure against DNS spoofing attacks. It might be faster and use fewer resources though. Balance, queen. โœจ

Set it to zero and dnsmasq uses a single port handed to it by the OS โ€” which was literally the default behaviour in versions before 2.43. History lesson, periodt. ๐Ÿ’…

  • --port-limit=<#ports> โ€” normally, when dnsmasq sends a query over random ports to multiple upstream servers, or retries a query, it reuses one random port for all of the tries/retries. This option lets it use a bigger number of ports instead, which can be more robust in certain network setups. But ngl โ€” bumping this above two or three has security and resource implications, so only do it if you actually understand those. ๐ŸŒธ
  • --min-port=<port> โ€” sets a floor: don't use any port below <port> as the source for outbound DNS queries. Dnsmasq picks random source ports; give it this option and the ports will always land above what you specified. Chef's kiss for systems sitting behind firewalls. ๐Ÿ”ฅ If you don't set it, it defaults to 1024.
  • --max-port=<port> โ€” the ceiling version: use ports lower than <port> as the source for outbound DNS queries. Same deal โ€” dnsmasq picks random source ports, and with this option they'll always be below your number. Again, iconic for systems behind firewalls. ๐ŸŽ€

  • -i, --interface=<interface name> โ€” listen only on the interface(s) you name. When you use --interface, dnsmasq automatically adds the loopback (local) interface to the list. And if you give neither --interface nor --listen-address, dnsmasq just listens on all available interfaces, minus whatever you listed in --except-interface. ๐Ÿ’š

On Linux, when --bind-interfaces or --bind-dynamic is in effect, it checks IP alias interface labels (like "eth1:0") rather than interface names. In the degenerate case where an interface has just one address, that's the same thing as using the name โ€” but when an interface has multiple addresses, this lets you control which of those addresses get accepted. ๐Ÿ‘‘

Same effect is achievable in default mode with --listen-address, fyi. And you can use a simple wildcard โ€” just a trailing * โ€” in both --interface and --except-interface. ๐Ÿฆ‹

  • -I, --except-interface=<interface name> โ€” do not listen on that interface. Note that the order of --listen-address, --interface and --except-interface options doesn't matter at all, and --except-interface always overrides the others. The comments about interface labels for --listen-address apply here too. ๐Ÿซถ
  • --auth-server=<domain>,[<interface>|<ip-address>...] โ€” turns on DNS authoritative mode for queries that arrive at an interface or address. Heads up: that interface or address doesn't need to be mentioned in --interface or --listen-address config โ€” in fact --auth-server overrides those and serves a completely different DNS service on the interface you picked. ๐Ÿ˜ญ

The <domain> is the "glue record". It should resolve in the global DNS to an A and/or AAAA record pointing at the address dnsmasq is listening on. When you specify an interface, you can qualify it with /4 or /6 to only use the IPv4 or IPv6 addresses associated with that interface. ๐ŸŒˆ

And since any defined authoritative zones are also available as part of the normal recursive DNS service dnsmasq provides, it can totally make sense to declare an --auth-server with no interfaces or address at all, and just name the primary external nameserver. iykyk. ๐Ÿ’œ

  • --local-service[=net|host] โ€” no parameter (or the net parameter) restricts service to the connected network: only accept DNS queries from hosts whose address is on a local subnet, i.e. a subnet that has an interface existing on the server. With the host parameter, it listens only on the lo interface and accepts queries from localhost only. ๐Ÿ 

This option only does anything if there are no --interface, --except-interface, --listen-address or --auth-server options. It's meant to be set as a default on installation โ€” so unconfigured installs are still useful while staying safe from being used for DNS amplification attacks. Protecting the people, fr fr. ๐Ÿ›ก๏ธ

  • -2, --no-dhcp-interface=<interface name> โ€” do not provide DHCP, TFTP or router advertisement on that interface. But DNS service? Still on. Best of both. โœจ
  • --no-dhcpv4-interface=<interface name> โ€” disable only IPv4 DHCP on the named interface.
  • --no-dhcpv6-interface=<interface name> โ€” disable IPv6 DHCP and router advertisement on the named interface.
  • -a, --listen-address=<ipaddr> โ€” listen on the IP address(es) you give. You can give both --interface and --listen-address, and then the set of both interfaces and addresses is used. ๐Ÿ’…
Careful though โ€” if you give no --interface option but you do give --listen-address, dnsmasq will not automatically listen on the loopback interface. To get that, you have to explicitly list 127.0.0.1 as a --listen-address. ๐Ÿšจ
  • -z, --bind-interfaces โ€” on systems that support it, dnsmasq binds the wildcard address even when it's only listening on some interfaces, then quietly discards requests it shouldn't be answering. The upshot: it keeps working even when interfaces come and go and change address. This option instead forces dnsmasq to really bind only the interfaces it's listening on. ๐ŸŽฏ

About the only time that's useful is when you're running another nameserver (or another dnsmasq instance) on the same machine. Setting this also enables multiple dnsmasq instances that provide DHCP service to run on the same machine. Iconic multitasking. ๐Ÿ‘‘

  • --bind-dynamic โ€” turns on a network mode that's a hybrid between --bind-interfaces and the default. Dnsmasq binds the address of individual interfaces, which allows multiple dnsmasq instances โ€” but if new interfaces or addresses show up, it automatically listens on those too (subject to any access-control config). That makes dynamically created interfaces behave just like they do in the default mode. ๐Ÿฆ‹

Implementing this needs non-standard networking APIs and it's only available under Linux. On other platforms it falls back to --bind-interfaces mode. No cap.

  • -y, --localise-queries โ€” returns answers to DNS queries from /etc/hosts, --interface-name and --dynamic-host based on which interface the query came in on. So if a name has more than one address and at least one of those addresses is on the same subnet as the interface the query was sent to, it returns only the address(es) on that subnet โ€” and returns all the available addresses otherwise. ๐ŸŒธ

This lets a server have multiple addresses in /etc/hosts, one per interface, and hosts get the correct one based on which network they're attached to. Currently limited to IPv4 only, just so you know.

  • -b, --bogus-priv โ€” bogus private reverse lookups, hence the name. ๐Ÿ’€ All reverse lookups for private IP ranges (like 192.168.x.x, etc.) that aren't found in /etc/hosts or the DHCP leases file get answered with "no such domain" instead of being forwarded upstream. The set of prefixes affected is the list given in RFC6303, for both IPv4 and IPv6.

Turning this on also subtly alters DNSSEC validation for reverse lookups in the private ranges โ€” such that a non-secure DS record is accepted as proof that the range isn't signed. This works around behaviour from the public DNS services that seem not to return validated proof-of-non-existence for DS records in those domains. Messy, but handled. ๐Ÿ™ˆ

  • -V, --alias=[<old-ip>]|[<start-ip>-<end-ip>],<new-ip>[,<mask>] โ€” modify IPv4 addresses coming back from upstream nameservers: old-ip gets replaced by new-ip. If you give the optional mask, then any address matching the masked old-ip gets rewritten. So for example:
--alias=1.2.3.0,6.7.8.0,255.255.255.0

maps 1.2.3.56 to 6.7.8.56 and 1.2.3.67 to 6.7.8.67. This is what Cisco PIX routers call "DNS doctoring". ๐Ÿฉบ

If you give the old IP as a range, then only addresses inside the range get rewritten rather than a whole subnet. So:

--alias=192.168.0.10-192.168.0.40,10.0.0.0,255.255.255.0

maps 192.168.0.10->192.168.0.40 to 10.0.0.10->10.0.0.40. Math, but make it fashion. ๐Ÿ’…

  • -B, --bogus-nxdomain=<ipaddr>[/prefix] โ€” transform replies containing the specified address or subnet into "No such domain" replies. IPv4 and IPv6 both supported. ๐ŸŒˆ

This exists to counteract a devious move Verisign pulled in September 2003, when they started returning the address of an advertising web page in response to queries for unregistered names instead of the correct NXDOMAIN response. Rude! ๐Ÿ˜ค This option tells dnsmasq to fake the correct response when it catches that behaviour. As at Sept 2003, the IP address Verisign was returning is 64.94.110.11.

  • --ignore-address=<ipaddr>[/prefix] โ€” ignore replies to A or AAAA queries that include the specified address or subnet. No error gets generated โ€” dnsmasq just keeps listening for another reply. ๐Ÿ‘‚

Useful for defeating blocking strategies that rely on quickly supplying a forged answer for a certain domain before the correct answer can arrive. Sneaky-sneaky, we see you. ๐Ÿ’€

  • -f, --filterwin2k โ€” later Windows versions make periodic DNS requests that get no sensible answers from the public DNS and can cause problems by triggering dial-on-demand links. This flag turns on an option to filter such requests. ๐Ÿ˜ญ The blocked requests are: records of type ANY where the requested name has underscores (to catch LDAP requests), plus all records of types SOA and SRV.
  • --filter-A โ€” remove A records from answers. No IPv4 addresses will be returned. โœ‚๏ธ
  • --filter-AAAA โ€” remove AAAA records from answers. No IPv6 addresses will be returned. โœ‚๏ธโœจ
  • --filter-rr=<rrtype>[,<rrtype>...] โ€” okay so bestie, this one lets you yeet specific record types out of the answers ๐Ÿ’…. You list the <rrtype>(s) comma-separated. But plot twist: --filter-rr=ANY has a special meaning โ€” it filters replies to queries for type ANY. It removes everything except A, AAAA, MX, and CNAME records. Why? Because ANY queries with forged source addresses are a whole mood for DNS amplification attacks (the replies can be huge ๐Ÿ˜ญ), so this defangs those attacks while still supporting the one remaining possible use of ANY queries. See RFC 8482 para 4.3 for the details, iykyk.
  • --cache-rr=<rrtype>[,<rrtype>...] โ€” By default, dnsmasq caches A, AAAA, CNAME, and SRV DNS record types. This option adds other record types to the cache. The RR-type can be given as a name such as TXT or MX, or a decimal number. A single --cache-rr option can take a comma-separated list of RR-types, and more than one --cache-rr option is allowed. Use --cache-rr=ANY to enable caching for all RR-types. slay โœจ.
  • -r, --resolv-file=<file> โ€” Read the IP addresses of the upstream nameservers from <file>, instead of /etc/resolv.conf. For the format of this file see resolv.conf(5). The only lines relevant to dnsmasq are nameserver ones. Dnsmasq can be told to poll more than one resolv.conf file; the first file name specified overrides the default, subsequent ones add to the list. This is only allowed when polling; the file with the currently latest modification time is the one used. ๐Ÿซถ
  • -R, --no-resolv โ€” Don't read /etc/resolv.conf. Get upstream servers only from the command line or the dnsmasq configuration file. no cap.
  • -1, --enable-dbus[=<service-name>] โ€” Allow dnsmasq configuration to be updated via DBus method calls. The configuration which can be changed is upstream DNS servers (and corresponding domains) and cache clear. Requires that dnsmasq has been built with DBus support. If the service name is given, dnsmasq provides service at that name, rather than the default which is uk.org.thekelleys.dnsmasq. ๐Ÿ’…
  • --enable-ubus[=<service-name>] โ€” Enable dnsmasq UBus interface. It sends notifications via UBus on DHCPACK and DHCPRELEASE events. Furthermore it offers metrics and allows configuration of Linux connection track mark based filtering. When DNS query filtering based on Linux connection track marks is enabled, UBus notifications are generated for each resolved or filtered DNS query. Requires that dnsmasq has been built with UBus support. If the service name is given, dnsmasq provides service at that namespace, rather than the default which is dnsmasq. โœจ
  • -o, --strict-order โ€” By default, dnsmasq will send queries to any of the upstream servers it knows about and tries to favour servers that are known to be up. Setting this flag forces dnsmasq to try each query with each server strictly in the order they appear in /etc/resolv.conf. ๐Ÿ‘‘
  • --all-servers โ€” By default, when dnsmasq has more than one upstream server available, it will send queries to just one server. Setting this flag forces dnsmasq to send all queries to all available servers. The reply from the server which answers first will be returned to the original requester. ๐Ÿ”ฅ
  • --dns-loop-detect โ€” Enable code to detect DNS forwarding loops; ie the situation where a query sent to one of the upstream servers eventually returns as a new query to the dnsmasq instance. The process works by generating TXT queries of the form <hex>.test and sending them to each upstream server. The <hex> is a UID which encodes the instance of dnsmasq sending the query and the upstream server to which it was sent. If the query returns to the server which sent it, then the upstream server through which it was sent is disabled and this event is logged. Each time the set of upstream servers changes, the test is re-run on all of them, including ones which were previously disabled. ๐Ÿฆ‹
  • --stop-dns-rebind โ€” Reject (and log) addresses from upstream nameservers which are in the private ranges. This blocks an attack where a browser behind a firewall is used to probe machines on the local network. For IPv6, the private range covers the IPv4-mapped addresses in private space plus all link-local (LL) and site-local (ULA) addresses. ๐Ÿ›ก๏ธ
  • --rebind-localhost-ok โ€” Exempt 127.0.0.0/8 and ::1 from rebinding checks. This address range is returned by realtime black hole servers, so blocking it may disable these services. ๐Ÿ’–
  • --rebind-domain-ok=[<domain>]|[[/<domain>/[<domain>/] โ€” Do not detect and block dns-rebind on queries to these domains. The argument may be either a single domain, or multiple domains surrounded by /, like the --server syntax, eg. --rebind-domain-ok=/domain1/domain2/domain3/. ๐ŸŒธ
  • -n, --no-poll โ€” Don't poll /etc/resolv.conf for changes. ๐Ÿ’€
  • --clear-on-reload โ€” Whenever /etc/resolv.conf is re-read or the upstream servers are set via DBus, clear the DNS cache. This is useful when new nameservers may have different data than that held in cache. ๐Ÿงš
  • -D, --domain-needed โ€” Tells dnsmasq to never forward A or AAAA queries for plain names, without dots or domain parts, to upstream nameservers. If the name is not known from /etc/hosts or DHCP then a "not found" answer is returned. ๐ŸŽ€
  • -S, --local, --server=[/[<domain>]/[domain/]][<server>[#<port>]][@<interface>][@<source-ip>[#<port>]] โ€” Specify upstream servers directly. Setting this flag does not suppress reading of /etc/resolv.conf, use --no-resolv to do that.
    • If one or more optional domains are given, that server is used only for those domains and they are queried only using the specified server. This is intended for private nameservers: if you have a nameserver on your network which deals with names of the form xxx.internal.thekelleys.org.uk at 192.168.1.1 then giving the flag --server=/internal.thekelleys.org.uk/192.168.1.1 will send all queries for internal machines to that nameserver, everything else will go to the servers in /etc/resolv.conf. An empty domain specification, // has the special meaning of "unqualified names only" ie names without any dots in them. A non-standard port may be specified as part of the IP address using a # character. More than one --server flag is allowed, with repeated domain or ipaddr parts as required.
    • More specific domains take precedence over less specific domains, so: --server=/google.com/1.2.3.4 --server=/www.google.com/2.3.4.5 will send queries for google.com and gmail.google.com to 1.2.3.4, but www.google.com will go to 2.3.4.5.
    • Matching of domains is normally done on complete labels, so /google.com/ matches google.com and www.google.com but NOT supergoogle.com. This can be overridden with a * at the start of a pattern only: /*google.com/ will match google.com and www.google.com AND supergoogle.com. The non-wildcard form has priority, so if /google.com/ and /*google.com/ are both specified then google.com and www.google.com will match /google.com/ and /*google.com/ will only match supergoogle.com.
    • For historical reasons, the pattern /.google.com/ is equivalent to /google.com/ if you wish to match any subdomain of google.com but NOT google.com itself, use /*.google.com/.
    • The special server address '#' means, "use the standard servers", so --server=/google.com/1.2.3.4 --server=/www.google.com/# will send queries for google.com and its subdomains to 1.2.3.4, except www.google.com (and its subdomains) which will be forwarded as usual.
    • Also permitted is a -S flag which gives a domain but no IP address; this tells dnsmasq that a domain is local and it may answer queries from /etc/hosts or DHCP but should never forward queries on that domain to any upstream servers. --local is a synonym for --server to make configuration files clearer in this case.
    • IPv6 addresses may include an %interface scope-id, eg fe80::202:a412:4512:7bbf%eth0.
    • The optional string after the @ character tells dnsmasq how to set the source of the queries to this nameserver. It can either be an ip-address, an interface name or both. The ip-address should belong to the machine on which dnsmasq is running, otherwise this server line will be logged and then ignored. If an interface name is given, then queries to the server will be forced via that interface; if an ip-address is given then the source address of the queries will be set to that address; and if both are given then a combination of ip-address and interface name will be used to steer requests to the server. The query-port flag is ignored for any servers which have a source address specified but the port may be specified directly as part of the source address. Forcing queries to an interface is not implemented on all platforms supported by dnsmasq.
    • Upstream servers may be specified with a hostname rather than an IP address. In this case, dnsmasq will try to use the system resolver to get the IP address of a server during startup. If name resolution fails, starting dnsmasq fails, too. If the system's configuration is such that the system resolver sends DNS queries through the dnsmasq instance which is starting up then this will time-out and fail.
  • --rev-server=<ip-address>[/<prefix-len>][,<server>][#<port>][@<interface>][@<source-ip>[#<port>]] โ€” This is functionally the same as --server, but provides some syntactic sugar to make specifying address-to-name queries easier. For example --rev-server=1.2.3.0/24,192.168.0.1 is exactly equivalent to --server=/3.2.1.in-addr.arpa/192.168.0.1 Allowed prefix lengths are 1-32 (IPv4) and 1-128 (IPv6). If the prefix length is omitted, dnsmasq substitutes either 32 (IPv4) or 128 (IPv6). ๐ŸŒˆ
  • -A, --address=/<domain>[/<domain>...]/[<ipaddr>] โ€” bestie, this one is the redirect queen ๐Ÿ‘‘. You hand it a domain and an IP, and it'll hand that IP back for any host inside those domains. A (or AAAA) queries in the domain are never forwarded, always answered with the IP you specify, which can be IPv4 or IPv6. Want multiple addresses, or both an IPv4 and an IPv6 for the same domain? Just stack up repeated --address flags, one per address. Heads up though โ€” /etc/hosts and DHCP leases override this for individual names. The classic glow-up move here is pointing the whole doubleclick.net domain at some friendly local web server so the banner ads justโ€ฆ don't ๐Ÿ’€. The domain spec works exactly like it does for --server, but with a bonus feature: /#/ matches any domain. So --address=/#/1.2.3.4 will literally always spit out 1.2.3.4 for any query that wasn't answered from /etc/hosts or DHCP, and wasn't sent upstream by a more specific --server directive. And just like --server, one or more domains with no address returns a no-such-domain answer โ€” so --address=/example.com/ is equivalent to --server=/example.com/ and returns NXDOMAIN for example.com and all its subdomains. If you specify the address as '#', it translates to the NULL address 0.0.0.0 and its IPv6 equivalent ::, so --address=/example.com/# returns NULL addresses for example.com and its subdomains. It's partly syntactic sugar for --address=/example.com/0.0.0.0 and --address=/example.com/::, but it's also more efficient than writing both as separate config lines. Lowkey important warning though: NULL addresses normally work the same way as localhost, so beware โ€” clients looking up these names are likely to end up talking to themselves ๐Ÿ™ˆ.

Oh and also โ€” the behaviour for queries that don't match the specified address literal changed in version 2.86, so pay attention bestie. Previous versions, configured with (eg) --address=/example.com/1.2.3.4 and then queried for an RR type other than A, would return a NoData answer. From 2.86 onward, the query is sent upstream instead. Want the pre-2.86 vibe back? Use the config --address=/example.com/1.2.3.4 --local=/example.com/.

  • --ipset=/<domain>[/<domain>...]/<ipset>[,<ipset>...] โ€” drops the resolved IP addresses of queries for one or more domains straight into the Netfilter IP set you name. Give it multiple setnames and the addresses go into each of them, subject to the limitations of an IP set (IPv4 addresses can't be stored in an IPv6 IP set and vice versa, periodt). Domains and subdomains are matched the same way as --address. These IP sets must already exist โ€” dnsmasq is not out here creating them for you. See ipset(8) for more.
  • --nftset=/<domain>[/<domain>...]/[(6|4)#[<family>#]<table>#<set>[,[(6|4)#[<family>#]<table>#<set>]...] โ€” the --ipset option's nftables cousin โœจ. Accepts one or more nftables sets to add IP addresses into. These sets must already exist. See nft(8) for more. The family, table and set are passed directly to the nft. And if the spec starts with 4# or 6#, then only A or AAAA records respectively get added to the set. Since an nftset can only hold IPv4 or IPv6 addresses, this is how you avoid errors being logged for addresses of the wrong type. Clean. Tidy. Slay ๐Ÿ’….
  • --connmark-allowlist-enable[=<mask>] โ€” turns on filtering of incoming DNS queries that have associated Linux connection track marks, checked against individual allowlists you set up via a series of --connmark-allowlist options. Disallowed queries are not forwarded โ€” they get rejected with a REFUSED error code. DNS queries are only allowed if they have no associated Linux connection track mark, or if the queried domains match the configured DNS patterns for that mark. And if no allowlist is configured for a mark at all? Every DNS query associated with that mark gets rejected ๐Ÿ˜ญ. If you specify a mask, Linux connection track marks are first bitwise ANDed with that mask before being processed.
  • --connmark-allowlist=<connmark>[/<mask>][,<pattern>[/<pattern>...]] โ€” configures the DNS patterns that are allowed in DNS queries tied to the given Linux connection track mark. If a mask is specified, Linux connection track marks are first bitwise ANDed with it before they get compared to the given connection track mark. Now, patterns follow the syntax of DNS names, but with a little extra sauce: they additionally allow the wildcard character * up to twice per label, to match 0 or more characters within that label. Careful though โ€” the wildcard never matches a dot (so "*.example.com" matches "api.example.com" but not "api.us.example.com"). Patterns must be fully qualified, meaning at least two labels. The final label must not be fully numeric, and must not be the "local" pseudo-TLD. A pattern must end with at least two literal (non-wildcard) labels. And instead of a pattern, you can just specify "*" to disable allowlist filtering for a given Linux connection track mark entirely. Easy out, no shame ๐Ÿซถ.
  • -m, --mx-host=<mx name>[[,<hostname>],<preference>] โ€” returns an MX record named <mx name> pointing to the given hostname (if you gave one), or to the host specified in the --mx-target switch, or โ€” if that switch isn't there either โ€” to the host dnsmasq itself is running on. The default is genuinely useful for funneling mail from systems on a LAN toward a central server, iykyk. The preference value is optional and defaults to 1 if you don't give one. You can hand out more than one MX record for a host, no problem.
  • -t, --mx-target=<hostname> โ€” sets the default target for the MX record dnsmasq returns. See --mx-host. And plot twist: if --mx-target is given but --mx-host is not, then dnsmasq returns an MX record containing the MX target for MX queries on the hostname of the machine dnsmasq is running on. Sneaky but iconic.
  • -e, --selfmx โ€” returns an MX record pointing to itself for each local machine. "Local machines" means the ones in /etc/hosts or with DHCP leases.
  • -L, --localmx โ€” returns an MX record pointing to the host given by --mx-target (or the machine dnsmasq runs on) for each local machine. Again, local machines = the ones in /etc/hosts or with DHCP leases.
  • -W, --srv-host=<_service>.<_prot>[.<domain>],[<target>[,<port>[,<priority>[,<weight>]]]] โ€” returns a SRV DNS record. See RFC2782 for the deets. If not supplied, the domain defaults to whatever --domain says. The default for the target domain is empty, the default for port is 1, and the defaults for weight and priority are 0. Big warning bestie: be careful if you're transposing data from BIND zone files, because the port, weight and priority numbers are in a different order ๐Ÿ˜ญ. More than one SRV record for a given service/domain is allowed, and all that match get returned.
  • --host-record=<name>[,<name>....],[<IPv4-address>],[<IPv6-address>][,<TTL>] โ€” adds A, AAAA and PTR records to the DNS. This adds one or more names with their associated IPv4 (A) and IPv6 (AAAA) records. A name can appear in more than one --host-record and therefore be assigned more than one address. Only the first address creates a PTR record linking the address to the name โ€” same rule as reading hosts-files. --host-record options are considered to be read before host-files, so a name appearing there inhibits PTR-record creation if it also appears in hosts-file. And unlike hosts-files, names are not expanded, even when --expand-hosts is in effect. Short and long names can hang out in the same --host-record, eg. --host-record=laptop,laptop.thekelleys.org,192.168.0.1,1234::100

If you give a time-to-live, it overrides the default, which is zero or the value of --local-ttl. The value is a positive integer and gives the time-to-live in seconds.

  • --dynamic-host=<name>,[IPv4-address],[IPv6-address],<interface> โ€” adds A, AAAA and PTR records to the DNS in the same subnet as the specified interface. The address is derived from the network part of each address associated with the interface, and the host part from the specified address. For example, --dynamic-host=example.com,0.0.0.8,eth0 will, when eth0 has the address 192.168.78.x and netmask 255.255.255.0, give the name example.com an A record for 192.168.78.8. Same principle applies to IPv6 addresses. Note that if an interface has more than one address, more than one A or AAAA record gets created. The TTL of the records is always zero, and any changes to interface addresses will be immediately reflected in them. Always current, main character energy ๐ŸŒŸ.
  • -Y, --txt-record=<name>[[,<text>],<text>] โ€” returns a TXT DNS record. The value of a TXT record is a set of strings, so any number of them may be included, delimited by commas; use quotes if you want to put commas into a string. Note that the maximum length of a single string is 255 characters โ€” anything longer gets split into 255-character chunks.
  • --ptr-record=<name>[,<target>] โ€” returns a PTR DNS record. Simple, clean, no notes โœจ.
  • --naptr-record=<name>,<order>,<preference>,<flags>,<service>,<regexp>[,<replacement>] โ€” returns a NAPTR DNS record, as specified in RFC3403. That's it, that's the tweet.
  • --caa-record=<name>,<flags>,<tag>,<value> โ€” returns a CAA DNS record, as specified in RFC6844.
  • --cname=<cname>,[<cname>,]<target>[,<TTL>] โ€” returns a CNAME record saying that <cname> is really <target>. But listen โ€” there's a significant limitation on the target: it must be a DNS record that dnsmasq knows about, and NOT a DNS record coming from an upstream server. Big deal, don't forget it. The cname must be unique, but it's totally permissible to have more than one cname pointing at the same target. In fact you can declare multiple cnames to a target in a single line, like so: --cname=cname1,cname2,target

If you give a time-to-live, it overrides the default, which is zero or the value of --local-ttl. The value is a positive integer and gives the time-to-live in seconds.

  • --dns-rr=<name>,<RR-number>,[<hex data>] โ€” returns an arbitrary DNS Resource Record. The number is the type of the record (which is always in the C_IN class). The value of the record is given by the hex data, which may be in the form 01:23:45 or 01 23 45 or 012345, or literally any mixture of these. Mix and match, live your truth ๐ŸŒˆ.
  • --interface-name=<name>,<interface>[/4|/6] โ€” okay so bestie, this one hands back DNS records that tie the name to the address(es) of the interface you picked ๐Ÿ’–. It's giving /etc/hosts energy, but the address is not constant โ€” it's pulled from the interface. You can slap /4 or /6 after the interface to say only IPv4 or only IPv6 addresses from it, okay? If the interface is down, not configured, or straight-up doesn't exist, you get an empty record back. The matching PTR record gets created too, mapping the interface address to the name. Want more than one name on one interface address? Repeat the flag, bestie, but heads up: the first instance is the one used for the reverse address-to-name mapping. Also major: a name used in --interface-name may not appear in /etc/hosts. ๐Ÿซถ
  • --synth-domain=<domain>,<address range>[,<prefix>[*]] โ€” This one makes artificial A/AAAA and PTR records for an address range โœจ. The records are either sequential numbers or the address, with periods (or colons for IPv6) replaced with dashes.

Example time, because yes. First, sequential numbers:

--synth-domain=thekelleys.org.uk,192.168.0.50,192.168.0.70,internal-*

results in internal-0.thekelleys.org.uk. returning 192.168.0.50, internal-1.thekelleys.org.uk returning 192.168.0.51 and so on. (note the *) The same principle applies to IPv6 addresses (where the numbers may be very large). Reverse lookups from address to name behave as expected.

Second, --synth-domain=thekelleys.org.uk,192.168.0.0/24,internal- (no *) will result in a query for internal-192-168-0-56.thekelleys.org.uk returning 192.168.0.56 and a reverse query vice versa. The same applies to IPv6; the representation doesn't use the :: compression feature or the special representation of V4 mapped IPv6 addresses as these can generate illegal domain names, so all domains are of the form internal-1000-0000-0000-0000-0000-0000-0000-0008.example.com.

The address range can be of the form <start address>,<end address> or <ip address>/<prefix-length> in both forms of the option. For IPv6 the start and end addresses must fall in the same /64 network, or prefix-length must be greater than or equal to 64 except that shorter prefix lengths than 64 are allowed only if non-sequential names are in use. ๐ŸŒˆ

  • --dumpfile=<path/to/file> โ€” Specify the location of a pcap-format file which dnsmasq uses to dump copies of network packets for debugging purposes ๐ŸŽ€. If the file exists when dnsmasq starts, it is not deleted; new packets are added to the end. The file may be a named-pipe which Wireshark is listening to. ๐Ÿ‘‘
  • --dumpmask=<mask> โ€” Specify which types of packets should be added to the dumpfile. The argument should be the OR of the bitmasks for each type of packet to be dumped: it can be specified in hex by preceding the number with 0x in the normal way. Each time a packet is written to the dumpfile, dnsmasq logs the packet sequence and the mask representing its type. The current types are:
    • 0x0001 - DNS queries from clients
    • 0x0002 DNS replies to clients
    • 0x0004 - DNS queries to upstream
    • 0x0008 - DNS replies from upstream
    • 0x0010 - queries send upstream for DNSSEC validation
    • 0x0020 - replies to queries for DNSSEC validation
    • 0x0040 - replies to client queries which fail DNSSEC validation
    • 0x0080 replies to queries for DNSSEC validation which fail validation
    • 0x1000 - DHCPv4
    • 0x2000 - DHCPv6
    • 0x4000 - Router advertisement
    • 0x8000 - TFTP
  • --add-mac[=base64|text] โ€” Add the MAC address of the requestor to DNS queries which are forwarded upstream ๐ŸŒธ. This may be used to DNS filtering by the upstream server. The MAC address can only be added if the requestor is on the same subnet as the dnsmasq server. Note that the mechanism used to achieve this (an EDNS0 option) is not yet standardised, so this should be considered experimental. Also note that exposing MAC addresses in this way may have security and privacy implications ๐Ÿ”ฅ. The warning about caching given for --add-subnet applies to --add-mac too. An alternative encoding of the MAC, as base64, is enabled by adding the "base64" parameter and a human-readable encoding of hex-and-colons is enabled by added the "text" parameter.
  • --strip-mac โ€” Remove any MAC address information already in downstream queries before forwarding upstream. ๐Ÿ’…
  • --add-cpe-id=<string> โ€” Add an arbitrary identifying string to DNS queries which are forwarded upstream. ๐Ÿฆ‹
  • --add-subnet[[=[<IPv4 address>/]<IPv4 prefix length>][,[<IPv6 address>/]<IPv6 prefix length>]] โ€” Add a subnet address to the DNS queries which are forwarded upstream. If an address is specified in the flag, it will be used, otherwise, the address of the requestor will be used. The amount of the address forwarded depends on the prefix length parameter: 32 (128 for IPv6) forwards the whole address, zero forwards none of it but still marks the request so that no upstream nameserver will add client address information either. The default is zero for both IPv4 and IPv6. Note that upstream nameservers may be configured to return different results based on this information, but the dnsmasq cache does not take account. Caching is therefore disabled for such replies, unless the subnet address being added is constant.

For example, --add-subnet=24,96 will add the /24 and /96 subnets of the requestor for IPv4 and IPv6 requestors, respectively. --add-subnet=1.2.3.4/24 will add 1.2.3.0/24 for IPv4 requestors and ::/0 for IPv6 requestors. --add-subnet=1.2.3.4/24,1.2.3.4/24 will add 1.2.3.0/24 for both IPv4 and IPv6 requestors. ๐Ÿ’œ

  • --strip-subnet โ€” Remove any subnet address already present in a downstream query before forwarding it upstream. If --add-subnet is set this also ensures that any downstream-provided subnet is replaced by the one added by dnsmasq. Otherwise, dnsmasq will NOT replace an existing subnet in the query. ๐Ÿ˜ญ
  • --umbrella[=[deviceid:<deviceid>][,orgid:<orgid>][,assetid:<id>]] โ€” Embeds the requestor's IP address in DNS queries forwarded upstream. If device id or, asset id or organization id are specified, the information is included in the forwarded queries and may be able to be used in filtering policies and reporting. The order of the id attributes is irrelevant, but they must be separated by a comma. Deviceid is a sixteen digit hexadecimal number, org and asset ids are decimal numbers. ๐Ÿ“
  • -c, --cache-size=<cachesize> โ€” Set the size of dnsmasq's cache. The default is 150 names. Setting the cache size to zero disables caching. Note: huge cache size impacts performance. ๐Ÿ‘‘
  • -N, --no-negcache โ€” Disable negative caching. Negative caching allows dnsmasq to remember "no such domain" answers from upstream nameservers and answer identical queries without forwarding them again. ๐ŸŒŸ
  • --no-round-robin โ€” Dnsmasq normally permutes the order of A or AAAA records for the same name on successive queries, for load-balancing. This turns off that behaviour, so that the records are always returned in the order that they are received from upstream. ๐ŸŽ€
  • --do-0x20-encode, --no-0x20-encode โ€” Dnsmasq can scramble the case of letters in DNS queries it sends upstream as a security feature. This technique can interact badly with rare broken DNS servers which don't preserve the case of the query in their reply. The first time a reply is returned which matches the query in all respects except case, a warning will be logged. If this coincides with DNS not functioning, it is necessary to disable the feature. As at version 2.91, 0x20 encoding is disabled by default, and must be enabled with --do-0x20-encode. The default may change in the future, so to be sure of its status after an upgrade, set --do-0x20-encode or --no-0x20-encode in your config. --no-0x20-encode overrides --do-0x20-encode or a future default 0x20-encode enable. โญ
  • --use-stale-cache[=<max TTL excess in s>] โ€” When set, if a DNS name exists in the cache, but its time-to-live has expired, dnsmasq will return the data anyway. (It attempts to refresh the data with an upstream query after returning the stale data.) This can improve speed and reliability. It comes at the expense of sometimes returning out-of-date data and less efficient cache utilisation, since old data cannot be flushed when its TTL expires, so the cache becomes mostly least-recently-used. To mitigate issues caused by massively outdated DNS replies, the maximum overaging of cached records can be specified in seconds (defaulting to not serve anything older than one day). Setting the TTL excess time to zero will serve stale cache data regardless how long it has expired. ๐Ÿงš
  • -0, --dns-forward-max=<queries> โ€” Set the maximum number of concurrent DNS queries. The default value is 150, which should be fine for most setups. The only known situation where this needs to be increased is when using web-server log file resolvers, which can generate large numbers of concurrent queries. This parameter actually controls the number of concurrent queries per server group, where a server group is the set of server(s) associated with a single domain. So if a domain has its own server via --server=/example.com/1.2.3.4 and 1.2.3.4 is not responding, but queries for *.example.com cannot go elsewhere, then other queries will not be affected. On configurations with many such server groups and tight resources, this value may need to be reduced. ๐Ÿ’–
  • --dnssec โ€” bestie, this one turns on the whole validating resolver era โœจ DNS replies get validated AND the DNSSEC data gets cached.

When it's forwarding queries, dnsmasq goes and grabs the DNSSEC records it needs to validate the replies. The replies get validated, and the result comes back as the Authenticated Data bit in the DNS packet. Bonus: those DNSSEC records land in the cache, so clients validating stuff get to be way more efficient about it. ๐ŸŽ€

Heads up tho โ€” validation by clients is the most secure DNSSEC mode. For clients that literally can't validate, using the AD bit that dnsmasq sets is useful, provided the network between the dnsmasq server and the client is trusted. ๐Ÿ‘‘

Requirements, no skipping: dnsmasq must be compiled with HAVE_DNSSEC enabled, and DNSSEC trust anchors must be provided โ€” see --trust-anchor.

Because the DNSSEC validation process uses the cache, you are not permitted to reduce the cache size below the default when DNSSEC is enabled. Periodt.

And the scary part ๐Ÿ˜ญ โ€” the nameservers upstream of dnsmasq must be DNSSEC-capable, i.e. capable of returning DNSSEC records with data. If they are not, dnsmasq won't be able to determine the trusted status of answers, and that means DNS service will be entirely broken. Not a vibe.

  • --trust-anchor=<domain>,[<class>,][<key-tag>,<algorithm>,<digest-type>,<digest>] โ€” hand over DS records to act as trust anchors for DNSSEC validation ๐Ÿซถ

The class defaults to IN. Usually these are the DS record(s) for Key Signing key(s) (KSK) of the root zone, but trust anchors for limited domains are also possible.

A negative trust anchor (i.e. proof that a DS record doesn't exist) can be configured by specifying only the name, or only the name and class. Lowkey iconic for forcing dnsmasq to treat zones delegated using --server=/<domain>/<ip-address> as unsigned.

Current root-zone trust anchors live at https://data.iana.org/root-anchors/root-anchors.xml ๐Ÿ’…

  • --dnssec-check-unsigned[=no] โ€” by default, dnsmasq checks that unsigned DNS replies are legitimate ๐ŸŒธ This means possible extra queries even for the majority of DNS zones which are not, at the moment, signed. If --dnssec-check-unsigned=no appears in the configuration, then such replies are assumed to be valid and passed on (without the "authentic data" bit set, of course). This does not protect against an attacker forging unsigned replies for signed DNS zones, but it is fast.

Lore drop ๐Ÿ“œ versions of dnsmasq prior to 2.80 defaulted to not checking unsigned replies, and used --dnssec-check-unsigned to switch this on. Such configurations will continue to work as before, but those which used the default of no checking will need to be altered to explicitly select no checking.

The new default exists because switching off checking for unsigned replies is inherently dangerous. Not only does it open the possibility of forged replies, but it allows everything to appear to be working even when the upstream nameservers do not support DNSSEC โ€” and in this case no DNSSEC validation at all is occurring. ๐Ÿ’€
  • --dnssec-no-timecheck โ€” okay so DNSSEC signatures are only valid for specified time windows, and should be rejected outside those windows. Which creates the most annoying chicken-and-egg problem for machines that don't have a hardware real time clock ๐Ÿ˜ญ

For these machines, figuring out the correct time typically requires NTP and therefore DNS โ€” but validating DNS requires that the correct time is already known. Catch-22 fr fr.

Setting this flag removes the time-window checks (but not other DNSSEC validation), only until the dnsmasq process receives SIGINT. The intention is that dnsmasq should be started with this flag when the platform determines that reliable time is not currently available. As soon as reliable time is established, a SIGINT should be sent to dnsmasq, which enables time checking, and purges the cache of DNS records which have not been thoroughly checked. ๐Ÿงš

Earlier versions of dnsmasq overloaded SIGHUP (which re-reads much configuration) to also enable time validation.

Careful tho ๐ŸŒˆ if dnsmasq is run in debug mode (--no-daemon flag) then SIGINT retains its usual meaning of terminating the dnsmasq process.

  • --dnssec-timestamp=<path> โ€” enables an alternative way of checking the validity of the system time for DNSSEC (see --dnssec-no-timecheck). In this case, the system time is considered to be valid once it becomes later than the timestamp on the specified file. ๐Ÿ’…

The file is created and its timestamp set automatically by dnsmasq. It must be stored on a persistent filesystem, so that it and its mtime are carried over system restarts. And because the timestamp file is created after dnsmasq has dropped root, it must be in a location writable by the unprivileged user that dnsmasq runs as. ๐Ÿ™ˆ

  • --proxy-dnssec โ€” copies the DNSSEC Authenticated Data bit from upstream servers to downstream clients โœจ

This is an alternative to having dnsmasq validate DNSSEC, but it depends on the security of the network between dnsmasq and the upstream servers, and the trustworthiness of the upstream servers.

Note that caching the Authenticated Data bit correctly in all cases is not technically possible. If the AD bit is to be relied upon when using this option, then the cache should be disabled using --cache-size=0.

In most cases, enabling DNSSEC validation within dnsmasq is a better option. See --dnssec for details. ๐Ÿ‘‘

  • --dnssec-limits=<limit>[,<limit>.......] โ€” override the default resource limits applied to DNSSEC validation ๐Ÿ”ฅ

Cryptographic operations are expensive, and crafted domains can DoS a DNSSEC validator by forcing it to do hundreds of thousands of such operations. To avoid this, the dnsmasq validation code applies limits on how much work will be expended in validation. If any of the limits are exceeded, the validation will fail and the domain treated as BOGUS.

There are four limits, in order (default values in parens):

  1. number a signature validation fails per RRset (20)
  2. number of signature validations and hash computations per query (200)
  3. number of sub-queries to fetch DS and DNSKEY RRsets per query (40)
  4. the number of iterations in a NSEC3 record (150)

The maximum values reached during validation are stored, and dumped as part of the stats generated by SIGUSR1. โœจ

Supplying a limit value of 0 leaves the default in place, so --dnssec-limits=0,0,20 sets the number of sub-queries to 20 whilst leaving the other limits at default values. Bestie math ๐Ÿ’–

  • --dnssec-debug โ€” set debugging mode for the DNSSEC validation, set the Checking Disabled bit on upstream queries, and don't convert replies which do not validate to responses with a return code of SERVFAIL.
Note that setting this may affect DNS behaviour in bad ways, it is not an extra-logging flag and should not be set in production. ๐Ÿ˜ญ
  • --auth-zone=<domain>[,<subnet>[/<prefix length>][,<subnet>[/<prefix length>].....][,exclude:<subnet>[/<prefix length>]].....] โ€” define a DNS zone for which dnsmasq acts as authoritative server ๐Ÿ‘‘

Locally defined DNS records which are in the domain will be served. If subnet(s) are given, A and AAAA records must be in one of the specified subnets.

As an alternative to directly specifying the subnets, it's possible to give the name of an interface, in which case the subnets implied by that interface's configured addresses and netmask/prefix-length are used. This is useful when using constructed DHCP ranges, as the actual address is dynamic and not known when configuring dnsmasq.

The interface addresses may be confined to only IPv6 addresses using <interface>/6 or to only IPv4 using <interface>/4. This is useful when an interface has dynamically determined global IPv6 addresses which should appear in the zone, but RFC1918 IPv4 addresses which should not. ๐ŸŒˆ

Interface-name and address-literal subnet specifications may be used freely in the same --auth-zone declaration. No gatekeeping ๐Ÿ’…

It's possible to exclude certain IP addresses from responses. It can be used to make sure that answers contain only global routeable IP addresses (by excluding loopback, RFC1918 and ULA addresses).

The subnet(s) are also used to define in-addr.arpa and ip6.arpa domains which are served for reverse-DNS queries. If not specified, the prefix length defaults to 24 for IPv4 and 64 for IPv6.

For IPv4 subnets, the prefix length should have the value 8, 16 or 24 unless you are familiar with RFC 2317 and have arranged the in-addr.arpa delegation accordingly. ๐ŸŒธ

Note that if no subnets are specified, then no reverse queries are answered. ๐Ÿ™ˆ
  • --auth-soa=<serial>[,<hostmaster>[,<refresh>[,<retry>[,<expiry>]]]] โ€” specify fields in the SOA record associated with authoritative zones. Note that this is optional, all the values are set to sane defaults โœจ
  • --auth-sec-servers=<domain>[,<domain>[,<domain>...]] โ€” specify any secondary servers for a zone for which dnsmasq is authoritative ๐Ÿซถ These servers must be configured to get zone data from dnsmasq by zone transfer, and answer queries for the same authoritative zones as dnsmasq.
  • --auth-peer=<ip-address>[,<ip-address>[,<ip-address>...]] โ€” specify the addresses of secondary servers which are allowed to initiate zone transfer (AXFR) requests for zones for which dnsmasq is authoritative ๐Ÿ’…

If this option is not given but --auth-sec-servers is, then AXFR requests will be accepted from any secondary.

Specifying --auth-peer without --auth-sec-servers enables zone transfer but does not advertise the secondary in NS records returned by dnsmasq. Sneaky but valid ๐Ÿ’–

  • --conntrack โ€” read the Linux connection track mark associated with incoming DNS queries and set the same mark value on upstream traffic used to answer those queries. This allows traffic generated by dnsmasq to be associated with the queries which cause it, useful for bandwidth accounting and firewalling. ๐Ÿ”ฅ

Dnsmasq must have conntrack support compiled in and the kernel must have conntrack support included and configured.

This option cannot be combined with --query-port. ๐Ÿšซ

๐ŸŒธ -F, --dhcp-range ๐ŸŒธ

bestie. okay. sit down. this is THE option, the one that turns the DHCP server on fr fr. There's an IPv4 flavor and an IPv6 flavor and they look kinda different, so here's both, verbatim:

-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag>,]<start-addr>[,<end-addr>|<mode>[,<netmask>[,<broadcast>]]][,<lease time>]
-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag>,]<start-IPv6addr>[,<end-IPv6addr>|constructor:<interface>][,<mode>][,<prefix-len>][,<lease time>]

So basically: this enables the DHCP server, and addresses get handed out everywhere from <start-addr> to <end-addr>, plus all the statically defined ones you set up in --dhcp-host. Give it a <lease time> and the leases last exactly that long. The lease time can be in seconds (just the number), or minutes (like 45m), or hours (like 1h), or days (2d), or weeks (1w), or the literal word infinite. No lease time? Then the default is one hour for IPv4 and one day for IPv6 ๐ŸŒˆ. And listen โ€” the minimum lease time is two minutes, that's the floor, no shorter leases allowed periodt.

For IPv6 ranges specifically, the lease time can also be deprecated ๐Ÿ‘€ โ€” which sets the preferred lifetime sent in a DHCP lease or router advertisement to zero. What that does is make clients use other addresses (if they have any) for new connections, as a lil prelude to renumbering. iykyk.

You can repeat this option with different addresses to serve more than one network โ€” it's giving multitasking queen. For directly connected networks (aka networks where the dnsmasq machine has an interface), the netmask is optional: dnsmasq will just figure it out from the interface configuration. For networks that get DHCP service through a relay agent, though, dnsmasq can't determine the netmask itself, so you should specify it, otherwise dnsmasq will have to guess based on the class (A, B or C) of the network address ๐Ÿ˜ฌ. The broadcast address is always optional. Also, it's always allowed to have more than one --dhcp-range in a single subnet. slay.


IPv6 gets its own rules ๐Ÿ’œ

For IPv6 the parameters are a lil different: instead of netmask and broadcast address, you get an optional prefix length, which must be equal to or larger than the prefix length on the local interface. If you don't give one, it defaults to 64. And unlike the IPv4 case, the prefix length is not automatically derived from the interface configuration โ€” you have to think about it, bestie. The minimum size of the prefix length is 64.

IPv6 (and only IPv6) also supports another whole type of range ๐Ÿฆ‹. In this one, the start address and optional end address contain only the network part (like ::1), and they're followed by constructor:<interface>. This forms a template describing how to create ranges based on the addresses assigned to the interface. For instance:

--dhcp-range=::1,::400,constructor:eth0

will go look at the addresses on eth0 and then create a range from <network>::1 to <network>::400. And if that interface is assigned more than one network, the corresponding ranges get automatically created โ€” and then deprecated, and then finally removed again as the address itself gets deprecated and deleted. It's a whole lifecycle. The interface name may have a final * wildcard. One important note tho: literally any address on eth0 will not do โ€” it must not be an autoconfigured or privacy address, or be deprecated. ๐Ÿ™ˆ

If a --dhcp-range is only being used for stateless DHCP and/or SLAAC, then the address can be just :: like this:

--dhcp-range=::,constructor:eth0

Tags ๐ŸŽ€

The optional set:<tag> sets an alphanumeric label that marks this network, so DHCP options can be specified on a per-network basis. But when it's prefixed with tag: instead, its whole meaning flips from setting a tag to matching it. Only one tag may be set, but more than one tag may be matched. periodt.


The <mode> options โœจ

The optional <mode> keyword may be static, which tells dnsmasq to enable DHCP for the network specified but not to dynamically allocate IP addresses: only hosts with static addresses given via --dhcp-host or from /etc/ethers will be served. A static-only subnet with address all zeros may be used as a "catch-all" address to enable replies to all Information-request packets on a subnet which is provided with stateless DHCPv6, ie:

--dhcp-range=::,static

For IPv4, the <mode> may be proxy โ€” in which case dnsmasq provides proxy-DHCP on the specified subnet. (See --pxe-prompt and --pxe-service for the deets.)

For IPv6, the mode may be some combination of ra-only, slaac, ra-names, ra-stateless, ra-advrouter, off-link. Let's break each one down ๐Ÿ‘‘:

  • ra-only โ€” tells dnsmasq to offer Router Advertisement only on this subnet, and not DHCP.
  • slaac โ€” tells dnsmasq to offer Router Advertisement on this subnet and to set the A bit in the router advertisement, so the client will use SLAAC addresses. When used with a DHCP range or static DHCP address, this results in the client having both a DHCP-assigned and a SLAAC address. two addresses, main character energy ๐Ÿ’….
  • ra-stateless โ€” sends router advertisements with the O and A bits set, and provides a stateless DHCP service. The client will use a SLAAC address, and use DHCP for other configuration information.
  • ra-names โ€” enables a mode which gives DNS names to dual-stack hosts doing SLAAC for IPv6. Dnsmasq uses the host's IPv4 lease to derive the name, network segment and MAC address, and assumes the host will also have an IPv6 address calculated using the SLAAC algorithm, on the same network segment. The address gets pinged, and if a reply comes back, an AAAA record is added to the DNS for this IPv6 address. Note that this only happens for directly-connected networks (not one doing DHCP via a relay), and it will not work if a host is using privacy extensions ๐Ÿšซ. ra-names can be combined with ra-stateless and slaac.
  • ra-advrouter โ€” enables a mode where router address(es) rather than prefix(es) are included in the advertisements. This is described in RFC-3775 section 7.2 and is used in mobile IPv6. In this mode the interval option is also included, as described in RFC-3775 section 7.3.
  • off-link โ€” tells dnsmasq to advertise the prefix without the on-link (aka L) bit set.

๐Ÿฆ‹ -G, --dhcp-host ๐Ÿฆ‹

-G, --dhcp-host=[<hwaddr>][,id:<client_id>|*][,set:<tag>][,tag:<tag>][,<ipaddr>][,<hostname>][,<lease_time>][,ignore]

This one lets you specify per-host parameters for the DHCP server, so a machine with a particular hardware address always gets the same hostname, IP address and lease time. It's giving favorite child privileges, honestly. And a hostname specified like this overrides any hostname supplied by the DHCP client on that machine. You're also allowed to omit the hardware address and just include the hostname โ€” in which case the IP address and lease times apply to any machine claiming that name. For example:

--dhcp-host=00:20:e0:3b:13:af,wap,infinite

tells dnsmasq to give the machine with hardware address 00:20:e0:3b:13:af the name wap, and an infinite DHCP lease. And:

--dhcp-host=lap,192.168.0.199

tells dnsmasq to always allocate the machine lap the IP address 192.168.0.199. ๐Ÿ’–

Addresses allocated like this are not constrained to be in the range given by the --dhcp-range option โ€” but they must be in the same subnet as some valid dhcp-range. For subnets that don't need a pool of dynamically allocated addresses, use the static keyword in the --dhcp-range declaration.


Identifying hosts by client ID ๐Ÿ’…

You're allowed to use client identifiers (called client DUID in IPv6-land) rather than hardware addresses to identify hosts, by prefixing with id:. So:

--dhcp-host=id:01:02:03:04,.....

refers to the host with client identifier 01:02:03:04. And you can also specify the client ID as text, like this:

--dhcp-host=id:clientidastext,.....

IPv6 addresses in here ๐Ÿฆ‹

A single --dhcp-host may contain an IPv4 address, or one or more IPv6 addresses, or both. IPv6 addresses must be bracketed by square brackets, thus:

--dhcp-host=laptop,[1234::56]

IPv6 addresses may contain only the host-identifier part:

--dhcp-host=laptop,[::56]

in which case they act as wildcards in constructed DHCP ranges, with the appropriate network part inserted for you. For IPv6, an address may also include a prefix length:

--dhcp-host=laptop,[1234:50/126]

which (in this case) specifies four addresses, 1234::50 to 1234::53. This โ€” and the ability to specify multiple addresses โ€” is useful when a host presents either a consistent name or hardware-ID but varying DUIDs, since it lets dnsmasq honour the static address allocation while still assigning a different address for each DUID. This typically happens when chain netbooting, as each stage of the chain in turn allocates an address. so chaotic of it ๐Ÿ˜ญ.

Note that in IPv6 DHCP, the hardware address may not be available โ€” though it normally is for direct-connected clients, or clients using DHCP relays which support RFC 6939.

For DHCPv4, the special option id:* means "ignore any client-id and use MAC addresses only." This is useful when a client presents a client-id sometimes but not others. ๐Ÿ™ƒ


/etc/hosts tea ๐Ÿ‘€

If a name appears in /etc/hosts, the associated address can be allocated to a DHCP lease โ€” but only if a --dhcp-host option specifying the name also exists. Only one hostname can be given in a --dhcp-host option, but aliases are possible by using CNAMEs. (See --cname.) Note that /etc/hosts is NOT used when the DNS server side of dnsmasq is disabled by setting the DNS server port to zero.

More than one --dhcp-host can be associated with a host (by name, hardware address or UID). Which one gets used โ€” and therefore which address is allocated by DHCP and appears in the DNS โ€” depends on the subnet on which the host last obtained a DHCP lease: the --dhcp-host with an address within the subnet is used. If more than one address is within the subnet, the result is undefined ๐Ÿ˜ฌ. And a corollary to all this: the name associated with a host using --dhcp-host does not appear in the DNS until that host obtains a DHCP lease. patience, bestie.


ignore ๐Ÿšซ

The special keyword ignore tells dnsmasq to never offer a DHCP lease to a machine. The machine can be specified by hardware address, client ID or hostname. For example:

--dhcp-host=00:20:e0:3b:13:af,ignore

This can be useful when there's another DHCP server on the network that some machines should be using instead. โœจ

and when a host matches any --dhcp-host directive (or one that got implied by /etc/ethers), the special tag known gets set โœจ. which is how you tell dnsmasq to ignore all the randos โ€” --dhcp-ignore=tag:!known โ€” no cap, that's the move. and if a host matches only a --dhcp-host directive that can't actually be used (because it specifies an address on a different subnet, rip), then the tag known-othernet gets set instead.

okay next: the tag:<tag> construct is the one that filters which dhcp-host directives get used. you can hand it more than one tag, and in that case the request has to match all of them โ€” every single one, no partial credit ๐Ÿ’…. tagged directives are always used in preference to untagged ones. but heads up bestie, one of <hwaddr>, <client_id> or <hostname> still has to be specified (it can be a wildcard, we're not monsters).

Ethernet addresses (but not client-ids, ok) can have wildcard bytes in them ๐Ÿฆ‹, so for example --dhcp-host=00:20:e0:3b:13:*,ignore makes dnsmasq ignore that whole range of hardware addresses. and ngl there's a little gotcha here: that "*" needs to be escaped or quoted on a command line, but not in the configuration file. society.

Hardware addresses normally match any network (ARP) type, but you can lock them down to a single ARP type by putting the ARP-type (in HEX) in front of them followed by -. so --dhcp-host=06-00:20:e0:3b:13:af,1.2.3.4 will only match a Token-Ring hardware address, since the ARP-address type for token ring is 6. periodt.

and here's a special case for DHCPv4 ๐Ÿ‘‘: you can include more than one hardware address. eg:

--dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.2

this lets an IP address be associated with multiple hardware addresses, and gives dnsmasq permission to abandon a DHCP lease to one of the hardware addresses when another one of them asks for a lease. and now the dramatic part:

โš ๏ธ beware, this is a dangerous thing to do. it will only work reliably if only one of the hardware addresses is active at any time, and there is no way for dnsmasq to enforce this. it is, for instance, useful to allocate a stable IP address to a laptop which has both wired and wireless interfaces. cute use case, chaotic energy.

  • --dhcp-hostsfile=<path> โ€” reads DHCP host information from the file you give it ๐Ÿ“‚. if you hand it a directory instead, it reads all the files contained in that directory in alphabetical order. the file holds info about one host per line, and the format of each line is the same as the text to the right of = in --dhcp-host. the whole point of keeping this in a file? you can change it without re-starting dnsmasq โ€” the file gets re-read when dnsmasq receives SIGHUP. slay.
  • --dhcp-optsfile=<path> โ€” reads DHCP option information from the specified file ๐ŸŒธ. same deal: if a directory is given, it reads all the files contained in that directory in alphabetical order. the advantage here is the same as for --dhcp-hostsfile โ€” --dhcp-optsfile gets re-read when dnsmasq receives SIGHUP. and lowkey iconic: you can encode the information in a --dhcp-boot flag as DHCP options, using the option names bootfile-name, server-ip-address and tftp-server. that means these can live inside a --dhcp-optsfile.
  • --dhcp-hostsdir=<path> โ€” basically --dhcp-hostsfile's twin, except for these bits ๐Ÿซถ: the path MUST be a directory, not an individual file. changed or new files inside the directory get read automatically, with no SIGHUP required. but โ€” and this is the catch ๐Ÿ˜ญ โ€” if a file is deleted or changed after dnsmasq has already read it, the host record it contained will remain until dnsmasq receives a SIGHUP, or gets restarted. ie host records are only ever added dynamically. and the order in which the files in a directory get read is not defined. vibe check: unspecified.
  • --dhcp-optsdir=<path> โ€” this is equivalent to --dhcp-optsfile, but with all the differences noted above for --dhcp-hostsdir. same energy, different folder ๐Ÿ’œ.
  • -Z, --read-ethers โ€” reads /etc/ethers for information about hosts for the DHCP server ๐ŸŒˆ. the format of /etc/ethers is a hardware address, followed by either a hostname or a dotted-quad IP address. when read by dnsmasq, these lines have <em>exactly</em> the same effect as --dhcp-host options containing the same information. /etc/ethers is re-read when dnsmasq receives SIGHUP. and note: IPv6 addresses are NOT read from /etc/ethers ๐Ÿšซ.
  • -O, --dhcp-option=[tag:<tag>,[tag:<tag>,]][encap:<opt>,][vi-encap:<enterprise>,][vendor:[<vendor-class>],][<opt>|option:<opt-name>|option6:<opt>|option6:<opt-name>],[<value>[,<value>]] โ€” sends various extra options to DHCP clients ๐Ÿ’–. so, context: by default dnsmasq sends some standard options to DHCP clients โ€” the netmask and broadcast address are set to the same as the host running dnsmasq, and the DNS server and default route are set to the address of the machine running dnsmasq. (equivalent rules apply for IPv6.) if the domain name option has been set, that one gets sent too. this configuration is how you override those defaults, or specify other options entirely. the option to be sent can be given as a decimal number, or as option:<option-name>.

Option numbers are specified in RFC2132 and subsequent RFCs ๐Ÿ“œ. you can discover the set of option-names dnsmasq knows about by running dnsmasq --help dhcp. for example, to set the default route option to 192.168.4.4, use --dhcp-option=3,192.168.4.4 or --dhcp-option=option:router,192.168.4.4, and to set the time-server address to 192.168.0.4, use --dhcp-option=42,192.168.0.4 or --dhcp-option=option:ntp-server,192.168.0.4. the special address 0.0.0.0 means "the address of the system running dnsmasq".

An option without data is valid, and it includes just the option without data. (there is only one option with a zero length data field currently defined for DHCPv4, 80:rapid commit, so this feature is not very useful in practice ๐Ÿ™ˆ.) Options for which dnsmasq normally provides default values can be omitted by defining the option with no data. these are netmask, broadcast, router, DNS server, domainname and hostname. so for DHCPv4, --dhcp-option = option:router results in no router option being sent at all, rather than the default of the host on which dnsmasq is running. for DHCPv6, the same is true of the options DNS server and refresh time.

Data types allowed are comma separated dotted-quad IPv4 addresses, []-wrapped IPv6 addresses, a decimal number, colon-separated hex digits, and a text string โœจ. if the optional tags are given, then this option is only sent when all the tags are matched.

Special processing is done on a text argument for option 119, to conform with RFC 3397 ๐ŸŒธ. text or dotted-quad IP addresses as arguments to option 120 are handled as per RFC 3361. dotted-quad IP addresses which are followed by a slash and then a netmask size are encoded as described in RFC 3442.

IPv6 options are specified using the option6: keyword, followed by the option number or option name ๐Ÿ’œ. the IPv6 option name space is disjoint from the IPv4 option name space. IPv6 addresses in options must be bracketed with square brackets, eg. --dhcp-option=option6:ntp-server,[1234::56]. for IPv6, [::] means "the global address of the machine running dnsmasq", whilst [fd00::] is replaced with the ULA, if it exists, and [fe80::] with the link-local address.

๐Ÿšจ be careful bestie: data-type suitability for the option number sent is not checked. it is quite possible to persuade dnsmasq to generate illegal DHCP packets with injudicious use of this flag. you've been warned. ๐Ÿ’€

When the value is a decimal number, dnsmasq must determine how large the data item is. it does this by examining the option number and/or the value, but that can be overridden by appending a single letter flag: b = one byte, s = two bytes, i = four bytes โœจ. this is mainly useful with encapsulated vendor class options (see below) where dnsmasq cannot determine data size from the option number. Option data which consists solely of periods and digits will be interpreted by dnsmasq as an IP address, and inserted into an option as such. to force a literal string, use quotes ๐ŸŽ€. for instance, when using option 66 to send a literal IP address as TFTP server name, it is necessary to do --dhcp-option=66,"1.2.3.4".

Encapsulated Vendor-class options may also be specified (IPv4 only) using --dhcp-option ๐Ÿฆ‹: for instance --dhcp-option=vendor:PXEClient,1,0.0.0.0 sends the encapsulated vendor class-specific option "mftp-address=0.0.0.0" to any client whose vendor-class matches "PXEClient". the vendor-class matching is substring based (see --dhcp-vendorclass for details ๐Ÿ‘€). if a vendor-class option (number 60) is sent by dnsmasq, then that is used for selecting encapsulated options in preference to any sent by the client. it's also possible to omit the vendorclass completely โ€” --dhcp-option=vendor:,1,0.0.0.0 โ€” in which case the encapsulated option is always sent ๐Ÿ‘‘.

Options may be encapsulated (IPv4 only) within other options: for instance --dhcp-option=encap:175, 190, iscsi-client0 will send option 175, within which is the option 190. if multiple options are given which are encapsulated with the same option number, then they will be correctly combined into one encapsulated option โœจ. encap: and vendor: may not both be set in the same --dhcp-option.

The final variant on encapsulated options is "Vendor-Identifying Vendor Options" as specified by RFC3925. these are denoted like this: --dhcp-option=vi-encap:2, 10, text ๐Ÿ’ซ. the number in the vi-encap: section is the IANA enterprise number used to identify this option. this form of encapsulation is supported in IPv6, ngl that's a serve.

The address 0.0.0.0 is not treated specially in encapsulated options ๐ŸŒธ.

  • --dhcp-option-force=[tag:<tag>,[tag:<tag>,]][encap:<opt>,][vi-encap:<enterprise>,][vendor:[<vendor-class>],]<opt>,[<value>[,<value>]] โ€” bestie this is literally --dhcp-option but with main character energy: the option gets sent no matter what, even if the client never asked for it in the parameter request list. Sometimes you just gotta โœจmanifestโœจ that option into the packet. Classic case? Sending options to PXELinux. It's giving "I don't wait for an invitation." ๐Ÿ’…
  • --dhcp-option-pxe=[tag:<tag>,[tag:<tag>,]][encap:<opt>,][vi-encap:<enterprise>,]<opt>,[<value>[,<value>]] โ€” a lil cousin of --dhcp-option ๐Ÿฆ‹ that defines options sent only in reply to PXE clients. And plot twist: when dnsmasq is acting as a PXE proxy, these options do get sent to PXE clients, unlike the regular options which don't. A super typical use-case is option 175, sent to iPXE. It's giving exclusive club, PXE-only, iykyk ๐ŸŽ€
  • --dhcp-no-override โ€” (IPv4 only ๐Ÿซถ) turns OFF the re-use of the DHCP servername and filename fields as extra option space. When it can, dnsmasq moves the boot server and filename info (from --dhcp-boot) out of their dedicated fields and into DHCP options, which frees up extra space in the DHCP packet for options. Sounds slay, right? But it can rarely confuse old or broken clients ๐Ÿ˜ญ. This flag forces the "simple and safe" behaviour so those messy clients don't get their whole vibe wrecked.
  • --leasequery[=<addr>[/<prefix>]] โ€” turns on RFC 4388 leasequery โœจ. With this on, the dnsmasq DHCP server will answer LEASEQUERY messages coming from DHCP relays. If you give an address or a subnet, then only queries from a relay at that source are allowed โ€” very demure, very selective. Repeat the --leasequery option to specify multiple allowed sources. ๐Ÿ’–

To correctly answer lease queries it's necessary to stash extra data in the lease database, and that's also switched on by --leasequery. The extra fields (agent-info and vendorclass) are stored in the leases file in a somewhat backwards compatible manner โ€” like, mostly fine, not perfect.

Turning leasequery on and then off will not cause problems; the extra info just gets aged out of the database. BUT listen up because this is the important part ๐Ÿ‘‘: enabling leasequery in release 2.92 or later, storing leases which come via DHCP relays that add option-82 agent-info data, and then moving back to a pre-2.92 dnsmasq binary may cause problems reading the leases file. As of release 2.92, leasequery is only supported for DHCPv4. No DHCPv6, periodt.

  • --dhcp-relay=<local address>[,<server address>[#<server port>]][,<interface] โ€” this makes dnsmasq do DHCP relay ๐Ÿš€. The local address is an address allocated to an interface on the host running dnsmasq. All DHCP requests arriving on that interface get relayed to a remote DHCP server at the server address. You can relay from a single local address to multiple remote servers by using multiple --dhcp-relay configs with the same local address and different server addresses. A server address must be an IP literal address โ€” not a domain name, no names, IPs only ๐Ÿ’…. If the server address is omitted, the request gets forwarded by broadcast (IPv4) or multicast (IPv6). In that case the interface must be given and not be wildcard. The server address may specify a non-standard port to relay to. If you use that, then --dhcp-proxy should likely also be set, otherwise parts of the DHCP conversation which don't pass through the relay will be delivered to the wrong port. Messy. ๐Ÿ™ˆ

Access control for DHCP clients follows the same rules as for the DHCP server โ€” see --interface, --except-interface, etc. The optional interface name in the --dhcp-relay config has a different function: it controls on which interface DHCP replies from the server will be accepted. This is meant for configs with three interfaces: one being relayed from, a second connecting the DHCP server, and a third untrusted network (typically the wider internet ๐ŸŒ). It avoids the possibility of spoof replies arriving via that third interface. Very protective, we love that.

It's allowed to have dnsmasq act as a DHCP server on one set of interfaces and relay from a disjoint set of interfaces. But heads up: whilst it's quite possible to write configurations which appear to act as a server and a relay on the same interface, this is not supported โ€” the relay function will take precedence. No cap.

Both DHCPv4 and DHCPv6 relay is supported ๐Ÿ”ฅ. It's not possible to relay DHCPv4 to a DHCPv6 server or vice-versa. Apples to apples only.

The DHCP relay function for IPv6 includes the ability to snoop prefix-delegation from relayed DHCP transactions. See --dhcp-script for details. ๐Ÿ‘€

  • --dhcp-split-relay=<local address>,[<server address>[#<server port>]],<server-facing-interface>|<server-facing-address> โ€” a usefully enhanced version of DHCPv4 relay โœจ. Here's the lore: IPv4 DHCP normally uses a single address for two functions โ€” it's used by the DHCP server to determine which network to allocate an address on, and it's used as the address of the relay to which the server sends packets. Two jobs, one address. Iconic but also lowkey limiting.

This version of DHCP relay splits those functions apart ๐Ÿ’…. It uses the address of the server-facing relay interface, or a directly-specified address, as the address that the server talks to. The address of the client-facing interface (the first item in the config) is used to determine the client's subnet. The local address is also used as server-ID override so that the client always sends requests via the relay. The effect of all this? The server doesn't require a route to the client network, and the clients don't require a route to the server. Everyone's routing-free and thriving ๐Ÿฆ‹.

The third parameter is mandatory. If it's an interface name it cannot be a wildcard, and the same filtering as described in --dhcp-relay applies โ€” answers from the server must arrve via the specified interface (yes, that typo lives in the original, we keep it exactly ๐Ÿ’–). If the third parameter is an IP address it must be an address of a local interface which is routable from the server. In that case no filtering is done and the reply packets can arrive via any route.

If you're setting up a network where the client networks have limited routing, be careful about configuring the DHCP server โš ๏ธ. Dnsmasq, as DHCP server, will set the default route to the client-facing relay interface unless explicitly configured โ€” that's a sensible default, respectfully. The normal default DNS server (same address as the DHCP server) will not be appropriate when there's no route bewteen the two (another one of those original-page typos, preserved for accuracy ๐ŸŽ€), so this will have to be explicitly configured.

  • -U, --dhcp-vendorclass=set:<tag>,[enterprise:<IANA-enterprise number>,][<vendor-class>] โ€” maps a vendor-class string to a tag ๐Ÿท๏ธ. Most DHCP clients provide a "vendor class" which represents, in some sense, the type of host. This option maps vendor classes to tags so DHCP options can be selectively delivered to different classes of hosts. Example time, bestie:
--dhcp-vendorclass=set:printers,Hewlett-Packard JetDirect

will let you set options only for HP printers like so:

--dhcp-option=tag:printers,3,192.168.4.4

The vendor-class string is substring matched against the vendor-class supplied by the client, to allow fuzzy matching ๐Ÿซถ. The set: prefix is optional but allowed for consistency.

Note that in IPv6 only, vendorclasses are namespaced with an IANA-allocated enterprise number ๐Ÿ‘‘. This may be given with an enterprise: keyword, and it specifies that only vendorclasses matching the specified number should be searched. Similarly, an enterprise number may be given with no vendor-class string โ€” this always matches vendorclasses with the given enterprise number. Slay.

  • -j, --dhcp-userclass=set:<tag>,<user-class> โ€” maps a user-class string to a tag, with substring matching, just like vendor classes ๐Ÿ’œ. Most DHCP clients provide a "user class" which is configurable. This option maps user classes to tags so DHCP options can be selectively delivered to different classes of hosts. For instance, you can use this to set a different printer server for hosts in the class "accounts" than for hosts in the class "engineering". Different departments, different printers, no drama ๐ŸŒธ.
  • -4, --dhcp-mac=set:<tag>,<MAC address> โ€” maps a MAC address to a tag ๐ŸŒˆ. The MAC address may include wildcards โœจ. For example:
--dhcp-mac=set:3com,01:34:23:*:*:*

will set the tag "3com" for any host whose MAC address matches the pattern. Wildcards go crazy, we love a pattern match ๐Ÿ’….

  • --dhcp-circuitid=set:<tag>,<circuit-id>, --dhcp-remoteid=set:<tag>,<remote-id> โ€” maps RFC3046 relay agent options to tags ๐ŸŽ€. This data may be provided by DHCP relay agents. The circuit-id or remote-id is normally given as colon-separated hex, but it's also allowed to be a simple string. If an exact match is achieved between the circuit or agent ID and one provided by a relay agent, the tag is set. Exact only, no fuzzy here โ€” this is a strict queen ๐Ÿ‘‘.

Heads up: --dhcp-remoteid (but not --dhcp-circuitid) is supported in IPv6. ๐Ÿฆ‹

  • --dhcp-subscrid=set:<tag>,<subscriber-id> โ€” (IPv4 and IPv6 ๐Ÿ’–) maps RFC3993 subscriber-id relay agent options to tags. Underrated, does both versions, we stan a versatile option.
  • --dhcp-proxy[=<ip addr>]...... โ€” (IPv4 only ๐Ÿ™ˆ) okay so normally a DHCP relay agent is only used to forward the initial parts of a DHCP interaction to the DHCP server. Once a client is configured, it communicates directly with the server. That's undesirable if the relay agent is adding extra information to the DHCP packets โ€” such as the info used by --dhcp-circuitid and --dhcp-remoteid. Losing that info mid-conversation? Not the vibe ๐Ÿ˜ญ.

A full relay implementation can use the RFC 5107 serverid-override option to force the DHCP server to use the relay as a full proxy, with all packets passing through it ๐Ÿ”ฅ. This flag provides an alternative method of doing the same thing, for relays which don't support RFC 5107. Given alone, it manipulates the server-id for all interactions via relays. If a list of IP addresses is given, only interactions via relays at those addresses are affected. Selective, deliberate, main character energy โœจ.

  • --dhcp-match=set:<tag>,<option number>|option:<option name>|vi-encap:<enterprise>[,<value>] โ€” without <value>, sets <tag> if the client sends a DHCP option of the given number or name ๐Ÿ’…. With <value>, sets <tag> only if the client sends the option matching or containing <value>. Two modes, one option, iconic behavior ๐ŸŒŸ.

The value may be of the form "01:ff:*:02" in which case the value must match (obviously apart from the wildcards bestie) but the option that gets sent can have unmatched data past the end of the value. The value may also be of the same form as in --dhcp-option, in which case the option sent is treated as an array, and one element must match. So like, --dhcp-match=set:efi-ia32,option:client-arch,6 sets the tag efi-ia32 if the number 6 shows up in the list of architectures the client sent in option 93. (Check RFC 4578 for the deets, iykyk.) And if the value is a string, substring matching is used. โœจ

The special form with vi-encap:<enterprise number> matches against vendor-identifying vendor classes for the specified enterprise. Please see RFC 3925 for more details of these rare and interesting beasts. ๐Ÿฆ‹

  • --dhcp-name-match=set:<tag>,<name>[*] โ€” Sets a <tag> if the given <name> is supplied by a DHCP client. There may be a single trailing wildcard *, and it's got a glob meaning. Combined with dhcp-ignore or dhcp-ignore-names this gives you the ability to ignore certain clients by name, or disallow certain hostnames from being claimed by a client. ๐Ÿ’…
  • --tag-if=set:<tag>[,set:<tag>[,tag:<tag>[,tag:<tag>]]] โ€” Performs boolean operations on tags, fr. All the set:<tag> tags get set if all the tag:<tag> are already set (or unset when tag:!<tag> is used). If no tag:<tag> appears, the set:<tag> tags are set unconditionally. Any number of set: and tag: forms may appear, in any order. --tag-if lines are executed in order, so if the tag in tag:<tag> is a tag set by another --tag-if, the line which sets the tag must precede the line which tests it. ๐Ÿ‘‘

As an extension, the tag:<tag> clauses support limited wildcard matching, similar to the matching in the --interface directive. This allows the example --tag-if=set:ppp,tag:ppp* to set the tag ppp for all requests received on any matching interface (ppp0, ppp1, etc). And this can be used in conjunction with the tag:!<tag> format meaning that no tag matching the wildcard may be set. โœจ

  • -J, --dhcp-ignore=tag:<tag>[,tag:<tag>] โ€” When all the given tags appear in the tag set, ignore the host and do not allocate it a DHCP lease. byeeeee ๐Ÿ™ˆ
  • --dhcp-ignore-names[=tag:<tag>[,tag:<tag>]] โ€” When all the given tags appear in the tag set, ignore any hostname provided by the host. Note that, unlike --dhcp-ignore, it is permissible to supply no tags, in which case DHCP-client supplied hostnames are always ignored, and DHCP hosts are added to the DNS using only --dhcp-host configuration in dnsmasq, plus the contents of /etc/hosts and /etc/ethers. ๐Ÿ’€
  • --dhcp-generate-names=tag:<tag>[,tag:<tag>] โ€” (IPv4 only) Generates a name for DHCP clients which don't otherwise have one, using the MAC address expressed in hex, separated by dashes. Note that if a host provides a name, it will be used by preference to this, unless --dhcp-ignore-names is set. ๐ŸŽ€
  • --dhcp-broadcast[=tag:<tag>[,tag:<tag>]] โ€” (IPv4 only) When all the given tags appear in the tag set, always use broadcast to communicate with the host when it is unconfigured. It is permissible to supply no tags, in which case this is unconditional. Most DHCP clients which need broadcast replies set a flag in their requests so that this happens automatically โ€” some old BOOTP clients just don't, and that's their problem bestie. ๐Ÿ˜ญ
  • -M, --dhcp-boot=[tag:<tag>,]<filename>,[<servername>[,<server address>|<tftp_servername>]] โ€” (IPv4 only) Set BOOTP options to be returned by the DHCP server. Server name and address are optional: if not provided, the name is left empty, and the address is set to the address of the machine running dnsmasq. If dnsmasq is providing a TFTP service (see --enable-tftp) then only the filename is required here to enable network booting. ๐Ÿ”ฅ If the optional tag(s) are given, they must match for this configuration to be sent. Instead of an IP address, the TFTP server address can be given as a domain name which is looked up in /etc/hosts. This name can be associated in /etc/hosts with multiple IP addresses, which are used round-robin. This facility can be used to load balance the tftp load among a set of servers. slay.
  • --dhcp-sequential-ip โ€” Dnsmasq is designed to choose IP addresses for DHCP clients using a hash of the client's MAC address. This normally allows a client's address to remain stable long-term, even if the client sometimes lets its DHCP lease expire. In this default mode, IP addresses are distributed pseudo-randomly over the entire available address range. There are sometimes circumstances (typically server deployment) where it is more convenient to have IP addresses allocated sequentially, starting from the lowest available address, and setting this flag enables this mode. Note that in the sequential mode, clients which allow a lease to expire are much more likely to move IP address; for this reason it should not be generally used. โš ๏ธ
  • --dhcp-ignore-clid โ€” Dnsmasq reads the 'client identifier' (RFC 2131) option sent by clients (if available) to identify clients. This allows one to serve the same IP address for a host using several interfaces. Use this option to disable 'client identifier' reading, i.e. to always identify a host using the MAC address. ๐Ÿฆ‹
  • --pxe-service=[tag:<tag>,]<CSA>,<menu text>[,<basename>|<bootservicetype>][,<server address>|<server_name>] โ€” Most uses of PXE boot-ROMS simply allow the PXE system to obtain an IP address and then download the file specified by --dhcp-boot and execute it. However the PXE system is capable of more complex functions when supported by a suitable DHCP server. ๐Ÿ‘‘

This specifies a boot option which may appear in a PXE boot menu. <CSA> is client system type, and only services of the correct type will appear in a menu. The known types are x86PC, PC98, IA64_EFI, Alpha, Arc_x86, Intel_Lean_Client, IA32_EFI, x86-64_EFI, Xscale_EFI, BC_EFI, ARM32_EFI and ARM64_EFI; an integer may be used for other types. The parameter after the menu text may be a file name, in which case dnsmasq acts as a boot server and directs the PXE client to download the file by TFTP โ€” either from itself (--enable-tftp must be set for this to work) or another TFTP server if the final server address/name is given. Note that the "layer" suffix (normally .0) is supplied by PXE, and need not be added to the basename. Alternatively, the basename may be a filename, complete with suffix, in which case no layer suffix is added. If an integer boot service type, rather than a basename, is given, then the PXE client will search for a suitable boot service for that type on the network. This search may be done by broadcast, or direct to a server if its IP address/name is provided. If no boot service type or filename is provided (or a boot service type of 0 is specified) then the menu entry will abort the net boot procedure and continue booting from local media. The server address can be given as a domain name which is looked up in /etc/hosts. This name can be associated in /etc/hosts with multiple IP addresses, which are used round-robin. โœจ

  • --pxe-prompt=[tag:<tag>,]<prompt>[,<timeout>] โ€” Setting this provides a prompt to be displayed after PXE boot. If the timeout is given then after the timeout has elapsed with no keyboard input, the first available menu option will be automatically executed. If the timeout is zero then the first available menu item will be executed immediately. If --pxe-prompt is omitted the system will wait for user input if there are multiple items in the menu, but boot immediately if there is only one. See --pxe-service for details of menu items. ๐ŸŒธ

Dnsmasq supports PXE "proxy-DHCP" โ€” in this case another DHCP server on the network is responsible for allocating IP addresses, and dnsmasq simply provides the information given in --pxe-prompt and --pxe-service to allow netbooting. This mode is enabled using the proxy keyword in --dhcp-range. If the "other" DHCP server is on a remote network, it is possible, and useful, to configure dnsmasq as both a PXE proxy-DHCP server and a DHCP relay to the remote DHCP server. See --dhcp-relay for details. PXE is only supported over IPv4 at this time. ๐Ÿ’…

  • --dhcp-pxe-vendor=<vendor>[,...] โ€” According to UEFI and PXE specifications, DHCP packets between PXE clients and proxy PXE servers should have PXEClient in their vendor-class field. However, the firmware of computers from a few vendors is customized to carry a different identifier in that field. This option is used to consider such identifiers valid for identifying PXE clients. For instance
--dhcp-pxe-vendor=PXEClient,HW-Client

will enable dnsmasq to also provide proxy PXE service to those PXE clients with HW-Client as their identifier. ๐Ÿงš

  • -X, --dhcp-lease-max=<number> โ€” Limits dnsmasq to the specified maximum number of DHCP leases. The default is 1000. This limit is to prevent DoS attacks from hosts which create thousands of leases and use lots of memory in the dnsmasq process. ๐Ÿ›ก๏ธ
  • -K, --dhcp-authoritative โ€” Should be set when dnsmasq is definitely the only DHCP server on a network. For DHCPv4, it changes the behaviour from strict RFC compliance so that DHCP requests on unknown leases from unknown hosts are not ignored. This allows new hosts to get a lease without a tedious timeout under all circumstances. It also allows dnsmasq to rebuild its lease database without each client needing to reacquire a lease, if the database is lost. For DHCPv6 it controls the same behaviour as DHCPv4 with missing leases (except for the RFC uncompliance โ€” the DHCPv6 RFCs allow this behaviour if configured). It also sets the priority in replies to 255 (the maximum) instead of 0 (the minimum). periodt. ๐Ÿ‘‘
  • --dhcp-rapid-commit โ€” turns on the DHCPv4 Rapid Commit Option from RFC 4039, bestie. When it's on, dnsmasq answers a DHCPDISCOVER that's rocking a Rapid Commit option with a DHCPACK that also carries a Rapid Commit option, plus the fully committed address and config info. ๐ŸŽ€ Only enable it if the server is the only server for the subnet, or if there are multiple servers and every single one of them commits a binding for all clients. No half-measures.
  • --dhcp-alternate-port[=<server port>[,<client port>]] โ€” (IPv4 only) swaps the ports DHCP uses away from the default. Give it alone with no arguments and DHCP moves from 67 and 68 to 1067 and 1068. Give it one argument and that port number is the server port, with the port number plus one for the client. Give it two port numbers and you get full arbitrary control of both server and client ports. ๐Ÿ’…
  • -3, --bootp-dynamic[=<network-id>[,<network-id>]] โ€” (IPv4 only) lets dnsmasq dynamically allocate IP addresses to BOOTP clients. โš ๏ธ Use this one with care: every address handed to a BOOTP client is leased forever, so it becomes permanently unavailable for re-use by other hosts. If you give it with no tags, dynamic allocation is enabled unconditionally. With tags, it only kicks in when all the tags are set. You can repeat it with different tag sets.
  • -5, --no-ping โ€” (IPv4 only) by default the DHCP server tries to make sure an address isn't already in use before it hands it to a host, by sending an ICMP echo request (aka a "ping") to the address. If something replies, the address is taken and dnsmasq tries another. This flag disables that check entirely. ๐Ÿซฃ Use with caution, fr.
  • --log-dhcp โ€” extra logging for DHCP: logs all the options sent to DHCP clients and the tags used to determine them. Full transparency era. โœจ
  • --quiet-dhcp, --quiet-dhcp6, --quiet-ra, --quiet-tftp โ€” suppress logging of the routine, boring operation of these protocols. Errors and problems still get logged, no worries. --quiet-tftp does not treat file not found as an error. Note that --quiet-dhcp and quiet-dhcp6 get over-ridden by --log-dhcp. ๐Ÿ‘‘
  • -l, --dhcp-leasefile=<path> โ€” use the specified file to store DHCP lease information.
  • --dhcp-duid=<enterprise-id>,<uid> โ€” (IPv6 only) specify the server persistent UID that the DHCPv6 server will use. You normally don't need this, because dnsmasq creates a DUID automatically the first time it's needed. When you do give it, it hands dnsmasq the data it needs to create a DUID-EN type DUID. Heads up: once set, the DUID lives in the lease database, so to switch between DUID-EN and automatically created DUIDs (either direction), the lease database must be re-initialised. The enterprise-id is assigned by IANA, and the uid is a string of hex octets unique to a particular device. ๐Ÿ”ฅ
  • -6, --dhcp-script=<path> โ€” okay bestie, this one's a whole moment, sit down. Whenever a new DHCP lease is created, an old one is destroyed, or a TFTP file transfer completes, the executable you name here gets run. path must be an absolute pathname โ€” there's no PATH search, okay? The arguments passed to the process are "add", "old" or "del", the MAC address of the host (or DUID for IPv6), the IP address, and the hostname, if known.
    • "add" means a lease has been created.
    • "del" means it has been destroyed.
    • "old" is a notification of an existing lease when dnsmasq starts, or a change to the MAC address or hostname of an existing lease. (It's also used for lease length or expiry and client-id, if --leasefile-ro is set, and for lease expiry if --script-on-renewal is set.)

If the MAC address comes from a network type other than ethernet, the network type gets prepended, eg "06-01:23:45:67:89:ab" for token ring. The process runs as root (assuming dnsmasq was originally run as root) even if dnsmasq is configured to change UID to an unprivileged user. ๐Ÿ˜ณ

The environment is inherited from the invoker of dnsmasq, with some or all of the following variables added.

For both IPv4 and IPv6:

  • DNSMASQ_DOMAIN โ€” if the fully-qualified domain name of the host is known, this is set to the domain part. (Note that the hostname passed to the script as an argument is never fully-qualified.)
  • If the client provides a hostname: DNSMASQ_SUPPLIED_HOSTNAME
  • If the client provides user-classes: DNSMASQ_USER_CLASS0..DNSMASQ_USER_CLASSn
  • If dnsmasq was compiled with HAVE_BROKEN_RTC, then the length of the lease (in seconds) is stored in DNSMASQ_LEASE_LENGTH, otherwise the time of lease expiry is stored in DNSMASQ_LEASE_EXPIRES. The number of seconds until lease expiry is always stored in DNSMASQ_TIME_REMAINING.
  • DNSMASQ_DATA_MISSING is set to "1" during "old" events for existing leases generated at startup, to indicate that data not stored in the persistent lease database will not be present. This comprises everything other than IP address, hostname, MAC address, DUID, IAID and lease length or expiry time.
  • If a lease used to have a hostname, and that hostname is removed, an "old" event is generated with the new state of the lease (ie: no name), and the former name is provided in the environment variable DNSMASQ_OLD_HOSTNAME.
  • DNSMASQ_INTERFACE stores the name of the interface on which the request arrived; this is not set for "old" actions when dnsmasq restarts.
  • DNSMASQ_RELAY_ADDRESS is set if the client used a DHCP relay to contact dnsmasq and the IP address of the relay is known.
  • DNSMASQ_TAGS contains all the tags set during the DHCP transaction, separated by spaces.
  • DNSMASQ_LOG_DHCP is set if --log-dhcp is in effect.
  • DNSMASQ_REQUESTED_OPTIONS โ€” a string containing the decimal values in the Parameter Request List option, comma separated, if the parameter request list option is provided by the client.
  • DNSMASQ_MUD_URL โ€” the Manufacturer Usage Description URL if provided by the client. (See RFC8520 for details.)

For IPv4 only:

  • DNSMASQ_CLIENT_ID if the host provided a client-id.
  • DNSMASQ_CIRCUIT_ID, DNSMASQ_SUBSCRIBER_ID, DNSMASQ_REMOTE_ID if a DHCP relay-agent added any of these options.
  • If the client provides vendor-class: DNSMASQ_VENDOR_CLASS.

For IPv6 only:

  • If the client provides vendor-class: DNSMASQ_VENDOR_CLASS_ID, containing the IANA enterprise id for the class, and DNSMASQ_VENDOR_CLASS0..DNSMASQ_VENDOR_CLASSn for the data.
  • DNSMASQ_SERVER_DUID containing the DUID of the server โ€” this is the same for every call to the script.
  • DNSMASQ_IAID containing the IAID for the lease. If the lease is a temporary allocation, this is prefixed to 'T'.
  • DNSMASQ_MAC containing the MAC address of the client, if known.
Note: the supplied hostname, vendorclass and userclass data is only supplied for "add" actions, or for "old" actions when a host resumes an existing lease, since these data are not held in dnsmasq's lease database. ๐Ÿซถ

All file descriptors are closed except stdin, which is open to /dev/null, and stdout and stderr, which capture output for logging by dnsmasq. (In debug mode, stdio, stdout and stderr file are left as those inherited from the invoker of dnsmasq.)

The script is not invoked concurrently: at most one instance of the script is ever running (dnsmasq waits for an instance of the script to exit before running the next). Changes to the lease database which require the script to be invoked are queued, awaiting exit of a running instance. If this queueing allows multiple state changes to occur to a single lease before the script can be run, then earlier states are discarded and the current state of that lease is reflected when the script finally runs. ๐Ÿงš

At dnsmasq startup, the script will be invoked for all existing leases as they are read from the lease file. Expired leases will be called with "del" and others with "old". When dnsmasq receives a HUP signal, the script will be invoked for existing leases with an "old" event.

There are five further actions which may appear as the first argument to the script: "init", "arp-add", "arp-del", "relay-snoop" and "tftp". More may be added in the future, so scripts should be written to ignore unknown actions. "init" is described below in --leasefile-ro.

  • The "tftp" action is invoked when a TFTP file transfer completes: the arguments are the file size in bytes, the address to which the file was sent, and the complete pathname of the file.
  • The "relay-snoop" action is invoked when dnsmasq is configured as a DHCP relay for DHCPv6 and it relays a prefix delegation to a client. The arguments are the name of the interface where the client is connected, its (link-local) address on that interface, and the delegated prefix. This information is sufficient to install routes to the delegated prefix of a router. See --dhcp-relay for more details on configuring DHCP relay.
  • The "arp-add" and "arp-del" actions are only called if enabled with --script-arp. They are supplied with a MAC address and IP address as arguments. "arp-add" indicates the arrival of a new entry in the ARP or neighbour table, and "arp-del" indicates the deletion of same. ๐ŸŒˆ
  • --dhcp-luascript=<path> โ€” specify a script written in Lua, to be run when leases are created, destroyed or changed. To use this option, dnsmasq must be compiled with the correct support. The Lua interpreter is initialised once, when dnsmasq starts, so that global variables persist between lease events. The Lua code must define a lease function, and may provide init and shutdown functions, which are called, without arguments, when dnsmasq starts up and terminates. It may also provide a tftp function. ๐Ÿฆ‹

The lease function receives the information detailed in --dhcp-script. It gets two arguments, bestie: first the action, which is a string containing "add", "old" or "del", and second a table of tag/value pairs. The tags mostly correspond to the environment variables detailed above โ€” for instance the tag domain holds the same data as the environment variable DNSMASQ_DOMAIN. There are a few extra tags which hold the data supplied as arguments to --dhcp-script. Those are mac_address, ip_address and hostname for IPv4, and client_duid, ip_address and hostname for IPv6. ๐Ÿ’…

The tftp function is called in the same way as the lease function, and the table holds the tags destination_address, file_name and file_size.

The arp and arp-old functions are called only when enabled with --script-arp and have a table which holds the tags mac_address and client_address.


  • --dhcp-scriptuser โ€” specify the user as which to run the lease-change script or Lua script. This defaults to root, but can be changed to another user using this flag. โœจ
  • --script-arp โ€” enable the "arp" and "arp-old" functions in the --dhcp-script and --dhcp-luascript.
  • -9, --leasefile-ro โ€” completely suppress use of the lease database file. The file will not be created, read, or written. Change the way the lease-change script (if one is provided) is called, so that the lease database may be maintained in external storage by the script. In addition to the invocations given in --dhcp-script the lease-change script is called once, at dnsmasq startup, with the single argument "init". When called like this the script should write the saved state of the lease database, in dnsmasq leasefile format, to stdout and exit with zero exit code. Setting this option also forces the leasechange script to be called on changes to the client-id and lease length and expiry time. ๐Ÿซถ
  • --script-on-renewal โ€” call the DHCP script when the lease expiry time changes, for instance when the lease is renewed.
  • --bridge-interface=<interface>,<alias>[,<alias>] โ€” treat DHCP (v4 and v6) requests and IPv6 Router Solicit packets arriving at any of the <alias> interfaces as if they had arrived at <interface>. This option allows dnsmasq to provide DHCP and RA service over unaddressed and unbridged Ethernet interfaces, e.g. on an OpenStack compute host where each such interface is a TAP interface to a VM, or as in "old style bridging" on BSD platforms. A trailing '*' wildcard can be used in each <alias>.

It is permissible to add more than one alias using more than one --bridge-interface option since --bridge-interface=int1,alias1,alias2 is exactly equivalent to --bridge-interface=int1,alias1 --bridge-interface=int1,alias2

  • --shared-network=<interface>,<addr>
  • --shared-network=<addr>,<addr> โ€” the DHCP server determines which DHCP ranges are useable for allocating an address to a DHCP client based on the network from which the DHCP request arrives, and the IP configuration of the server's interface on that network. The shared-network option extends the available subnets (and therefore DHCP ranges) beyond the subnets configured on the arrival interface.

The first argument is either the name of an interface, or an address that is configured on a local interface, and the second argument is an address which defines another subnet on which addresses can be allocated.

To be useful, there must be a suitable dhcp-range which allows address allocation on this subnet and this dhcp-range MUST include the netmask.

Using shared-network also needs extra consideration of routing. Dnsmasq does not have the usual information that it uses to determine the default route, so the default route option (or other routing) MUST be configured manually. The client must have a route to the server: if the two-address form of shared-network is used, this needs to be to the first specified address. If the interface,address form is used, there must be a route to all of the addresses configured on the interface.

The two-address form of shared-network is also usable with a DHCP relay: the first address is the address of the relay and the second, as before, specifies an extra subnet which addresses may be allocated from.

  • -s, --domain=<domain>[[,<address range>[,local]]|<interface>] โ€” specifies DNS domains for the DHCP server. Domains may be given unconditionally (without the IP range) or for limited IP ranges. This has two effects; firstly it causes the DHCP server to return the domain to any hosts which request it, and secondly it sets the domain which it is legal for DHCP-configured hosts to claim. The intention is to constrain hostnames so that an untrusted host on the LAN cannot advertise its name via DHCP as e.g. "microsoft.com" and capture traffic not meant for it. If no domain suffix is specified, then any DHCP hostname with a domain part (ie with a period) will be disallowed and logged. If suffix is specified, then hostnames with a domain part are allowed, provided the domain part matches the suffix. In addition, when a suffix is set then hostnames without a domain part have the suffix added as an optional domain part. Eg on my network I can set --domain=thekelleys.org.uk and have a machine whose DHCP hostname is "laptop". The IP address for that machine is available from dnsmasq both as "laptop" and "laptop.thekelleys.org.uk". If the domain is given as "#" then the domain is read from the first "search" directive in /etc/resolv.conf (or equivalent).

The address range can be of the form <ip address>,<ip address> or <ip address>/<netmask> or just a single <ip address>. See --dhcp-fqdn which can change the behaviour of dnsmasq with domains.

If the address range is given as ip-address/network-size, then an additional flag "local" may be supplied which has the effect of adding --local declarations for forward and reverse DNS queries. Eg. --domain=thekelleys.org.uk,192.168.0.0/24,local is identical to --domain=thekelleys.org.uk,192.168.0.0/24 --local=/thekelleys.org.uk/ --local=/0.168.192.in-addr.arpa/

The address range can also be given as a network interface name, in which case all of the subnets currently assigned to the interface are used in matching the address. This allows hosts on different physical subnets to be given different domains in a way which updates automatically as the interface addresses change. ๐ŸŒˆ

  • --dhcp-fqdn โ€” in the default mode, dnsmasq inserts the unqualified names of DHCP clients into the DNS. For this reason, the names must be unique, even if two clients which have the same name are in different domains. If a second DHCP client appears which has the same name as an existing client, the name is transferred to the new client. If --dhcp-fqdn is set, this behaviour changes: the unqualified name is no longer put in the DNS, only the qualified name. Two DHCP clients with the same name may both keep the name, provided that the domain part is different (ie the fully qualified names differ.) To ensure that all names have a domain part, there must be at least --domain without an address specified when --dhcp-fqdn is set.
  • --dhcp-client-update โ€” normally, when giving a DHCP lease, dnsmasq sets flags in the FQDN option to tell the client not to attempt a DDNS update with its name and IP address. This is because the name-IP pair is automatically added into dnsmasq's DNS view. This flag suppresses that behaviour, this is useful, for instance, to allow Windows clients to update Active Directory servers. See RFC 4702 for details. โœจ
  • --enable-ra โ€” enable dnsmasq's IPv6 Router Advertisement feature. DHCPv6 doesn't handle complete network configuration in the same way as DHCPv4. Router discovery and (possibly) prefix discovery for autonomous address creation are handled by a different protocol. When DHCP is in use, only a subset of this is needed, and dnsmasq can handle it, using existing DHCP configuration to provide most data. When RA is enabled, dnsmasq will advertise a prefix for each --dhcp-range, with default router as the relevant link-local address on the machine running dnsmasq. By default, the "managed address" bits are set, and the "use SLAAC" bit is reset. This can be changed for individual subnets with the mode keywords described in --dhcp-range. RFC6106 DNS parameters are included in the advertisements. By default, the relevant link-local address of the machine running dnsmasq is sent as recursive DNS server. If provided, the DHCPv6 options dns-server and domain-search are used for the DNS server (RDNSS) and the domain search list (DNSSL). ๐Ÿ‘‘
  • --ra-param=<interface>,[mtu:<integer>|<interface>|off,][high,|low,]<ra-interval>[,<router lifetime>] โ€” set non-default values for router advertisements sent via an interface. The priority field for the router may be altered from the default of medium with eg --ra-param=eth0,high. The interval between router advertisements may be set (in seconds) with --ra-param=eth0,60. The lifetime of the route may be changed or set to zero, which allows a router to advertise prefixes but not a route via itself. --ra-param=eth0,0,0 (a value of zero for the interval means the default value.) All four parameters may be set at once. --ra-param=eth0,mtu:1280,low,60,1200

The interface field may include a wildcard.

The mtu: parameter may be an arbitrary interface name, in which case the MTU value for that interface is used. This is useful for (eg) advertising the MTU of a WAN interface on the other interfaces of a router. ๐Ÿฆ‹

  • --dhcp-reply-delay=[tag:<tag>,]<integer> โ€” bestie, this one holds back your DHCPOFFER and PROXYDHCP replies for at least however many seconds you say. Why would anyone do that? Because some PXE boot firmware is a whole mess ๐Ÿ˜ญ and just cannot cope when a reply lands instantly, so this is the workaround. And the icon behavior: it counts the time you've already burned (like doing a ping check) toward that total, so you're not double-waiting. ๐Ÿ’…
  • --enable-tftp[=<interface>[,<interface>]] โ€” turn the TFTP server ON, no cap ๐ŸŽ€. It's deliberately kept to the bare minimum needed to net-boot a client. Reading only โ€” you can't write anything. The tsize and blksize extensions are supported, and heads up: tsize only works in octet mode. No argument? Then TFTP serves the exact same set of interfaces as DHCP service. Give it a list of interfaces and that's what gets TFTP service. Simple as. โœจ
  • --tftp-root=<directory>[,<interface>] โ€” where should TFTP look for files to transfer? Relative to the directory you drop here. The second you set this, any TFTP path containing ".." gets rejected โ€” that's the whole point, stopping clients from sneaking outside your root. ๐Ÿ’€ Absolute paths (starting with /) are allowed, but they must live inside the tftp-root. And if you pass the optional interface arg, that directory only gets used for TFTP requests coming through that interface.
  • --tftp-no-fail โ€” don't abort startup if the tftp root directories you named are inaccessible. Graceful. ๐Ÿซถ
  • --tftp-unique-root[=ip|mac] โ€” this one slaps: it tacks the TFTP client's IP or hardware address onto the end of the TFTP-root as a path component. Only valid if a --tftp-root is set and the directory exists. Defaults to adding the IP address in standard dotted-quad format. Example time, so you get it fr: if --tftp-root is "/tftp" and client 1.2.3.4 asks for file "myfile", the effective path is "/tftp/1.2.3.4/myfile" if /tftp/1.2.3.4 exists โ€” and /tftp/myfile otherwise. When you say =mac it appends the MAC address instead, in lowercase zero-padded digits separated by dashes, like: 01-02-03-04-aa-bb. โญ Note that resolving MAC addresses is only possible if the client is on the local network or got a DHCP lease from us.
  • --tftp-secure โ€” TFTP secure mode, activate ๐ŸŽ€. Without it, literally any file the dnsmasq process can read under normal unix access-control rules is available via TFTP. Yikes. With the --tftp-secure flag, only files owned by the user running the dnsmasq process are accessible. But if dnsmasq is running as root, different rules apply: --tftp-secure has no effect, and only files with the world-readable bit set are accessible. It is not recommended to run dnsmasq as root with TFTP enabled, and certainly not without specifying --tftp-root. Doing so can expose any world-readable file on the server to any host on the net. That's a red flag, bestie. Don't do it. ๐Ÿšจ
  • --tftp-lowercase โ€” convert filenames in TFTP requests to all lowercase. Useful for requests from Windows machines, which have case-insensitive filesystems and tend to play fast-and-loose with case in filenames. ๐Ÿ™ˆ Also note: dnsmasq's tftp server always converts "\" to "/" in filenames.
  • --tftp-max=<connections> โ€” cap on concurrent TFTP connections. Defaults to 50. When you're serving a lot of TFTP connections, per-process file descriptor limits may show up and ruin the vibe. Dnsmasq needs one file descriptor for each concurrent TFTP connection and one file descriptor per unique file (plus a few others). So serving the same file simultaneously to n clients takes about n + 10 file descriptors, and serving different files simultaneously to n clients takes about (2*n) + 10 descriptors. And if --tftp-port-range is given, that can affect the number of concurrent connections. Numbers don't lie. ๐Ÿ”ฅ
  • --tftp-mtu=<mtu size> โ€” use size as the ceiling of the MTU supported by the intervening network when negotiating TFTP blocksize, overriding the MTU setting of the local interface if it's larger.
  • --tftp-no-blocksize โ€” stops the TFTP server from negotiating the "blocksize" option with a client. Some buggy clients request this option and then behave badly when it's granted, so this is your fix. Not their fault, but also... ๐Ÿ™„
  • --tftp-port-range=<start>,<end> โ€” a TFTP server listens on a well-known port (69) for connection initiation, but it also uses a dynamically-allocated port for each connection. Normally the OS allocates those, but this option specifies a range of ports for TFTP transfers. Useful when TFTP has to traverse a firewall. ๐Ÿงš The start of the range cannot be lower than 1025 unless dnsmasq is running as root. And heads up: the number of concurrent TFTP connections is limited by the size of the port range.
  • --tftp-single-port โ€” run in a mode where the TFTP server uses ONLY the well-known port (69) for its end of the TFTP transfer. This lets TFTP work when there's a NAT in the path between client and server. ๐Ÿซถ But note that this is not strictly compliant with the RFCs specifying the TFTP protocol: use at your own risk. ๐Ÿ’€
  • -C, --conf-file=<file> โ€” specify a configuration file. The presence of this option stops dnsmasq from reading the default configuration file (normally /etc/dnsmasq.conf). You can specify multiple files by repeating the option โ€” either on the command line or in configuration files. And a filename of "-" makes dnsmasq read configuration from stdin. Cute. โœจ
  • -7, --conf-dir=<directory>[,<file-extension>......], โ€” read all the files in the given directory as configuration files. If extension(s) are given, any files that end in those extensions are skipped. Any files whose names end in ~ or start with . or start and end with # are always skipped. If the extension starts with * then only files with that extension are loaded. So --conf-dir=/path/to/dir,*.conf loads all files with the suffix .conf in /path/to/dir. This flag may be given on the command line or in a configuration file. If you're giving it on the command line, be sure to escape * characters โ€” the shell will eat them otherwise ๐Ÿ˜ญ. Files are loaded in alphabetical order of filename.
  • --servers-file=<file> โ€” a special case of --conf-file that differs in two respects. First: only --server and --rev-server are allowed in the configuration file included. Second: the file is re-read and the configuration therein is updated when dnsmasq receives SIGHUP. Live updates, we love to see it. ๐Ÿ’…
  • --conf-script=<file>[ <arg] โ€” execute file, and treat whatever it emits to stdout as the contents of a configuration file. If the script exits with a non-zero exit code, dnsmasq treats this as a fatal error. The script can be passed arguments, space separated from the filename and each other, so for instance:
--conf-dir="/etc/dnsmasq-uncompress-ads /share/ads-domains.gz"

with /etc/dnsmasq-uncompress-ads containing:

set -e

zcat ${1} | sed -e "s:^:address=/:" -e "s:$:/:"

exit 0

and /share/ads-domains.gz containing a compressed list of ad server domains, this saves disk space with large ad-server blocklists. Iconic problem-solving ngl. ๐Ÿ‘‘

  • --no-ident โ€” do not respond to class CHAOS and type TXT in domain bind queries.

Without this option being set, the cache statistics are also available in the DNS as answers to queries of class CHAOS and type TXT in bind. The domain names are cachesize.bind, insertions.bind, evictions.bind, misses.bind, hits.bind, auth.bind and servers.bind โ€” unless disabled at compile-time. An example command to query this, using the dig utility, would be:

dig +short chaos txt cachesize.bind
  • --max-tcp-connections=<number> โ€” the maximum number of concurrent TCP connections. The application forks to handle each TCP request. The default maximum is 20.

๐ŸŽ€ CONFIG FILE ๐ŸŽ€

At startup, dnsmasq reads /etc/dnsmasq.conf, if it exists. (On FreeBSD, the file is /usr/local/etc/dnsmasq.conf.) (But see the --conf-file and --conf-dir options. ๐Ÿ‘€)

The format of this file: one option per line, exactly as the long options detailed in the OPTIONS section, but without the leading --. Lines starting with # are comments and get ignored. ๐Ÿ’…

For options which may only be specified once, the configuration file overrides the command line. Yep, fr fr.

Quoting is allowed in a config file: between " quotes the special meanings of ,:. and # are removed, and the following escapes are allowed: \\ \" \t \e \b \r and \n. The latter corresponding to tab, escape, backspace, return and newline. ๐ŸŒˆ

๐Ÿ“ NOTES ๐Ÿ“

okay bestie, this is the section where we talk about signals, vibes and how the whole thing actually holds together. buckle up ๐Ÿ”ฅ


๐Ÿ’Œ signal time: what happens when you poke dnsmasq

  • SIGHUP โ€” when it gets one of these, dnsmasq clears its cache and then re-loads /etc/hosts and /etc/ethers and any file given by --dhcp-hostsfile, --dhcp-hostsdir, --dhcp-optsfile, --dhcp-optsdir, --addn-hosts or --hostsdir. The DHCP lease change script is called for all existing DHCP leases. If --no-poll is set, SIGHUP also re-reads /etc/resolv.conf. SIGHUP does NOT re-read the configuration file. (yes, for real. cry about it.)
  • SIGUSR1 โ€” dnsmasq writes statistics to the system log. It writes the cache size, the number of names which have had to removed from the cache before they expired in order to make room for new names and the total number of names that have been inserted into the cache. The number of cache hits and misses and the number of authoritative queries answered are also given. For each upstream server it gives the number of queries sent, and the number which resulted in an error. It also gives information on the number of forks for TCP connections. In --no-daemon mode or when full logging is enabled (--log-queries), a complete dump of the contents of the cache is made. ๐Ÿ“Šโœจ
  • SIGUSR2 โ€” when it receives this and it is logging direct to a file (see --log-facility) dnsmasq will close and reopen the log file. Heads up tho: during this operation, dnsmasq will not be running as root. When it first creates the logfile dnsmasq changes the ownership of the file to the non-root user it will run as. Logrotate should be configured to create a new log file with the ownership which matches the existing one before sending SIGUSR2. If TCP DNS queries are in progress, the old logfile will remain open in child processes which are handling TCP queries and may continue to be written. There is a limit of 150 seconds, after which all existing TCP processes will have expired: for this reason, it is not wise to configure logfile compression for logfiles which have just been rotated. Using logrotate, the required options are create and delaycompress.

๐ŸŒ the whole DNS-forwarder situation

Dnsmasq is a DNS query forwarder: it is not capable of recursively answering arbitrary queries starting from the root servers but forwards such queries to a fully recursive upstream DNS server which is typically provided by an ISP. ๐Ÿ’…

By default, dnsmasq reads /etc/resolv.conf to discover the IP addresses of the upstream nameservers it should use, since the information is typically stored there. Unless --no-poll is used, dnsmasq checks the modification time of /etc/resolv.conf (or equivalent if --resolv-file is used) and re-reads it if it changes. This allows the DNS servers to be set dynamically by PPP or DHCP since both protocols provide the information. ๐ŸŒˆ

Absence of /etc/resolv.conf is not an error since it may not have been created before a PPP connection exists. Dnsmasq simply keeps checking in case /etc/resolv.conf is created at any time. lowkey patient icon.

Dnsmasq can be told to parse more than one resolv.conf file. This is useful on a laptop, where both PPP and DHCP may be used: dnsmasq can be set to poll both /etc/ppp/resolv.conf and /etc/dhcpc/resolv.conf and will use the contents of whichever changed last, giving automatic switching between DNS servers. ๐Ÿฆ‹ main character energy fr.

Upstream servers may also be specified on the command line or in the configuration file. These server specifications optionally take a domain name which tells dnsmasq to use that server only to find names in that particular domain.


๐Ÿ  making dnsmasq the cache for the box it's on

In order to configure dnsmasq to act as cache for the host on which it is running, put "nameserver 127.0.0.1" in /etc/resolv.conf to force local processes to send queries to dnsmasq.

Then either specify the upstream servers directly to dnsmasq using --server options or put their addresses real in another file, say /etc/resolv.dnsmasq and run dnsmasq with the --resolv-file /etc/resolv.dnsmasq option. This second technique allows for dynamic update of the server addresses by PPP or DHCP. ๐ŸŽ€


๐Ÿซฅ shadowing, aka /etc/hosts said "mine now"

Addresses in /etc/hosts will "shadow" different addresses for the same names in the upstream DNS, so "mycompany.com 1.2.3.4" in /etc/hosts will ensure that queries for "mycompany.com" always return 1.2.3.4 even if queries in the upstream DNS would otherwise return a different address. iconic behaviour honestly.

There is one exception to this: if the upstream DNS contains a CNAME which points to a shadowed name, then looking up the CNAME through dnsmasq will result in the unshadowed address associated with the target of the CNAME. To work around this, add the CNAME to /etc/hosts so that the CNAME is shadowed too. ๐Ÿ’€ gotcha.


๐Ÿท๏ธ the tag system, explained (bestie edition)

The tag system works as follows: dnsmasq tags each DHCP request with tags from applicable configuration lines containing set:<tag> i.e.

  • set:<tag> from the --dhcp-range used to allocate the address;
  • set:<tag> from any matching --dhcp-host (plus the tag known or known-othernet).

BOOTP requests are tagged bootp. Each request is also tagged with the name of the interface on which the request arrived.

Each configuration line containing one or more tag:<tag> constructs applies when all its tags exist on the request. That is:

  • Configuration tag:A applies to a request set:tagged A.
  • Configuration tag:B applies to a request set:tagged B.
  • Configuration tag:A+B doesn't apply to a request set:tagged A.
  • Configuration tag:A+B doesn't apply to a request set:tagged B.
  • Configurations tag:A+B, tag:A, tag:B apply to a request set:tagged A+B.

set:<tag> constructs in --dhcp-range and --dhcp-host tag requests.

Use tag:<tag>s in --dhcp-options to match set:<tag> and apply configurations.

A --dhcp-option with tag:<tag> is preferred over an untagged --dhcp-option, provided that all its tags match somewhere in the set gathered above.

The tag prefix '!' means 'not'. --dhcp-option=tag:!purple,3,1.2.3.4 sends the option when the request is not tagged with purple. (The shell metacharacter '!' must be escaped on the command line but not in a configuration file). ๐ŸŒธ

When selecting --dhcp-options, a --dhcp-range tag is second class to other tags, to make it easy to override options for individual hosts, so:

--dhcp-range=set:interface1,......

--dhcp-host=set:myhost,.....

--dhcp-option=tag:interface1,option:nis-domain,"domain1"

--dhcp-option=tag:myhost,option:nis-domain,"domain2"

sets the NIS-domain to domain1 for hosts in the range, but to domain2 for a particular host that may or may not fall in the range. slay โœจ

Note that for --dhcp-range both tag:<tag> and set:<tag> are possible, in order to both select the range in use based on (eg) --dhcp-host, and to affect the options sent, based on the range selected.

The tag system evolved from an earlier, more limited system. For backward compatibility, "net:" may be used instead of "tag:" and "set:" may be omitted. (Except in --dhcp-host, where "net:" may be used instead of "set:".) For the same reason, '#' may be used instead of '!' to indicate NOT. ๐Ÿงš


๐Ÿฅพ BOOTP? also yes

The DHCP server in dnsmasq will function as a BOOTP server also, provided that the MAC address and IP address for clients are given, either using --dhcp-host configurations or in /etc/ethers, and a --dhcp-range configuration option is present to activate the DHCP server on a particular network. (Setting --bootp-dynamic removes the need for static address mappings.) The filename parameter in a BOOTP request is used as a tag, as is the tag bootp, allowing some control over the options returned to different classes of hosts. ๐Ÿ‘‘


๐Ÿ‘‘ AUTHORITATIVE CONFIGURATION ๐Ÿ‘‘

okay bestie, setting dnsmasq up as an authoritative DNS server is a lil complicated, and here's why: it lowkey involves configuring external DNS servers to do the delegation. so we're gonna walk through three scenarios, getting more complex as we go, fr fr. ๐Ÿ”ฅ

Prerequisites for all three of them:

  • a globally accessible IP address
  • an A or AAAA record pointing to that address
  • an external DNS server that can actually do delegation of the zone in question

For the first part of this whole explanation, we're calling the A (or AAAA) record for the globally accessible address server.example.com, and the zone dnsmasq is authoritative for our.zone.com. ๐Ÿ’…


โœจ Scenario One: the simplest one โœจ

The simplest configuration is literally just two lines of dnsmasq config, something like:

--auth-server=server.example.com,eth0
--auth-zone=our.zone.com,1.2.3.0/24

...and two records in the external DNS:

server.example.com       A    192.0.43.10
our.zone.com            NS    server.example.com

eth0 is the external network interface dnsmasq is listening on, and it has the (globally accessible) address 192.0.43.10. no cap. ๐ŸŒธ

Heads up bestie: that external IP address may very well be dynamic (i.e. assigned from an ISP by DHCP or PPP). if so, the A record has to be linked to this dynamic assignment by one of the usual dynamic-DNS systems. ๐Ÿ™ˆ

๐Ÿ’– Scenario Two: the practically-useful one ๐Ÿ’–

A more complex, but practically useful configuration has the address record for the globally accessible IP address living inside the authoritative zone dnsmasq is serving, typically at the root. So now we've got:

--auth-server=our.zone.com,eth0
--auth-zone=our.zone.com,1.2.3.0/24
our.zone.com             A    1.2.3.4
our.zone.com            NS    our.zone.com

The A record for our.zone.com has now become a glue record โ€” it solves the chicken-and-egg problem of finding the IP address of the nameserver for our.zone.com when the A record is within that zone. iconic. ๐ŸŽ€

Note that this is the only role of this record: since dnsmasq is now authoritative from our.zone.com, it too must provide this record. If the external address is static, you can do it with an /etc/hosts entry or --host-record:

--auth-server=our.zone.com,eth0
--host-record=our.zone.com,1.2.3.4
--auth-zone=our.zone.com,1.2.3.0/24

If the external address is dynamic, the address associated with our.zone.com must be derived from the address of the relevant interface. This is done using --interface-name. Something like:

--auth-server=our.zone.com,eth0
--interface-name=our.zone.com,eth0
--auth-zone=our.zone.com,1.2.3.0/24,eth0

(The "eth0" argument in --auth-zone adds the subnet containing eth0's dynamic address to the zone, so that the --interface-name returns the address in outside queries.) ๐Ÿฆ‹


๐ŸŒˆ Scenario Three: adding a secondary ๐ŸŒˆ

Our final configuration builds on that one above, but also adds a secondary DNS server. This is another DNS server which learns the DNS data for the zone by doing zone transfer, and acts as a backup should the primary server become inaccessible. The configuration of the secondary is beyond the scope of this man-page, but the extra configuration of dnsmasq is simple:

--auth-sec-servers=secondary.myisp.com

and

our.zone.com           NS    secondary.myisp.com

Adding auth-sec-servers enables zone transfer in dnsmasq, to allow the secondary to collect the DNS data. If you wish to restrict this data to particular hosts, then

--auth-peer=<IP address of secondary>

will do so. ๐Ÿ’…


Dnsmasq acts as an authoritative server for in-addr.arpa and ip6.arpa domains associated with the subnets given in --auth-zone declarations, so reverse (address to name) lookups can be simply configured with a suitable NS record. for instance, in this example where we allow 1.2.3.0/24 addresses:

 3.2.1.in-addr.arpa  NS    our.zone.com
note that at present, reverse (in-addr.arpa and ip6.arpa) zones are not available in zone transfers, so there's genuinely no point arranging secondary servers for reverse lookups. ๐Ÿ˜ญ

๐Ÿงš What data populates the authoritative zone ๐Ÿงš

When dnsmasq is configured to act as an authoritative server, the following data is used to populate the authoritative zone. ๐Ÿ’–

  • --mx-host, --srv-host, --dns-rr, --txt-record, --naptr-record, --caa-record, as long as the record names are in the authoritative domain.
  • --synth-domain as long as the domain is in the authoritative zone and, for reverse (PTR) queries, the address is in the relevant subnet.
  • --cname as long as the record name is in the authoritative domain. If the target of the CNAME is unqualified, then it is qualified with the authoritative zone name. CNAME used in this way (only) may be wildcards, as in:
--cname=*.example.com,default.example.com
  • IPv4 and IPv6 addresses from /etc/hosts (and --addn-hosts) and --host-record and --interface-name and ---dynamic-host provided the address falls into one of the subnets specified in the --auth-zone.
  • Addresses of DHCP leases, provided the address falls into one of the subnets specified in the --auth-zone. (If constructed DHCP ranges are is use, which depend on the address dynamically assigned to an interface, then the form of --auth-zone which defines subnets by the dynamic address of an interface should be used to ensure this condition is met.)

In the default mode, where a DHCP lease has an unqualified name, and possibly a qualified name constructed using --domain, then the name in the authoritative zone is constructed from the unqualified name and the zone's domain. This may or may not equal that specified by --domain. If --dhcp-fqdn is set, then the fully qualified names associated with DHCP leases are used, and must match the zone's domain. โœจ


๐Ÿ’€ EXIT CODES ๐Ÿ’€

  • 0 โ€” Dnsmasq successfully forked into the background, or terminated normally if backgrounding is not enabled.
  • 1 โ€” A problem with configuration was detected.
  • 2 โ€” A problem with network access occurred (address in use, attempt to use privileged ports without permission).
  • 3 โ€” A problem occurred with a filesystem operation (missing file/directory, permissions).
  • 4 โ€” Memory allocation failure.
  • 5 โ€” Other miscellaneous problem.
  • 11 or greater โ€” a non zero return code was received from the lease-script process "init" call or a --conf-script file. The exit code from dnsmasq is the script's exit code with 10 added.

๐ŸŒŸ LIMITS ๐ŸŒŸ

The default values for resource limits in dnsmasq are generally conservative, and appropriate for embedded router type devices with slow processors and limited memory. On more capable hardware, it is possible to increase the limits, and handle so many more clients. The following applies to dnsmasq-2.37: earlier versions did not scale as well. ๐Ÿ’…

Dnsmasq is capable of handling DNS and DHCP for at least a thousand clients. The DHCP lease times should not be very short (less than one hour). The value of --dns-forward-max can be increased: start with it equal to the number of clients and increase if DNS seems slow. Note that DNS performance depends too on the performance of the upstream nameservers. The size of the DNS cache may be increased: the hard limit is 10000 names and the default (150) is very low. Sending SIGUSR1 to dnsmasq makes it log information which is useful for tuning the cache size. See the NOTES section for details. ๐Ÿ‘‘

The built-in TFTP server is capable of many simultaneous file transfers: the absolute limit is related to the number of file-handles allowed to a process and the ability of the select() system call to cope with large numbers of file handles. If the limit is set too high using --tftp-max it will be scaled down and the actual limit logged at start-up. Note that more transfers are possible when the same file is being sent than when each transfer sends a different file. ๐Ÿ“

It is possible to use dnsmasq to block Web advertising by using a list of known banner-ad servers, all resolving to 127.0.0.1 or 0.0.0.0, in /etc/hosts or an additional hosts file. The list can be very long โ€” dnsmasq has been tested successfully with one million names. That size file needs a 1GHz processor and about 60Mb of RAM. ๐Ÿ”ฅ


๐ŸŒ INTERNATIONALISATION ๐ŸŒ

Dnsmasq can be compiled to support internationalisation. To do this, the make targets "all-i18n" and "install-i18n" should be used instead of the standard targets "all" and "install". When internationalisation is compiled in, dnsmasq will produce log messages in the local language and support internationalised domain names (IDN). Domain names in /etc/hosts, /etc/ethers and /etc/dnsmasq.conf which contain non-ASCII characters will be translated to the DNS-internal punycode representation. ๐Ÿฆ‹

Note that dnsmasq determines both the language for messages and the assumed charset for configuration files from the LANG environment variable. This should be set to the system default value by the script which is responsible for starting dnsmasq. When editing the configuration files, be careful to do so using only the system-default locale and not a user-specific one, since dnsmasq has no direct way of determining the charset in use, and must assume that it is the system default. ๐Ÿ™ˆ


๐ŸŽ€ FILES ๐ŸŽ€

  • /etc/dnsmasq.conf
  • /usr/local/etc/dnsmasq.conf
  • /etc/resolv.conf
  • /var/run/dnsmasq/resolv.conf
  • /etc/ppp/resolv.conf
  • /etc/dhcpc/resolv.conf
  • /etc/hosts
  • /etc/ethers
  • /var/lib/misc/dnsmasq.leases
  • /var/db/dnsmasq.leases
  • /var/run/dnsmasq.pid

๐Ÿ’œ SEE ALSO ๐Ÿ’œ

hosts(5), resolver(5)


๐Ÿซถ AUTHOR ๐Ÿซถ

This manual page was written by Simon Kelley <simon@thekelleys.org.uk>.


and that's a wrap bestie!! ๐ŸŽ‰ this iconic lil page is from DNSMASQ(8), dated 2025-02-05 โ€” go forth and slay your DNS, ily, bye! ๐Ÿ’–โœจ๐Ÿ‘‘๐ŸŒˆ

๐Ÿ“ฆ where this page comes from