Bookmark

How to Redirect All DNS Queries to OPNsense

Outdated

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.

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.

 Screenshot
DNS rewrite

On a Windows PC:

1
2
ipconfig /flushdns
nslookup 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 😉


0 Bình luận

Góp Ý / Bình Luận / Đánh giá