Prerequisites#
- Have a configured gateway pointing to a proxy service (transparent proxy). For specific implementation methods, refer to the article Using WireGuard for Transparent Proxying in OPNsense (Advanced) - Kre’s Blog (Recommended), or Setting up tun2socks service on OPNsense - Kre’s Blog. In this article the gateway is
TUNPROXY. - Enable Unbound as a recursive DNS query server.
Steps#
1. Configure Unbound’s DoT#
In Services ‣ Unbound DNS ‣ DNS over TLS, add the following DoT settings (you can also choose your preferred DoT provider):
| Setting | Value |
|---|---|
| Enable | True |
| Server IP | 1.1.1.1 |
| Server Port | 853 |
| Verify CN | one.one.one.one |
| Setting | Value |
|---|---|
| Enable | True |
| Server IP | 9.9.9.9 |
| Server Port | 853 |
| Verify CN | dns.quad9.net |
Apply the changes.
2. Configure Routing Table#
In System ‣ Routes ‣ Configuration, set up the following routing table:
| Setting | Value |
|---|---|
| Network Address | 1.1.1.1/32 |
| Gateway | TUNPROXY |
| Setting | Value |
|---|---|
| Network Address | 9.9.9.9/32 |
| Gateway | TUNPROXY |
If you filled in the IPv6 version of the DNS address in the previous step, remember to select the IPv6 version of the gateway here as well.
3. (Optional) Enable DNSSEC in Unbound#
In Services ‣ Unbound DNS ‣ General, enable Enable DNSSEC Support and apply.
Advantages#
- Satisfies your minor obsession/preference, the resolution process is relatively secure;
- Able to use DNSSEC;
- DNS leaks safe.
Disadvantages#
- Potential traffic loops (see the note above);
- All traffic from all devices to 1.1.1.1/9.9.9.9 will go through the proxy, difficult to supervise;
- If the proxy service is unstable, it will affect the initial query speed (but the second query with cached results will be much faster);
- Some geolocation-based resolution results may return unexpected results due to the proxy.
Why Do This#
Originally, Unbound supported setting Outgoing Network Interfaces, but apparently this feature was removed in version 21.7 and later. Therefore, there are now two methods to implement this functionality:
- Write static routes, which is the method in this article (Reference: adguard home lookups through WG tunnel? - OPNsense Forum);
- First write a route to direct
TUNPROXYtraffic through WAN, then setTUNPROXYas the Upstream Gateway and give it a higher priority (set Priority value lower than WAN), so that all traffic (including OPNsense’s own traffic) goes through the proxy. Couldn’t get this to work, and also felt this setup was too destructive (Reference: Unbound outgoing network interface - OPNsense Forum).
Originally, I wanted to write Floating Rules to match traffic from OPNsense itself and then route it to the proxy gateway, but the connection was matched yet mysteriously couldn’t work. Then I searched randomly online and found the above content, and finally adopted the method in this article. If I figure it out in the future, I’ll try again.

