Jump to content

Pi-Hole: Difference between revisions

From Official NixOS Wiki
J7 (talk | contribs)
No edit summary
J7 (talk | contribs)
typos
 
(6 intermediate revisions by the same user not shown)
Line 4: Line 4:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.pihole-ftl = {
services.pihole-ftl = {
    enable = true;
  enable = true;
     openFirewallDNS = true;              # To open port 53 for DNS traffic
  settings = {
     # See <https://docs.pi-hole.net/ftldns/configfile/>


     # Settings documented at <https://docs.pi-hole.net/ftldns/configfile/>
     # External DNS Servers quad9 and cloudflare
     settings = {
     dns.upstreams = [ "9.9.9.9" "1.1.1.1" ];
        dns.upstreams = [ "1.1.1.1" ];  # To use Cloudflare's DNS Servers
        hosts = [                        # Optionally resolve local domains
            "192.168.178.188 some.domain"
        ];
    };


     # Lists can be added via URL
     # Optionally resolve local hosts (domain is optional)
     lists = [
     dns.hosts = [ "192.168.1.188 hostname.domain" ];
        {
  };
            url = "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/pro.txt";
            type = "block";
            enabled = true;
            description = "Sample blocklist by hagezi";
        }
    ];
};
};
</syntaxhighlight>At your option, a web interface can be enabled via <code>services.pihole-web.enable = true;</code>. You will have to open the corresponding ports when doing so.
</syntaxhighlight>


Now, setting your routers DNS server to your IP will direct your traffic to the Pi-Hole. Blocked domains will not be resolved.
Test if it's working
 
<syntaxhighlight>
$ systemctl status pihole-ftl.service
$ nslookup nixos.org localhost
$ nslookup hostname.domain localhost
</syntaxhighlight>
 
== Adding lists and enabling web interface ==
<syntaxhighlight lang="nix">
services.pihole-ftl = {
  enable = true;
  settings = {
    # See <https://docs.pi-hole.net/ftldns/configfile/>
 
    # External DNS Servers quad9 and cloudflare
    dns.upstreams = [ "9.9.9.9" "1.1.1.1" ];
 
    # Optionally resolve local hosts (domain is optional)
    dns.hosts = [ "192.168.1.188 hostname.domain" ];
  };
 
  lists = [    # Lists can be added via URL
    {
      url = "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/pro.txt";
      type = "block";
      enabled = true;
      description = "hagezi blocklist";
    }
  ];
};
 
services.pihole-web = {
  enable = true;
  ports = [ "443s" ];
};
</syntaxhighlight>
Test pihole web interface at https://localhost:443
 
Now you can set your router's DNS server to the IP of the host running pihole and blocked domains should not be resolved.

Latest revision as of 20:18, 27 February 2026

Pi-Hole is a DNS service that functions as network ad-blocker.

Minimal Configuration Example

services.pihole-ftl = {
  enable = true;
  settings = {
    # See <https://docs.pi-hole.net/ftldns/configfile/>

    # External DNS Servers quad9 and cloudflare
    dns.upstreams = [ "9.9.9.9" "1.1.1.1" ];

    # Optionally resolve local hosts (domain is optional)
    dns.hosts = [ "192.168.1.188 hostname.domain" ];
  };
};

Test if it's working

$ systemctl status pihole-ftl.service
$ nslookup nixos.org localhost
$ nslookup hostname.domain localhost

Adding lists and enabling web interface

services.pihole-ftl = {
  enable = true;
  settings = {
    # See <https://docs.pi-hole.net/ftldns/configfile/>

    # External DNS Servers quad9 and cloudflare
    dns.upstreams = [ "9.9.9.9" "1.1.1.1" ];

    # Optionally resolve local hosts (domain is optional)
    dns.hosts = [ "192.168.1.188 hostname.domain" ];
  };

  lists = [    # Lists can be added via URL
    {
      url = "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/pro.txt";
      type = "block";
      enabled = true;
      description = "hagezi blocklist";
    }
  ];
};

services.pihole-web = {
  enable = true;
  ports = [ "443s" ];
};

Test pihole web interface at https://localhost:443

Now you can set your router's DNS server to the IP of the host running pihole and blocked domains should not be resolved.