HOWTO - Redirect all DNS Requests to Opnsense

Started by Cypher100, July 26, 2018, 03:16:37 AM

Previous topic - Next topic
Quote from: meyergru on September 04, 2025, 09:24:14 PMI just tried to do this on my own OpnSense, however, I noticed two problems:

1. I use an nmap scan like:

nmap -sn -n --reason -PE -PS135,445,3389,22,80,443,8888 -PU53 --min-parallelism 100 --max-rtt-timeout 100ms --host-timeout 5s -T4 -oX - $network

to detect live systems on my own VLANs and on some site-2-site networks connected over VPN.

Because of nmap checking if the UDP port 53 is open on the targets, it will issue DNS requests that are not targeted to the LAN address of OpnSense. Since those will then be redirected to OpnSense by the given NAT port forwarding rule:

Interface: LAN
Protocol: TCP/UDP
Destination / Invert: Checked
Destination: LAN address
Destination Port: DNS
Redirect target IP: 127.0.0.1
Redirect target port: DNS
NAT reflection: Disable

This will result in a positive answer - essentially, all hosts will be flagged as being "up".

I order to fix this, one should probably use an RFC1918 alias and use !RFC1918 for the destination. In my case, I grouped all the local VLANs together, so the NAT rule becomes:

Interface: LOCAL_VLANS (alias containing all local VLANs)
Protocol: TCP/UDP
Destination / Invert: Checked
Destination: RFC1918 (alias containing all RFC1918 networks)
Destination Port: DNS
Redirect target IP: 127.0.0.1
Redirect target port: DNS
NAT reflection: Disable

You could get away by using !"LOCAL_VLANs net" as destination, but this will exclude the site-2-site subnets, so !RFC1918 is safer.


2. I wanted the same functionality for IPv6 (this was once discussed without a solution here), for which you have to create a second NAT rule that looks like this:

Interface: LOCAL_VLANS (alias containing all local VLANs)
Protocol: TCP/UDP
Destination / Invert: Checked
Destination: This Firewall
Destination Port: DNS
Redirect target IP: LAN_IPv6 (alias containing a dynamic IPv6 host with the EUI-64 of any VLAN interface that listens to DNS)
Redirect target port: DNS
NAT reflection: Disable

Note that the LAN_IPv6 alias must contain a routeable IPv6 for this to work, so ::1 or fe80::xxxx are out of the question.

Can you explain a little bit how you created the LAN_IPv6 alias? I have several vlans and my dns server is adguardhome running on OPNsense and listening to all vlans. OPNsense itself has an ipv6 address that the lower 64 bits is just 252. Do I select "dynamic ipv6 host" as the alias type, set the appropriate vlan in "interface" and put ::252 in the "content"? Do I create one alias for each of my vlans and one NAT rule for each one aswell?