Installing AdGuard Home on PFSense

Today I will show how to install AdGuard Home on PFSense. While I haven’t tested this on OPNSense. The binary for FreeBSD (PFSense) may work on HardendBSD (OPNSense).

Why use AdGuard Home?​



  • Pretty UI: While PFBlockerNG can do DNS Blocking, it has a much more complex UI.
  • AdGuard Home UI is easier to use
  • Built in Encrypted DNS: AdGuard Home supports build in encrypted DNS (DNS over TLS, DNS over HTTPS).
  • Different methods of querying: AdGuard Home supports Parallel Querying where multiple servers are queried at once. This is especially good if you have a unreliable network.
  • FreeBSD Support: AdGuard Home supports FreeBSD so you won’t have to virtualize anything.
  • Modify DNS TTL to keep DNS Records in cache for longer.

Step 1: Disable your PFSense DNS Resolver/Forwarder.​




Login to your PFSense Firewall web UI and go to Service> DNS Resolver and uncheck “Enable”, click Save

Do the same for DNS Forwarder if its enabled.

Step 2: Go to AdGuard home releases page and get the FreeBSD Version:​



Go to Releases · AdguardTeam/AdGuardHome

Then get the latest version of AdGuard for FreeBSD (as PFSense runs on FreeBSD). Most likely you will have 64Bit version of PFSense so you need AdGuardHome_freebsd_amd64.tar.gz . However if you have 32 Bit PFSense you need AdGuardHome_freebsd_386.tar.gz.

Step 3: SSH into your PFSense box​

Right click and copy the link of the release.

SSH into your PFSense box using Putty or SSH on WSL and enter the following commands:

Code:
cd /
mkdir opt
cd opt
fetch https://github.com/AdguardTeam/AdGuardHome/releases/download/v0.104.0-beta2/AdGuardHome_freebsd_amd64.tar.gz

Make sure to change the url in fetch to the one you got on Step 2.
Code:
tar -xvf AdGuardHome_freebsd_amd64.tar.gz
cd AdGuardHome
./AdGuardHome

This command executes AdGuardHome so that we can do initial configuration in the browser.

Step 4: Initial Configuration​



Go to your router URL with port 3000 on your browser. In my case its http://192.168.5.1:3000 . Replace 192.168.5.1 to your PFSense Address.

It should open the web interface of AdGuard Home.

Click on Get Started.

Now you will see a screen asking to setup interfaces for AdGuard UI and Resolver to run on. You need to set both the Admin Interface and DNS Server Interface to your LAN Interface. In my case it is igb3. It will also show the IP of the Interface next to it to help you identify easily. In my case it is 192.168.5.1 which is the IP Address of my router.

Set the same interface for DNS Server.

Also, make sure to change the Port of web interface from 80 to something that is unlikely to be used on the network. Lets say port 12838. Choose any high port that isn’t likely to conflict with your other applications.

Next enter a username and password for your AdGuard Home. Make sure to use a strong password.

Click on Next and then Open Dashboard.

Now that initial configuration of AdGuard is done. Go back to PFSense SSH and terminate AdGuard using Ctrl+C.

Step 5: Installing some extra packages:​

To make sure that AdGuard gets filters without errors, you will need to install ca_root_nss

Run this command on the PFSense SSH
Code:
pkg install ca_root_nss

Next you will need to install screen so that you can run AdGuard even when ssh is closed.

Code:
pkg install screen

Lets also install nano text editor so we can write and edit simple text files.

Code:
pkg install nano

Install shellcmd PFSense Package from WebUI. Its under System>Package Manager>Installed Packages:


Step 6: Making AdGuard Home start on boot:​

Go to Services>shellcmd and click Add

Command: /usr/local/bin/screen -S AdGuardHome_screen -d -m /opt/AdGuardHome/AdGuardHome
Shellcmd Type: shellcmd
Description: AdGuard


Click Save
Reboot PFSense and AdGuardHome will start up.

Step 7: Set Filters and DNS Resolvers for AdGuard Home:​



Go to the Web UI of AdGuard Home. It is at http://192.168.5.1:12838 . Where 192.168.5.1 is the IP of your PFSense and 12838 is the Port of Web Interface of AdGuard which we set in Step 4.

Login with your username and password which you set in Step 4.

Now go to Settings>DNS Settings

Use the upstream DNS Server of your choice. These are my resolvers

Code:
https://dns10.quad9.net/dns-query
tls://dns.google
tls://1.1.1.1
https://doh.opendns.com/dns-query

Find more Encrypted DNS Resolvers at DNS Privacy Public Resolvers - DNS Privacy Project - Global Site

Set the query mode to “Parralel Requests” for faster queries.

By default AdGuard Home only uses “AdGuard DNS filter” however you can add your own filters such as

https://www.malwaredomainlist.com/hostslist/hosts.txt

https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts

and enable the filters Disabled by default.

However, keep in mind, higher the number of domains higher the likelihood of false positives.

Step 8: Set PFSense to use the AdGuard DNS:​


Go to System> General Setup in PFSense Web Interface and set the DNS Server to 192.168.5.1 and remove any other resolvers.

That’s it AdGuard Home is up and running on PFSense


Step 9: Test AdGuard​



Go to your PFSense SSH and type in:

Code:
dig @192.168.5.1 google.com

Where 192.168.5.1 is the IP of your router

It should output the IP Address of Google.
dig @192.168.5.1 google.com

; <<>> DiG 9.16.1-Ubuntu <<>> @192.168.5.1 google.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 946
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com. IN A

;; ANSWER SECTION:
google.com. 10 IN A 74.125.130.147

;; Query time: 0 msec
;; SERVER: 192.168.5.1#53(192.168.5.1)
;; WHEN: Thu Jan 07 16:34:08 IST 2021
;; MSG SIZE rcvd: 44

On Windows you can do

Code:
nslookup google.com 192.168.5.1

to test the resolver
 
Last edited:

JB701

CCP ate my homework
Messages
1,527
Location
Delhi
ISP
TriplePlay/Excitel
Yes but you have to be careful. Since then you have to make resolver public.

Alternatively you can use ufw to block access to port 53 from everywhere except your public ip (this is a problem is ip changes). What you can do is set it to the IP range for example 59.177.1.0/24
 
Messages
167
Location
Kolhapur, Maharashtra
ISP
Airtel 4G & LCO
@JB701 yep am aware of those security groups from which we can manage inbound traffics, ip's, ports etc.

I already have setup up pi-hole DNS resolver on AWS and only allowed my public IP (despite in CG-NAT, my internal IP may get change but public IP is same always, but adding subnet CIDR is better then adding exact IP for CG-NAT users)

since DNS query where un encrypted in pi-hole so I thought of shifting to ad-guard. I used VPS since I don't have rasberry pi or any other spare computer where I can host these service.
 

JB701

CCP ate my homework
Messages
1,527
Location
Delhi
ISP
TriplePlay/Excitel
Feel free to host it on a VPS. Its very easy. You can setup a systemd service instead of having it start by script rc.d on Linux.
 

JB701

CCP ate my homework
Messages
1,527
Location
Delhi
ISP
TriplePlay/Excitel
Initially I was on 192.168.5.0/24 but soon realized it wasn't ''enough'' for macvlan docker containers. So I changed it to 192.168.4.0/22 but gateway is still 192.168.5.1

With /22 I can put Docker containers on 192.168.7.0/24

Edit: I see what you were asking now lol, it's 192.168.5.1 on one screen and 192.168.4.1 on another I'll fix that.
 
Last edited:

JB701

CCP ate my homework
Messages
1,527
Location
Delhi
ISP
TriplePlay/Excitel
Adguard home stores settings in a yaml file. I don't think it'll be gone after upgrade.

shell cmd is also supposed to work through upgrade. I had written the guide but using rc.d instead but shellcmd is better.

I didnt want to virtualize because I know it can result in issues sometimes with performance.

When stable upgrade comes I'll update here if it works or not.
 
Last edited:

JB701

CCP ate my homework
Messages
1,527
Location
Delhi
ISP
TriplePlay/Excitel
This guide got more popular than I expected it to with people referencing it outside of IBF. I have fixed some errors with this.

Google searching "AdGuard Home on PFSense" shows this at top lol.

Anyways, AdGuard Home has been working very well. DNS Queries are fast and it starts as soon as PFSense boots so no worrying about reboots screwing up DNS.

The only "bad" part is that AdGuard updates have to be manually done. But I plan to make a script (my scripting and programming skills are pretty meh so I'm not sure) to update it automatically.
 
Last edited: