Running multiple dnsmasq instances as DNS forwarder and/or DHCPv4 server, each having their own configuration and lease list can be configured by creating multiple dnsmasq sections.Typically in such configs each dnsmasq section will be bound to a specific interface by using the interface list; assigning sections like dhcp, host, etc. to a specific dnsmasq instance is done by the instance option.By default dnsmasq adds the loopback interface to the interface list to listen when the --interface option is used; therefore the loopback interface needs to be excluded in one of the dnsmasq instances by using the notinterface list.
These are example settings for multiple dnsmasq instances each having their own dhcp section.dnsmasq instance lan_dns is bound to the lan interface while the dnsmasq instance guest_dns is bound to the guest interface.
Note that we are not going the usual route to specify dhcp configs via /etc/config/dhcp, as the latter does not allow us to specify a dhcp-range without binding it to an interface. (This interface exists, except it is on the Mikrotik). Thus we feed it directly to dnsmasq, bypassing the openwrt configuration engine.
Dnsmasq accepts DNS queries and either answers them from a small, local,cache or forwards them to a real, recursive, DNS server. It loads thecontents of /etc/hosts so that local hostnameswhich do not appear in the global DNS can be resolved and also answersDNS queries for DHCP configured hosts.The dnsmasq DHCP server supports static address assignments, multiplenetworks, DHCP-relay and RFC3011 subnet specifiers. It automaticallysends a sensible default set of DHCP options, and can be configured tosend any desired set of DHCP options, including vendor-encapsulatedoptions. It includes a secure, read-only,TFTP server to allow net/PXE boot of DHCP hosts and also supports BOOTP.Dnsmasqsupports IPv6 for DNS, but not DHCP.OPTIONSNote that in general missing parameters are allowed and switch offfunctions, for instance \"--pid-file\" disables writing a PID file. OnBSD, unless the GNU getopt library is linked, the long form of theoptions does not work on the command line; it is still recognised inthe configuration file.TagDescription-h, --no-hosts Don’t read the hostnames in /etc/hosts.-H, --addn-hosts= Additional hosts file. Read the specified file as well as /etc/hosts. If -h is given, readonly the specified file. This option may be repeated for more than oneadditional hosts file.-E, --expand-hosts Add the domain to simple names (without a period) in /etc/hostsin the same way as for DHCP-derived names.-T, --local-ttl= When replying with information from /etc/hosts or the DHCP leasesfile dnsmasq by default sets the time-to-live field to zero, meaningthat the requestor should not itself cache the information. This isthe correct thing to do in almost all situations. This option allows atime-to-live (in seconds) to be given for these replies. This willreduce the load on the server at the expense of clients using staledata under some circumstances.--neg-ttl= Negative replies from upstream servers normally contain time-to-liveinformation in SOA records which dnsmasq uses for caching. If thereplies from upstream servers omit this information, dnsmasq does notcache the reply. This option gives a default value for time-to-live(in seconds) which dnsmasq uses to cache negative replies even inthe absence of an SOA record.-k, --keep-in-foreground Do not go into the background at startup but otherwise run asnormal. This is intended for use when dnsmasq is run under daemontoolsor 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 onSIGUSR1, log to stderr as well as syslog, don’t fork new processesto handle TCP queries.-q, --log-queries Log the results of DNS queries handled by dnsmasq. Enable a full cache dump on receipt of SIGUSR1.-8, --log-facility= Set the facility to which dnsmasq will send syslog entries, thisdefaults to DAEMON, and to LOCAL0 when debug mode is in operation. Ifthe facility given contains at least one ’/’ character, it is taken tobe a filename, and dnsmasq logs to the given file, instead ofsyslog. (Errors whilst reading configuration will still go to syslog,but all output from a successful startup, and all output whilstrunning, will go exclusively to the file.) When logging to a file,dnsmasq will close and reopen the file when it receives SIGUSR2. Thisallows the log file to be rotated without stopping dnsmasq.--log-async[=] Enable asynchronous logging and optionally set the limit on thenumber of lineswhich will be queued by dnsmasq when writing to the syslog is slow.Dnsmasq can log asynchronously: thisallows it to continue functioning without being blocked by syslog, andallows syslog to use dnsmasq for DNS queries without risking deadlock.If the queue of log-lines becomes full, dnsmasq will log theoverflow, and the number of messages lost. The default queue length is5, a sane value would be 5-25, and a maximum limit of 100 is imposed.-x, --pid-file= Specify an alternate path for dnsmasq to record its process-id in. Normally /var/run/dnsmasq.pid.-u, --user= Specify the userid to which dnsmasq will change after startup. Dnsmasq must normally be started as root, but it will drop rootprivileges after startup by changing id to another user. Normally this user is \"nobody\" but thatcan be over-ridden with this switch.-g, --group= Specify the group which dnsmasq will runas. The defaults to \"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= Listen on instead of the standard DNS port (53). Setting thisto zero completely disables DNS function, leaving only DHCP and/or TFTP.-P, --edns-packet-max= Specify the largest EDNS.0 UDP packet which is supported by the DNSforwarder. Defaults to 1280, which is the RFC2671-recommended maximumfor ethernet.-Q, --query-port= Send outbound DNS queries from, and listen for their replies on, thespecific UDP port instead of using random ports. NOTEthat using this option will make dnsmasq less secure against DNSspoofing attacks but it may be faster and use less resources. Setting this optionto zero makes dnsmasq use a single port allocated to it by theOS: this was the default behaviour in versions prior to 2.43.--min-port= Do not use ports less than that given as source for outbound DNSqueries. Dnsmasq picks random ports as source for outbound queries:when this option is given, the ports used will always to largerthan that specified. Useful for systems behind firewalls.-i, --interface= Listen only on the specified interface(s). Dnsmasq automatically addsthe loopback (local) interface to the list of interfaces to use whenthe--interface option is used. If no--interface or--listen-address options are given dnsmasq listens on all available interfaces except anygiven in--except-interface options. IP alias interfaces (eg \"eth1:0\") cannot be used with--interface or--except-interface options, use --listen-address instead.-I, --except-interface= Do not listen on the specified interface. Note that the order of--listen-address --interface and--except-interface options does not matter and that--except-interface options always override the others.-2, --no-dhcp-interface= Do not provide DHCP or TFTP on the specified interface, but do provide DNS service.-a, --listen-address= Listen on the given IP address(es). Both--interface and--listen-address options may be given, in which case the set of both interfaces andaddresses is used. Note that if no--interface option is given, but--listen-address is, dnsmasq will not automatically listen on the loopbackinterface. To achieve this, its IP address, 127.0.0.1, must beexplicitly given as a--listen-address option.-z, --bind-interfaces On systems which support it, dnsmasq binds the wildcard address,even when it is listening on only some interfaces. It then discardsrequests that it shouldn’t reply to. This has the advantage ofworking even when interfaces come and go and change address. Thisoption forces dnsmasq to really bind only the interfaces it islistening on. About the only time when this is useful is whenrunning another nameserver (or another instance of dnsmasq) on thesame machine. Setting this option also enables multiple instances ofdnsmasq which provide DHCP service to run in the same machine.-y, --localise-queries Return answers to DNS queries from /etc/hosts which depend on the interface over which the query wasreceived. If a name in /etc/hosts has more than one address associated withit, and at least one of those addresses is on the same subnet as theinterface to which the query was sent, then return only theaddress(es) on that subnet. This allows for a server to have multipleaddresses in /etc/hosts corresponding to each of its interfaces, andhosts will get the correct address based on which network they areattached to. Currently this facility is limited to IPv4.-b, --bogus-priv Bogus private reverse lookups. All reverse lookups for private IP ranges (ie 192.168.x.x, etc)which are not found in /etc/hosts or the DHCP leases file are answeredwith \"no such domain\" rather than being forwarded upstream.-V, --alias=,[,] Modify IPv4 addresses returned from upstream nameservers; old-ip isreplaced by new-ip. If the optional mask is given then any addresswhich matches the masked old-ip will be re-written. So, for instance--alias=188.8.131.52,184.108.40.206,255.255.255.0 will map 220.127.116.11 to 18.104.22.168 and 22.214.171.124 to 126.96.36.199. This is whatCisco PIX routers call \"DNS doctoring\".-B, --bogus-nxdomain= Transform replies which contain the IP address given into \"No suchdomain\" replies. This is intended to counteract a devious move made byVerisign in September 2003 when they started returning the address ofan advertising web page in response to queries for unregistered names,instead of the correct NXDOMAIN response. This option tells dnsmasq tofake the correct response when it sees this behaviour. As at Sept 2003the IP address being returned by Verisign is 188.8.131.52-f, --filterwin2k Later versions of windows make periodic DNS requests which don’t get sensible answers fromthe public DNS and can cause problems by triggering dial-on-demand links. This flag turns on an optionto filter such requests. The requests blocked are for records of types SOA and SRV, and type ANY where therequested name has underscores, to catch LDAP requests.-r, --resolv-file= Read the IP addresses of the upstream nameservers from , instead of/etc/resolv.conf. For the format of this file seeresolv.conf(5)the only lines relevant to dnsmasq are nameserver ones. Dnsmasq canbe told to poll more than one resolv.conf file, the first file name specifiedoverrides the default, subsequent ones add to the list. This is onlyallowed when polling; the file with the currently latest modificationtime is the one used.-R, --no-resolv Don’t read /etc/resolv.conf. Get upstream servers only from the commandline or the dnsmasq configuration file.-1, --enable-dbus Allow dnsmasq configuration to be updated via DBus method calls. Theconfiguration which can be changed is upstream DNS servers (andcorresponding domains) and cache clear. Requires that dnsmasq hasbeen built with DBus support.-o, --strict-order By default, dnsmasq will send queries to any of the upstream serversit knows about and tries to favour servers that are known tobe up. Setting this flag forces dnsmasq to try each query with eachserver 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 forcesdnsmasq to send all queries to all available servers. The reply fromthe server which answers first will be returned to the original requestor.--stop-dns-rebind Reject (and log) addresses from upstream nameservers which are in theprivate IP ranges. This blocks an attack where a browser behind afirewall is used to probe machines on the local network.-n, --no-poll Don’t poll /etc/resolv.conf for changes.--clear-on-reload Whenever /etc/resolv.conf is re-read, clear the DNS cache.This is useful when new nameservers may have differentdata than that held in cache.-D, --domain-needed Tells dnsmasq to never forward queries for plain names, without dotsor domain parts, to upstream nameservers. If the name is not knownfrom /etc/hosts or DHCP then a \"not found\" answer is returned.-S, --local, --server=[//[domain/]][[#][@[#]] Specify IP address of upstream servers directly. Setting this flag doesnot suppress reading of /etc/resolv.conf, use -R to do that. If one ormoreoptional domains are given, that server is used only for those domainsand they are queried only using the specified server. This isintended for private nameservers: if you have a nameserver on yournetwork which deals with names of the formxxx.internal.thekelleys.org.uk at 192.168.1.1 then giving the flag-S /internal.thekelleys.org.uk/192.168.1.1 will send all queries forinternal machines to that nameserver, everything else will go to theservers in /etc/resolv.conf. An empty domain specification,// has the special meaning of \"unqualified names only\" ie names without anydots in them. A non-standard port may be specified aspart of the IPaddress using a # character.More than one -S flag is allowed, withrepeated domain or ipaddr parts as required.Also permitted is a -Sflag which gives a domain but no IP address; this tells dnsmasq thata domain is local and it may answer queries from /etc/hosts or DHCPbut should never forward queries on that domain to any upstreamservers.local is a synonym forserver to make configuration files clearer in this case.The optional string after the @ character tellsdnsmasq how to set the source of the queries to thisnameserver. It should be an ip-address, which should belong to the machine on whichdnsmasq is running otherwise this server line will be logged and thenignored, or an interface name. If an interface name is given, thenqueries to the server will be forced via that interface; if anip-address is given then the source address of the queries will be setto that address.The query-port flag is ignored for any servers which have asource address specified but the port may be specified directly aspart of the source address. Forcing queries to an interface is notimplemented on all platforms supported by dnsmasq.-A, --address=//[domain/] Specify an IP address to return for any host in the given domains.Queries in the domains are never forwarded and always replied towith the specified IP address which may be IPv4 or IPv6. To giveboth IPv4 and IPv6 addresses for a domain, use repeated -A flags.Note that /etc/hosts and DHCP leases override this for individualnames. A common use of this is to redirect the entire doubleclick.netdomain to some friendly local web server to avoid banner ads. Thedomain specification works in the same was as for --server, with theadditional facility that /#/ matches any domain. Thus--address=/#/184.108.40.206 will always return 220.127.116.11 for any query notanswered from /etc/hosts or DHCP and not sent to an upstreamnameserver by a more specific --server directive.-m, --mx-host=[[,],] Return an MX record named pointing to the given hostname (ifgiven), orthe host specified in the --mx-target switchor, if that switch is not given, the host on which dnsmasqis running. The default is useful for directing mail from systems on a LANto a central server. The preference value is optional, and defaults to1 if not given. More than one MX record may be given for a host.-t, --mx-target= Specify the default target for the MX record returned by dnsmasq. See--mx-host. If --mx-target is given, but not --mx-host, then dnsmasqreturns a MX record containing the MX target for MX queries on thehostname of the machine on which dnsmasq is running.-e, --selfmx Return an MX record pointing to itself for each localmachine. Local machines are those in /etc/hosts or with DHCP leases.-L, --localmx Return an MX record pointing to the host given by mx-target (or themachine on which dnsmasq is running) for eachlocal machine. Local machines are those in /etc/hosts or with DHCPleases.-W, --srv-host=..,[[,[,[,]]]] Return a SRV DNS record. See RFC2782 for details. If not supplied, thedomain defaults to that given by--domain. The default for the target domain is empty, and the default for portis one and the defaults forweight and priority are zero. Be careful if transposing data from BINDzone files: the port, weight and priority numbers are in a differentorder. More than one SRV record for a given service/domain is allowed,all that match are returned.-Y, --txt-record=[[,],] Return a TXT DNS record. The value of TXT record is a set of strings,so any number may be included, split by commas.--ptr-record=[,] Return a PTR DNS record.--naptr-record=,,,,,[,] Return an NAPTR DNS record, as specified in RFC3403.--interface-name=, Return a DNS record associating the name with the primary address onthe given interface. This flag specifies an A record for the givenname in the same way as an /etc/hosts line, except that the address isnot constant, but taken from the given interface. If the interface isdown, not configured or non-existent, an empty record is returned. Thematching PTR record is also created, mapping the interface address tothe name. More than one name may be associated with an interfaceaddress by repeating the flag; in that case the first instance is usedfor the reverse address-to-name mapping.-c, --cache-size= Set the size of dnsmasq’s cache. The default is 150 names. Setting the cache size to zero disables caching.-N, --no-negcache Disable negative caching. Negative caching allows dnsmasq to remember\"no such domain\" answers from upstream nameservers and answeridentical queries without forwarding them again.-0, --dns-forward-max= Set the maximum number of concurrent DNS queries. The default value is150, which should be fine for most setups. The only known situationwhere this needs to be increased is when using web-server log fileresolvers, which can generate large numbers of concurrent queries.-F, --dhcp-range=[[net:]network-id,],[[,],][,] Enable the DHCP server. Addresses will be given out from the range to and from statically defined addresses givenindhcp-host options. If the lease time is given, then leaseswill be given for that length of time. The lease time is in seconds,or minutes (eg 45m) or hours (eg 1h) or the literal \"infinite\". Theminimum lease time is two minutes. Thisoption may be repeated, with different addresses, to enable DHCPservice to more than one network. For directly connected networks (ie,networks on which the machine running dnsmasq has an interface) thenetmask is optional. It is, however, required for networks whichreceive DHCP service via a relay agent. The broadcast address isalways optional. On some broken systems, dnsmasq can listen on onlyone interface when using DHCP, and the name of that interface must begiven using theinterface option. This limitation currently affects OpenBSD before version 4.0. It is alwaysallowed to have more than one dhcp-range in a single subnet. The optionalnetwork-id is a alphanumeric label which marks this network so thatdhcp options may be specified on a per-network basis.When it is prefixed with ’net:’ then its meaning changes from settinga tag to matching it. Only one tag may be set, but more than one tag may be matched.The end address may be replaced by the keywordstatic which tells dnsmasq to enable DHCP for the network specified, but notto dynamically allocate IP addresses. Only hosts which have staticaddresses given viadhcp-host or from /etc/ethers will be served.-G, --dhcp-host=[,id:*][,net:][,][,][,][,ignore] Specify per host parameters for the DHCP server. This allows a machinewith a particular hardware address to be always allocated the samehostname, IP address and lease time. A hostname specified like thisoverrides any supplied by the DHCP client on the machine. It is alsoallowable to ommit the hardware address and include the hostname, inwhich case the IP address and lease times will apply to any machineclaiming that name. For example--dhcp-host=00:20:e0:3b:13:af,wap,infinite tells dnsmasq to givethe machine with hardware address 00:20:e0:3b:13:af the name wap, andan infinite DHCP lease.--dhcp-host=lap,192.168.0.199 tellsdnsmasq to always allocate the machine lap the IP address192.168.0.199. Addresses allocated like this are not constrained to bein the range given by the --dhcp-range option, but they must be on thenetwork being served by the DHCP server. It is allowed to use client identifiers rather thanhardware addresses to identify hosts by prefixing with ’id:’. Thus:--dhcp-host=id:01:02:03:04,..... refers to the host with client identifier 01:02:03:04. It is alsoallowed to specify the client ID as text, like this:--dhcp-host=id:clientidastext,..... The special option id:* means \"ignore any client-idand use MAC addresses only.\" This is useful when a client presents a client-id sometimesbut not others.If a name appears in /etc/hosts, the associated address can beallocated to a DHCP lease, but only if a--dhcp-host option specifying the name also exists. The special keyword \"ignore\"tells dnsmasq to never offer a DHCP lease to a machine. The machinecan be specified by hardware address, client ID or hostname, forinstance--dhcp-host=00:20:e0:3b:13:af,ignore This isuseful when there is another DHCP server on the network which shouldbe used by some machines. The net: sets the network-id tagwhenever this dhcp-host directive is in use.This can be used toselectively send DHCP options just for this host. When a host matches anydhcp-host directive (or one implied by /etc/ethers) then the specialnetwork-id tag \"known\" is set. This allows dnsmasq to be configured toignore requests from unknown machines using--dhcp-ignore=#known Ethernet addresses (but not client-ids) may havewildcard bytes, so for example--dhcp-host=00:20:e0:3b:13:*,ignore will cause dnsmasq to ignore a range of hardware addresses. Note thatthe \"*\" will need to be escaped or quoted on a command line, but notin the configuration file. Hardware addresses normally match anynetwork (ARP) type, but it is possible to restrict them to a singleARP type by preceding them with the ARP-type (in HEX) and \"-\". so--dhcp-host=06-00:20:e0:3b:13:af,18.104.22.168 will only match aToken-Ring hardware address, since the ARP-address type for token ringis 6.--dhcp-hostsfile= Read DHCP host information from the specified file. The file containsinformation about one host per line. The format of a line is the sameas text to the right of ’=’ in --dhcp-host. The advantage of storing DHCP host informationin this file is that it can be changed without re-starting dnsmasq:the file will be re-read when dnsmasq receives SIGHUP.--dhcp-optsfile= Read DHCP option information from the specified file. The advantage ofusing this option is the same as for --dhcp-hostsfile: thedhcp-optsfile will be re-read when dnsmasq receives SIGHUP.-Z, --read-ethers Read /etc/ethers for information about hosts for the DHCP server. Theformat of /etc/ethers is a hardware address, followed by either ahostname or dotted-quad IP address. When read by dnsmasq these lineshave exactly the same effect as--dhcp-host options containing the same information. /etc/ethers is re-read whendnsmasq receives SIGHUP.-O, --dhcp-option=[,[,]][vendor:,][option:],[[,]] Specify different or extra options to DHCP clients. By default,dnsmasq sends some standard options to DHCP clients, the netmask andbroadcast address are set to the same as the host running dnsmasq, andthe DNS server and default route are set to the address of the machinerunning dnsmasq. If the domain name option has been set, that is sent.This configuration allows these defaults to be overridden,or other options specified. The option, to be sent may be given as adecimal number or as \"option:\" The option numbers arespecified in RFC2132 and subsequent RFCs. The set of option-namesknown by dnsmasq can be discovered by running \"dnsmasq --help dhcp\".For example, to set the default route option to192.168.4.4, do--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, do--dhcp-option = 42,192.168.0.4 or--dhcp-option = option:ntp-server, 192.168.0.4 The special address 0.0.0.0 is taken to mean \"the address of themachine running dnsmasq\". Data types allowed are comma separateddotted-quad IP addresses, a decimal number, colon-separated hex digitsand a text string. If the optional network-ids are given thenthis option is only sent when all the network-ids are matched.Special processing is done on a text argument for option 119, toconform with RFC 3397. Text or dotted-quad IP addresses as argumentsto option 120 are handled as per RFC 3361. Dotted-quad IP addresseswhich are followed by a slash and then a netmask size are encoded asdescribed in RFC 3442.Be careful: no checking is done that the correct type of data for theoption number is sent, it is quite possible topersuade dnsmasq to generate illegal DHCP packets with injudicious useof this flag. When the value is a decimal number, dnsmasq must determine howlarge the data item is. It does this by examining the option number and/or thevalue, but can be overridden by appending a single letter flag as follows:b = one byte, s = two bytes, i = four bytes. This is mainly useful withencapsulated vendor class options (see below) where dnsmasq cannotdetermine data size from the option number. Option data whichconsists solely of periods and digits will be interpreted by dnsmasqas an IP address, and inserted into an option as such. To force aliteral string, use quotes. For instance when using option 66 to senda literal IP address as TFTP server name, it is necessary to do--dhcp-option=66, 22.214.171.124 Encapsulated Vendor-class options may also be specified using--dhcp-option: for instance--dhcp-option=vendor:PXEClient,1,0.0.0.0 sends the encapsulated vendorclass-specific option \"mftp-address=0.0.0.0\" to any client whosevendor-class matches \"PXEClient\". The vendor-class matching issubstring based (see --dhcp-vendorclass for details). If avendor-class option (number 60) is sent by dnsmasq, then that is usedfor selecting encapsulated options in preference to any sent by theclient. It ispossible to omit the vendorclass completely;--dhcp-option=vendor:,1,0.0.0.0 in which case the encapsulated option is always sent.The address 0.0.0.0 is not treated specially inencapsulated vendor class options.--dhcp-option-force=[,[,]][vendor:,],[[,]] This works in exactly the same way as--dhcp-option except that the option will always be sent, even if the client doesnot ask for it in the parameter request list. This is sometimesneeded, for example when sending options to PXELinux.--dhcp-no-override Disable re-use of the DHCP servername and filename fields as extraoption space. If it can, dnsmasq moves the boot server and filenameinformation (from dhcp-boot) out of their dedicated fields intoDHCP options. This make extra space available in the DHCP packet foroptions but can, rarely, confuse old or broken clients. This flagforces \"simple and safe\" behaviour to avoid problems in such a case.-U, --dhcp-vendorclass=, Map from a vendor-class string to a network id tag. Most DHCP clients provide a\"vendor class\" which represents, in some sense, the type of host. This optionmaps vendor classes to tags, so that DHCP options may be selectively deliveredto different classes of hosts. For exampledhcp-vendorclass=printers,Hewlett-Packard JetDirect will allow options to be set only for HP printers like so:--dhcp-option=printers,3,192.168.4.4 The vendor-class string issubstring matched against the vendor-class supplied by the client, toallow fuzzy matching.-j, --dhcp-userclass=, Map from a user-class string to a network id tag (with substringmatching, like vendor classes). Most DHCP clients provide a\"user class\" which is configurable. This optionmaps user classes to tags, so that DHCP options may be selectively deliveredto different classes of hosts. It is possible, for instance to usethis to set a different printer server for hosts in the class\"accounts\" than for hosts in the class \"engineering\".-4, --dhcp-mac=, Map from a MAC address to a network-id tag. The MAC address may includewildcards. For example--dhcp-mac=3com,01:34:23:*:*:* will set the tag \"3com\" for any host whose MAC address matches the pattern.--dhcp-circuitid=,, --dhcp-remoteid=, Map from RFC3046 relay agent options to network-id tags. This data maybe provided by DHCP relay agents. The circuit-id or remote-id isnormally given as colon-separated hex, but is also allowed to be asimple string. If an exact match is achieved between the circuit oragent ID and one provided by a relay agent, the network-id tag is set.--dhcp-subscrid=, Map from RFC3993 subscriber-id relay agent options to network-id tags.--dhcp-match=, Set the network-id tag if the client sends a DHCP option of the givennumber. This can be used to identify particular clients which sendinformation using private option numbers.-J, --dhcp-ignore=[,] When all the given network-ids match the set of network-ids derivedfrom the net, host, vendor and user classes, ignore the host and donot allocate it a DHCP lease.--dhcp-ignore-names[=[,]] When all the given network-ids match the set of network-ids derivedfrom the net, host, vendor and user classes, ignore any hostnameprovided by the host. Note that, unlike dhcp-ignore, it is permissibleto supply no netid tags, in which case DHCP-client supplied hostnamesare always ignored, and DHCP hosts are added to the DNS using onlydhcp-host configuration in dnsmasq and the contents of /etc/hosts and/etc/ethers.--dhcp-broadcast=[,] When all the given network-ids match the set of network-ids derivedfrom the net, host, vendor and user classes, always use broadcast tocommunicate with the host when it is unconfigured. Most DHCP clients whichneed broadcast replies set a flag in their requests so that thishappens automatically, some old BOOTP clients do not.-M, --dhcp-boot=[net:,],[[,]] Set BOOTP options to be returned by the DHCP server. Server name andaddress are optional: if not provided, the name is left empty, and theaddress set to the address of the machine running dnsmasq. If dnsmasqis providing a TFTP service (see--enable-tftp ) then only the filename is required here to enable network booting.If the optional network-id(s) are given,they must match for this configuration to be sent. Note thatnetwork-ids are prefixed by \"net:\" to distinguish them.-X, --dhcp-lease-max= Limits dnsmasq to the specified maximum number of DHCP leases. Thedefault is 150. This limit is to prevent DoS attacks from hosts whichcreate thousands of leases and use lots of memory in the dnsmasqprocess.-K, --dhcp-authoritative Should be set when dnsmasq is definitely the only DHCP server on a network.It changes the behaviour from strict RFC compliance so that DHCP requests onunknown leases from unknown hosts are not ignored. This allows new hoststo get a lease without a tedious timeout under all circumstances. It alsoallows dnsmasq to rebuild its lease database without each client needing toreacquire a lease, if the database is lost.--dhcp-alternate-port[=[,]] Change the ports used for DHCP from the default. If this option isgiven alone, without arguments, it changes the ports used for DHCPfrom 67 and 68 to 1067 and 1068. If a single argument is given, thatport number is used for the server and the port number plus one usedfor the client. Finally, two port numbers allows arbitraryspecification of both server and client ports for DHCP.-3, --bootp-dynamic Enable dynamic allocation of IP addresses to BOOTP clients. Use thiswith care, since each address allocated to a BOOTP client is leasedforever, and therefore becomes permanently unavailable for re-use byother hosts.-5, --no-ping By default, the DHCP server will attempt to ensure that an address innot in use before allocating it to a host. It does this by sending anICMP echo request (aka \"ping\") to the address in question. If it getsa reply, then the address must already be in use, and another istried. This flag disables this check. Use with caution.--log-dhcp Extra logging for DHCP: log all the options sent to DHCP clients andthe netid tags used to determine them.-l, --dhcp-leasefile= Use the specified file to store DHCP lease information. If this optionis given but no dhcp-range option is given then dnsmasq version 1behaviour is activated. The file given is assumed to be an ISC dhcpdlease file and parsed for leases which are then added to the DNSsystem if they have a hostname. This functionality may have beenexcluded from dnsmasq at compile time, in which case an error willoccur. In any case note that ISC leasefile integration is a deprecatedfeature. It should not be used in new installations, and will beremoved in a future release.-6 --dhcp-script= Whenever a new DHCP lease is created, or an old one destroyed, thebinary specified by this option is run. The arguments to the processare \"add\", \"old\" or \"del\", the MACaddress of the host (or \"\"), the IP address, and the hostname,if known. \"add\" means a lease has been created, \"del\" means it hasbeen destroyed, \"old\" is a notification of an existing lease whendnsmasq starts or a change to MAC address or hostname of an existinglease (also, lease length or expiry and client-id, if leasefile-ro is set).The process is run as root (assuming that dnsmasq was originally run asroot) even if dnsmasq is configured to change UID to an unprivileged user.The environment is inherited from the invoker of dnsmasq, and if thehost provided a client-id, this is stored in the environment variableDNSMASQ_CLIENT_ID. If the client provides vendor-class or user-classinformation, these are provided in DNSMASQ_VENDOR_CLASS andDNSMASQ_USER_CLASS0..DNSMASQ_USER_CLASSn variables, but only for\"add\" actions or \"old\" actions when a host resumes an existing lease,since these data are not held in dnsmasq’s leasedatabase. If dnsmasq was compiled with HAVE_BROKEN_RTC, thenthe length of the lease (in seconds) is stored inDNSMASQ_LEASE_LENGTH, otherwise the time of lease expiry is stored inDNSMASQ_LEASE_EXPIRES. The number of seconds until lease expiry isalways stored in DNSMASQ_TIME_REMAINING.If a lease used to have a hostname, which isremoved, an \"old\" event is generated with the new state of the lease,ie no name, and the former name is provided in the environmentvariable DNSMASQ_OLD_HOSTNAME. DNSMASQ_INTERFACE stores the name ofthe interface on which the request arrived; this is not set for \"old\"actions when dnsmasq restarts.All file descriptors areclosed except stdin, stdout and stderr which are open to /dev/null(except in debug mode).The script is not invoked concurrently: if subsequent leasechanges occur, the script is not invoked again until any existinginvocation exits. At dnsmasq startup, the script will be invoked forall existing leases as they are read from the lease file. Expiredleases will be called with \"del\" and others with \"old\". must be an absolute pathname, no PATH search occurs. When dnsmasqreceives a HUP signal, the script will be invoked for existing leaseswith an \"old \" event.--dhcp-scriptuser Specify the user as which to run the lease-change script. This defaults to root, but can be changed to another user using this flag.-9, --leasefile-ro Completely suppress use of the lease database file. The file will notbe created, read, or written. Change the way the lease-changescript (if one is provided) is called, so that the lease database maybe maintained in external storage by the script. In addition to theinvocations given in--dhcp-script the lease-change script is called once, at dnsmasq startup, with thesingle argument \"init\". When called like this the script should writethe saved state of the lease database, in dnsmasq leasefile format, tostdout and exit with zero exit code. Setting thisoption also forces the leasechange script to be called on changesto the client-id and lease length and expiry time.--bridge-interface=,[,] Treat DHCP request packets arriving at any of the interfacesas if they had arrived at . This option is only availableon BSD platforms, and is necessary when using \"old style\" bridging, sincepackets arrive at tap interfaces which don’t have an IP address.-s, --domain= Specifies the domain for the DHCP server. This has two effects;firstly it causes the DHCP server to return the domain to any hostswhich request it, and secondly it sets the domain which it is legalfor DHCP-configured hosts to claim. The intention is to constrainhostnames so that an untrusted host on the LAN cannot advertiseits name via dhcp as e.g. \"microsoft.com\" and capture traffic notmeant for it. If no domain suffix is specified, then any DHCPhostname with a domain part (ie with a period) will be disallowedand logged. If suffix is specified, then hostnames with a domainpart are allowed, provided the domain part matches the suffix. Inaddition, when a suffix is set then hostnames without a domainpart 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 fromdnsmasq both as \"laptop\" and \"laptop.thekelleys.org.uk\". If the domain isgiven as \"#\" then the domain is read from the first \"search\" directivein /etc/resolv.conf (or equivalent).--enable-tftp Enable the TFTP server function. This is deliberately limited to thatneeded to net-boot a client. Only reading is allowed; the tsize andblksize extensions are supported (tsize is only supported in octet mode).--tftp-root= Look for files to transfer using TFTP relative to the givendirectory. When this is set, TFTP paths which include \"..\" arerejected, to stop clients getting outside the specified root.Absolute paths (starting with /) are allowed, but they must be withinthe tftp-root.--tftp-unique-root Add the IP address of the TFTP client as a path component on the endof the TFTP-root (in standard dotted-quad format). Only valid if atftp-root is set and the directory exists. For instance, if tftp-root is \"/tftp\" and client126.96.36.199 requests file \"myfile\" then the effective path will be\"/tftp/188.8.131.52/myfile\" if /tftp/184.108.40.206 exists or /tftp/myfile otherwise.--tftp-secure Enable TFTP secure mode: without this, any file which is readable bythe dnsmasq process under normal unix access-control rules isavailable via TFTP. When the --tftp-secure flag is given, only filesowned by the user running the dnsmasq process are accessible. Ifdnsmasq is being run as root, different rules apply: --tftp-securehas no effect, but only files which have the world-readable bit setare accessible. It is not recommended to run dnsmasq as root with TFTPenabled, and certainly not without specifying --tftp-root. Doing socan expose any world-readable file on the server to any host on the net.--tftp-max= Set the maximum number of concurrent TFTP connections allowed. Thisdefaults to 50. When serving a large number of TFTP connections,per-process file descriptor limits may be encountered. Dnsmasq needsone file descriptor for each concurrent TFTP connection and onefile descriptor per unique file (plus a few others). So serving thesame file simultaneously to n clients will use require about n + 10 filedescriptors, serving different files simultaneously to n clients willrequire about (2*n) + 10 descriptors. If--tftp-port-range is given, that can affect the number of concurrent connections.--tftp-no-blocksize Stop the TFTP server from negotiating the \"blocksize\" option with aclient. Some buggy clients request this option but then behave badlywhen it is granted.--tftp-port-range=, A TFTP server listens on a well-known port (69) for connection initiation,but it also uses a dynamically-allocated port for eachconnection. Normally these are allocated by the OS, but this optionspecifies a range of ports for use by TFTP transfers. This can beuseful when TFTP has to traverse a firewall. The start of the rangecannot be lower than 1025 unless dnsmasq is running as root. The numberof concurrent TFTP connections is limited by the size of the port range.-C, --conf-file= Specify a different configuration file. The conf-file option is also allowed inconfiguration files, to include multiple configuration files.-7, --conf-dir= Read all the files in the given directory as configurationfiles. Files whose names end in or start with . or start and endwith # are skipped. This flag may be given on the commandline or in a configuration file.CONFIG FILEAt startup, dnsmasq reads/etc/dnsmasq.conf, if it exists. (OnFreeBSD, the file is/usr/local/etc/dnsmasq.conf ) (but see the-C and-7 options.) The format of thisfile consists of one option per line, exactly as the long options detailedin the OPTIONS section but without the leading \"--\". Lines starting with # are comments and ignored. Foroptions which may only be specified once, the configuration file overridesthe command line. Quoting is allowed in a config file:between \" quotes the special meanings of ,:. and # are removed and thefollowing escapes are allowed: \\\\ \\\" \\t \\e \\b \\r and \\n. The latercorresponding to tab, escape, backspace, return and newline.NOTESWhen it receives a SIGHUP,dnsmasq clears its cache and then re-loads/etc/hosts and/etc/ethers and any file given by --dhcp-hostsfile, --dhcp-optsfile or --addn-hosts.The dhcp lease change script is called for allexisting DHCP leases. If --no-pollis set SIGHUP also re-reads/etc/resolv.conf. SIGHUPdoes NOT re-read the configuration file.When it receives a 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 beforethey expired in order to make room for new names and the total numberof names that have been inserted into the cache. For each upstreamserver it gives the number of queries sent, and the number whichresulted in an error. In--no-daemon mode or when full logging is enabled (-q), a complete dump of thecontents of the cache is made.When it receives SIGUSR2 and it is logging direct to a file (see--log-facility )dnsmasq will close and reopen the log file. Note that during this operation,dnsmasq will not be running as root. When it first creates the logfilednsmasq changes the ownership of the file to the non-root user it will runas. Logrotate should be configured to create a new log file withthe ownership which matches the existing one before sending SIGUSR2.If TCP DNS queries are in progress, the old logfile will remain open inchild processes which are handling TCP queries and may continue to bewritten. There is a limit of 150 seconds, after which all existing TCPprocesses will have expired: for this reason, it is not wise toconfigure logfile compression for logfiles which have just beenrotated. Using logrotate, the required options arecreate anddelaycompress. Dnsmasq is a DNS query forwarder: it it not capable of recursivelyanswering arbitrary queries starting from the root servers butforwards such queries to a fully recursive upstream DNS server which istypically provided by an ISP. By default, dnsmasq reads/etc/resolv.conf to discover the IPaddresses of the upstream nameservers it should use, since theinformation 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 tobe set dynamically by PPP or DHCP since both protocols provide theinformation.Absence of/etc/resolv.conf is not an errorsince it may not have been created before a PPP connection exists. Dnsmasqsimply keeps checking in case/etc/resolv.conf is created at anytime. Dnsmasq can be told to parse more than one resolv.conffile. 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 changedlast, giving automatic switching between DNS servers.Upstream servers may also be specified on the command line or inthe configuration file. These server specifications optionally take adomain name which tells dnsmasq to use that server only to find namesin that particular domain.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 todnsmasq. Then either specify the upstream servers directly to dnsmasqusing--server options or put their addresses real in another file, say/etc/resolv.dnsmasq and run dnsmasq with the-r /etc/resolv.dnsmasq option. This second technique allows for dynamic update of the serveraddresses by PPP or DHCP.Addresses in /etc/hosts will \"shadow\" different addresses for the samenames in the upstream DNS, so \"mycompany.com 220.127.116.11\" in /etc/hosts will ensure thatqueries for \"mycompany.com\" always return 18.104.22.168 even if queries inthe upstream DNS would otherwise return a different address. There isone exception to this: if the upstream DNS contains a CNAME whichpoints to a shadowed name, then looking up the CNAME through dnsmasqwill result in the unshadowed address associated with the target ofthe CNAME. To work around this, add the CNAME to /etc/hosts so thatthe CNAME is shadowed too.The network-id system works as follows: For each DHCP request, dnsmasqcollects a set of valid network-id tags, one from thedhcp-range used to allocate the address, one from any matchingdhcp-host and possibly many from matching vendor classes and userclasses sent by the DHCP client. Anydhcp-option which has network-id tags will be used in preference to an untaggeddhcp-option, provided that _all_ the tags match somewhere in theset collected as described above. The prefix ’#’ on a tag means ’not’so --dhcp=option=#purple,3,22.214.171.124 sends the option when thenetwork-id tag purple is not in the set of valid tags.If the network-id in adhcp-range is prefixed with ’net:’ then its meaning changes from setting atag to matching it. Thus if there is more than dhcp-range on a subnet,and one is tagged with a network-id which is set (for instancefrom a vendorclass option) then hosts which set the netid tag will beallocated addresses in the tagged range.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 usingdhcp-host configurations or in/etc/ethers , and adhcp-range configuration option is present to activate the DHCP serveron a particular network. (Setting --bootp-dynamic removes the need forstatic address mappings.) The filenameparameter in a BOOTP request is matched against netids indhcp-option configurations, as is the tag \"bootp\", allowing some control over the options returned todifferent classes of hosts.EXIT CODES0 - Dnsmasq successfully forked into the background, or terminatednormally if backgrounding is not enabled.1 - A problem with configuration was detected.2 - A problem with network access occurred (address in use, attemptto use privileged ports without permission).3 - A problem occurred with a filesystem operation (missingfile/directory, permissions).4 - Memory allocation failure.5 - Other miscellaneous problem.11 or greater - a non zero return code was received from thelease-script process \"init\" call. The exit code from dnsmasq is thescript’s exit code with 10 added.LIMITSThe default values for resource limits in dnsmasq are generallyconservative, and appropriate for embedded router type devices withslow processors and limited memory. On more capable hardware, it ispossible to increase the limits, and handle many more clients. Thefollowing applies to dnsmasq-2.37: earlier versions did not scale as well.Dnsmasq is capable of handling DNS and DHCP for at least a thousandclients. Clearly to do this the value of--dhcp-lease-max must be increased,and lease times should not be very short (less than one hour). Thevalue of--dns-forward-max can be increased: start with it equal tothe number of clients and increase if DNS seems slow. Note that DNSperformance depends too on the performance of the upstreamnameservers. The size of the DNS cache may be increased: the hardlimit is 10000 names and the default (150) is very low. SendingSIGUSR1 to dnsmasq makes it log information which is useful for tuningthe cache size. See theNOTES section for details.The built-in TFTP server is capable of many simultaneous filetransfers: the absolute limit is related to the number of file-handlesallowed to a process and the ability of the select() system call tocope with large numbers of file handles. If the limit is set too highusing--tftp-max it will be scaled down and the actual limit logged atstart-up. Note that more transfers are possible when the same file isbeing sent than when each transfer sends a different file.It is possible to use dnsmasq to block Web advertising by using a listof 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 sizefile needs a 1GHz processor and about 60Mb of RAM.FILES/etc/dnsmasq.conf /usr/local/etc/dnsmasq.conf /etc/resolv.conf /etc/hosts /etc/ethers /var/lib/misc/dnsmasq.leases /var/db/dnsmasq.leases /var/run/dnsmasq.pid SEE ALSOThis manual page was written by Simon Kelley . Advertisements 153554b96e