Also curious about this, i have a number of hosts to insert and wildcard support would be great
In the mid-term Unbound blocklists will be able to run pattern matching with the switch to Python backend, but to my knowledge it's impossible to derive all IP addresses from all (unknown) subdomains as an alias in the firewall.
Cheers,
Franco
Hi, there,
The post is old, but I'll take the liberty of replying to it as I've been faced with the same problem. I was able to solve it based on other forum user entries.
Unfortunately it requires some tweaking to use wildcard domains.
References- https://github.com/opnsense/core/issues/4145
- https://gist.github.com/PiDroid-B/078198bc84c1e8451d5fd331b46b332d
1. Create Aliases for Each wildcardFor each domain that uses a wildcard, create two aliases "External (advanced)" (e.g., _a and _b).
Then create a "Host(s)" alias containing the two externals created above.
Example Aliases for Multiple Domains:
- Microsoft_IPs_a
External (advanced)- Microsoft_IPs_b
External (advanced)- Microsoft_IPs
Host(s)2. Configure DNSMASQ on Port 53530- Navigate to Services > DNSMASQ in the OPNsense web interface.
- Set DNSMASQ to listen on port `53530`.
Edit the DNSMASQ Configuration File
Access the firewall via CLI/SSH and edit the DNSMASQ configuration:
vi /usr/local/etc/dnsmasq.conf.d/dnsmasq-ipset.conf
Example Configuration File:
Replace the domain names and alias names with those relevant to your environment.
# Add the response for certain A/AAAA lookups to an OPNsense alias
ipset=/microsoft.com/windowsupdate.com/windows.net/Microsoft_IPs_a,Microsoft_IPs_b
# Uncomment these if Unbound is still your primary DNS server; otherwise, it may cause a loop
no-resolv
server=1.1.1.2
server=1.0.0.2
server=9.9.9.9
server=149.112.112.112
3. Configure Unbound DNS to Use DNSMASQ for specific domain resolutionUnbound DNS will forward specific queries to DNSMASQ to handle the aliases.
Navigate to Services > Unbound DNS > Overrides and create an entry in "Domain Overrides".
Example Entry:
Domain: microsoft.com
IP: 127.0.0.1@53530
Domain: windowsupdate.com
IP: 127.0.0.1@53530
Domain: windows.net
IP: 127.0.0.1@53530
4. Create a Cron Job to Flush Alias EntriesTo prevent aliases from growing indefinitely and containing obsolete data, set up a cron job to flush the alias entries periodically (e.g., every 48 hours).
Create the Action Configuration File
vi /usr/local/opnsense/service/conf/actions.d/actions_alias-flush.conf
Add the Following Content:**
[flush]
command:/usr/local/bin/flock -n -E 0 -o /tmp/filter_update_tables_blk.lock /usr/home/alias-flush.sh
parameters: %s
type:script_output
message:Alias IPs flushed
description:Flush IPs from alias
Reload the system to make the cron job task appear
service configd restart
5. Create the Flush ScriptThis script will handle flushing the IPs from the specified alias.
vi /usr/home/alias-flush.sh
Add the Following Content:
#!/bin/sh
# Check if the alias name is provided as a parameter
if [ -z "$1" ]; then
echo "Error: No alias name provided."
exit 1
fi
ALIAS_NAME="$1"
pfctl -t "$ALIAS_NAME" -T flush
if [ $? -eq 0 ]; then
echo "Alias '$ALIAS_NAME' flushed successfully."
exit 0
else
echo "Error while flushing alias '$ALIAS_NAME'."
exit 1
fi
Make the Script Executable
chmod 755 /usr/home/alias-flush.sh
6. Schedule the Cron Jobs for Each AliasCreate cron job for each alias to flush them alternately (e.g., *_a` and *_b`) every 48 hours.
This rotation ensures that the aliases do not accumulate obsolete data.
Example Cron jobs:
enabled: Check
Minutes: 4
Hours: 3
Days of the months: *
Months: *
Days of the week: 1,3,5,7
Command: Flush IPs from alias
Parameters: Microsoft_IPs_a (Must be the exact name of you external alias)
Description: Flush - Microsoft_IPs_a
enabled: Check
Minutes: 5
Hours: 3
Days of the months: *
Months: *
Days of the week: 2,4,6
Command: Flush IPs from alias
Parameters: Microsoft_IPs_b (Must be the exact name of you external alias)
Description: Flush - Microsoft_IPs_b
7. Configure Firewall Rules Using the AliasesCreate firewall rules based on your requirements and use the combined aliases.
When users perform DNS resolutions, the aliases will dynamically populate with the relevant IPs.
If Unbound has a cached resolution, the request might not be forwarded to DNSMASQ, preventing the client from communicating with the desired IP.
To resolve this issue, restart the Unbound service to clear the cache.