···11+# Dnsmasq {#module-services-networking-dnsmasq}
22+33+Dnsmasq is an integrated DNS, DHCP and TFTP server for small networks.
44+55+## Configuration {#module-services-networking-dnsmasq-configuration}
66+77+### An authoritative DHCP and DNS server on a home network {#module-services-networking-dnsmasq-configuration-home}
88+99+On a home network, you can use Dnsmasq as a DHCP and DNS server. New devices on
1010+your network will be configured by Dnsmasq, and instructed to use it as the DNS
1111+server by default. This allows you to rely on your own server to perform DNS
1212+queries and caching, with DNSSEC enabled.
1313+1414+The following example assumes that
1515+1616+- you have disabled your router's integrated DHCP server, if it has one
1717+- your router's address is set in [](#opt-networking.defaultGateway.address)
1818+- your system's Ethernet interface is `eth0`
1919+- you have configured the address(es) to forward DNS queries in [](#opt-networking.nameservers)
2020+2121+```nix
2222+{
2323+ services.dnsmasq = {
2424+ enable = true;
2525+ settings = {
2626+ interface = "eth0";
2727+ bind-interfaces = true; # Only bind to the specified interface
2828+ dhcp-authoritative = true; # Should be set when dnsmasq is definitely the only DHCP server on a network
2929+3030+ server = config.networking.nameservers; # Upstream dns servers to which requests should be forwarded
3131+3232+ dhcp-host = [
3333+ # Give the current system a fixed address of 192.168.0.254
3434+ "dc:a6:32:0b:ea:b9,192.168.0.254,${config.networking.hostName},infinite"
3535+ ];
3636+3737+ dhcp-option = [
3838+ # Address of the gateway, i.e. your router
3939+ "option:router,${config.networking.defaultGateway.address}"
4040+ ];
4141+4242+ dhcp-range = [
4343+ # Range of IPv4 addresses to give out
4444+ # <range start>,<range end>,<lease time>
4545+ "192.168.0.10,192.168.0.253,24h"
4646+ # Enable stateless IPv6 allocation
4747+ "::f,::ff,constructor:eth0,ra-stateless"
4848+ ];
4949+5050+ dhcp-rapid-commit = true; # Faster DHCP negotiation for IPv6
5151+ local-service = true; # Accept DNS queries only from hosts whose address is on a local subnet
5252+ log-queries = true; # Log results of all DNS queries
5353+ bogus-priv = true; # Don't forward requests for the local address ranges (192.168.x.x etc) to upstream nameservers
5454+ domain-needed = true; # Don't forward requests without dots or domain parts to upstream nameservers
5555+5656+ dnssec = true; # Enable DNSSEC
5757+ # DNSSEC trust anchor. Source: https://data.iana.org/root-anchors/root-anchors.xml
5858+ trust-anchor = ".,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D";
5959+ };
6060+ };
6161+}
6262+```
6363+6464+## References {#module-services-networking-dnsmasq-references}
6565+6666+- Upstream website: <https://dnsmasq.org>
6767+- Manpage: <https://dnsmasq.org/docs/dnsmasq-man.html>
6868+- FAQ: <https://dnsmasq.org/docs/FAQ>