🌐 VI | EN

How to Redirect All DNS Queries to OPNsense

Nghia Phan
Nghia Phan
🌐 Bản tiếng Việt Technical Guide Views

{{< notice “warning” >}} Outdated {{< /notice >}}

My OPNsense installation runs AdGuard Home to filter advertisements and malicious websites, but many phone and computer applications hard-code external DNS servers such as Google DNS or 1.1.1.1. This can bypass AdGuard Home.

The following rule redirects all DNS queries to AdGuard Home (local DNS). Even when a client chooses another DNS server, queries sent over port 53 are redirected to OPNsense. This reduces DNS leaks and makes the local policy effective.

{{< notice “tip” >}} See the AdGuard Home installation guide. {{< /notice >}}

1. Open FirewallNATPort Forward

Firewall > NAT > Port Forward

2. Click + to add a rule

Click the plus button

3. Configure the rule
FieldSelectionNotes
InterfaceLAN
ProtocolTCP/UDP
Destination / InvertChecked
DestinationLAN addressSelect the network to redirect, such as LAN or Guest.
Destination port rangeDNS to DNS
Redirect target IPSingle host or Network: 192.168.1.1Replace with the OPNsense LAN address.
Redirect target portDNS
NAT reflectionDisable

Leave fields not listed above at their defaults.

4. Click Save and then Apply Changes

New rule

5. Open FirewallRulesLAN

LAN rules

6. Move the new rule above the default LAN allow rule

Rule order

Click Apply Changes.

7. Test the result

For testing, I configured an AdGuard Home DNS rewrite for router.com to return 172.16.1.2. {{< collapse “Screenshot” >}} DNS rewrite {{< /collapse >}}

On a Windows PC:

ipconfig /flushdnsnslookup router.com 8.8.8.8

Although the client asks 8.8.8.8, OPNsense redirects the DNS query to AdGuard Home, so the result should be 172.16.1.2. Result

Good luck 😉

Comments & Discussion

Share your thoughts, ask questions and feedback

Markdown & QQ Emoji
Loading comments...