EDIT: I found the following tutorial after posting this (and then finding some sites not resolving properly): https://labzilla.io/blog/force-dns-pihole .... this tutorial better describes the 3 NAT rules that are implemented and detail how they operate. I have seen that these rules operate better than how I have things configured.
Previously, I have setup multiple AdGuard Home instances on my personal network and have all VLAN's pointing to those instances. This works well, like 99% of the time. However, there are times where kids or others have devices (Amazon tablets, Roku TV's, etc) that have external DNS resolvers (like google dns) as a fallback in case there are issues with the local DNS. Now... I literally want to avoid this. Part of this is due to restricting children's access on the Internet, some is due to making sure that everything gets logged. When these devices are permitted to bypass local DNS resolvers, it opens up the Internet for wide consumption, such as being able to access YouTube without restriction.
Here is my method of forcefully redirecting all DNS requests to AGH on OPNsense.
Now, I understand from others, that I have a complicated setup and I have only continued to complicate this network, all in the name of network security and segregation since there are some services that I expose publicly.
First, since I have two AGH instances and then two Windows Server Active Directory servers as primary DNS, I setup an Alias for those instances:
Firewall > Aliases
Create a new Alias, providing a name that relates to AGH... I chose "AdGuard_LAN_DNS_Servers
" ... it specifically identifies that it is AdGuard related, but also specifies that it is for LAN.
- Type: Hosts
- Categories: enter something if you want... I chose "DNS"
- Content: Enter each individual IP, pressing Enter after each.
Save.
Go to Firewall > NAT > Port Forward
, create a new rule. (we'll refer to this as Rule 1 as a reference for this post)
Enter the following:
- Interface: LAN
- TCP/IP Version: IPv4
- Protocol: TCP/UDP
- Destination/Invert: Checked
- Destination: LAN net
- Destination port range: DNS
- Redirect target IP: AdGuard_LAN_DNS_Servers (use alias name from above)
- Redirect target port: DNS Pool Options: Round Robin or Random. I chose Round Robin with Sticky Address
- Category: DNS (not necessary though)
- Description: enter something if you want
- NAT Reflection: Use system default
- Filter Rule Association: create system rule
Save. Apply changes.
At this point, the rule should cause redirection to occur. You can test this. For instance, on Linux, when the above rule is disabled, if you run the command host yahoo.com 8.8.8.8
, this will force an NSLookup using the name server 8.8.8.8 (google's DNS) and will return valid values. However, once you enable the rule and apply the configuration changes, if you attempt the same command again, it should fail.
I have applied the same rules for every single VLAN that I have setup and every VLAN is now unable to access external DNS.
The only remaining permission that I needed to have added is to permit my AdGuardHome instances to effectively "bypass" the restrictions that OPNsense has now put in.
Firewall > Rules > LAN
:
Create rule (we'll refer to this as rule 2)
- Protocol: TCP/UDP
- Source: AD_DNS_Servers
- Destination: any
- Gateway: WAN
This permits my AD DNS Servers to access the internet, without going through the port forwards.
Create another rule: (we'll refer to this as rule 3)
- Protocol: TCP/UDP
- Source: AdGuardHome_LAN_DNS_Servers
- Destination: AD_DNS_Servers
- Port: DNS
Save; This gives permission for AGH instances to access my local primary DNS servers that are "upstream" of AGH.
Finally, We need to make sure that our Firewall rule ordering is in order, to make sure to permit access without causing blockers.
I have rules configured in the following order on Firewall > Rules > LAN
:
2, 3, 1
This permits all DNS Servers to access WAN. Then Permits AGH to access AD DNS Servers port 53. Finally, the port forward that reflects all DNS requests to AGH.
If you have questions, please feel free to ask below!