How to redirect dns from UniFi Security Gateway to Pi-hole
Introduction
With this redirect I make sure that all my devices use my own DNS settings. In this case all DNS traffic is going to my Pi-hole, but that could also be AdGuard Home, for example.
Requirements
You need a UniFi Security Gateway (USG) so you can use the config.gateway.json
settings.
How To
Find the right interface
-
Log in to the USG with a SSH connection
-
Lookup the interface
Run the following command:
Check if
eth1
is the interface with your gateway IP. For example192.168.1.1
. Make a note which interface is used.
Create config.gateway.json
-
Log in to the UniFi Controller
-
Obtain the id of the site
In the address bar, the id will appear after
/manage/site
. In my casedefault
is the id of the site. -
Modify config.gateway.json
Log in to the machine where the UniFi Controller is running, for example the host where the container is running. If you are using the container the
sites
folder is located inunifi/data
. Then you can save the following code tounifi/data/sites/default/config.gateway.json
and replacedefault
with the name of your site:Instructions:
- Required Remove all comments starting with
#
- Required Replace
192.168.x.xx
with the IP address of Pi-hole - Required Replace
eth1
with the interface you noted earlier
- Required Remove all comments starting with
Apply the settings and check the results
-
Test on Windows or go to the next step
Go to the Command Prompt and run the following commands:
This query will not be found in the Pi-hole logs.
-
Apply the
config.gateway.json
settingsOpen the UniFi Controller and go to
Devices
. Click on theUSG
, thenSettings
(gear icon). Go toTrigger Provision
and click onTrigger Provision
. -
Repeat the test
Go to the Command Prompt and run the following commands:
This query will now be found in the Pi-hole logs.
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.