Post

PfSense DNS and AdBlocker

This configuration is part of Pfsense-WAN-LAN-DMZ, if you want to take a look at it.


In the following post, we are going to look at how to configure our dns servers and filter the ads creating an adblock per network.

AdBlocks

As now our wifi network is over the LAN, we have control over the packets that are sent and received, that’s why we can change the dns and use our own ones like pi-hole, adguard, etc… so that we can filter contents, ads, certain pages, etc…

Pi-hole

Instalation

1
 curl -sSL https://install.pi-hole.net | bash

Basic config

  • Change passwd
    1
    
     pihole -a -p
    
  • We will be able to access the web interface, http://{your-ip}/admin

  • If we log in we will see something similar to: ALT IMG

  • Once we have this, we can configure your rules. ALT IMG

Here we will add all the DNS services that we have, in this case the Adguard (we will install it later, and pfsense in its absence).

In Settings:

  • DNS ALT IMG

The rest will be left as default.

Adguard

Installation

1
2
3
4
5
6
7
8
9
10
11
12
$ curl -LO https://github.com/AdguardTeam/AdGuardHome/releases/latest/download/AdGuardHome_linux_amd64.tar.gz

$ tar -vxf AdGuardHome_linux_amd64.tar.gz

$ sudo mkdir /opt/AdGuardHome
$ sudo mv ~/AdGuardHome/AdGuardHome /opt/AdGuardHome/

$ sudo chown -R root:root /opt/AdGuardHome
$ sudo chmod -R o-rwx /opt/AdGuardHome

$ sudo /opt/AdGuardHome/AdGuardHome -s install

If you are using a firewall like ufw (and you really should be), you might need to temporarily open ports to make sure you can reach the server from the outside. This would look like: ` sudo ufw allow 3000/tcp`

The configuration will depend a little on our network, in this case my wizard configuration was by default, but pay attention to the network you are going to listen in this case it will be the LAN (the only network interface that the machine has).

Basic config

ALT IMG

Here we will add the blockilist as we see fit.

ALT IMG

BINDNS

Once we have our DNS servers configured, it is time to tell pfsense how it is going to be managed on the LAN (where we will normally connect)

Installation

ALT IMG

I already have it installed, but in “Available Packages”, search for Bind and this will appear, click on install and it will appear later in “installed packages”:

ALT IMG

ALT IMG

Potential errors

It is common that depending on the configuration, installation, etc.. this fails and gives an error similar to:

ALT IMG

In this case, we open a shelle in pfsense and update the repos:

ALT IMG

1
pkg update -f ; pkg upgrade -fy; pkg-static clean -ay; pkg bootstrap -fy; pkg-static install -fy pkg pfSense-repo pfSense-upgrade; pkg-static upgrade -fy; pfSense-upgrade fy;

Reboot the system and you should have this error fixed.

1
 reboot

Configuration

This will create a new service:

ALT IMAGE

Copy configuration:

ALT IMG ALT IMG

We create a new view: ALT IMG

We create a new area:

ALT IMG ALT IMG ALT IMG

In “Zone Domain record”, we add the domains that we are interested in, if we do not have any to add, we add the pfsense, since it needs at least 1.

  • Save the changes and that’s it.

Before validating that everything works, we make sure that pfsense uses the dns we want, for that:

ALT IMG

ALT IMG

In the installation I added “saf.local”, “.local” is reserved so we will not be able to use it in this case.

Before proceeding make sure you have a static IP address assigned to the Pi Hole server.

Update this on the pfsense:

  • Allow DHCP/PPP on the WAN to override the DNS server list.
  • Do not utilize the DNS Forwarder/DNS Resolver as the firewall’s DNS server.

Alt text

  • Enable DNS resolver
  • Enable DNSSEC Support
  • And activate the Forwarding Mode

Alt text

It works for us!

ALT IMG

  • Pihole dasboard:

Alt text

  • Adguard dashboard:

Alt text

🚀 Don’t forget to check out the 🚀 VPN configuration to improve your PfSense setup.

This post is licensed under CC BY 4.0 by the author.