OPNSense


HAProxy Simple Configuration for local webserver

Parameters for this setup

Local webserver is on ip address 192.168.1.200 and uses port 80

Step 1: Define a Real server

afbeelding.png

  1. Define a Virtual service->Backend Pool
    • Name: anything you like
    • Servers: The server you defined in the step 1 (remember to press TAB after entering server name) 

afbeelding.png

afbeelding.png

Step 2: Define a condition:

afbeelding.png

Step 3: Define a rule

afbeelding.png

Step 4: Define a Virtual Service

Under Public Service:

afbeelding.png

afbeelding.png

Adguard Home communications error to 127.0.0.1#53: connection refused

When you cannot update OPNsense and you see an error in a SSH session when you try to run:

root@OPNsense:~ # dig @127.0.0.1 -p 53 google.com

dig @127.0.0.1 -p 53 google.com

You probably have a wrong binding in the Adguard config file.

To solve this issue:

nano AdGuardhome.yaml
cd /usr/local/AdGuardHome

Change the bind (from a local ip address) to:

dns:
  bind_hosts:
    - 0.0.0.0

Then restart Adguard Home

Disable IPv6 in OPNSense

Set IPv6 on all interfaces on ' None' and also remove the ' Allow IPv6' vinkje.

afbeelding.png

Remove also the ' Allow IPv6' rule in de firewall rules:

afbeelding.png

How to enable the HAProxy statistics page in OPNsense

Step 1: Edit Global Settings

In the left-hand menu, go to Services , select HAPproxy and then and then Settings.

afbeelding.png

Step 2: Configure Statistics in Frontend Settings

      • stats enable
        stats uri /haproxy?stats
        stats realm Haproxy\ Statistics
        stats auth admin:password123
        Replace admin with your desired username and password with a strong password.
      • Click on “Save” and then apply changes by clicking on “Apply”.

afbeelding.png


Step 3: Configure Firewall Rules

  1. Allow Access to the Statistics Port:

    • Navigate to Firewall > Rules > LAN
    • Create a new rule with these parameters:
      • Action: Pass
      • Protocol: TCP
      • Destination: This Firewall
      • Destination Port Range: Other and the 8822
      • Description: Access the Statistics page
      • Leave everything else to the default values
      • Save the rule and click on “Apply Changes”.

afbeelding.png


Step 4: Test Access to the Statistics Page

  1. Open a web browser from a device allowed by your firewall rules.
  2. Enter the URL for accessing statistics, such as:
http://192.168.2.1:8822/haproxy?stats

Enter the username and password you configured earlier when prompted.

If everything is configured correctly, you should see HAProxy’s statistics page displaying real-time data about connections, backends, frontends, etc.

afbeelding.png

HowTo Restore a Google Drive backup file in OPNsense

A description on how to use Google Drive backup feature in OPNsense can be found here:

https://docs.opnsense.org/manual/how-tos/cloud_backup.html

But this is a rather complicated process, so read carefully!

You probably already know that you need a P12 key to store the backup files on Google Drive. Why is that?

The P12 key you created for use with Google Drive backups in OPNsense plays an important role in the authentication process between OPNsense and Google’s API. Here's exactly what the P12 key does during the backup and restore process:


1. What does the P12 key do?

The P12 key (a so-called PKCS#12 file) contains a private key that OPNsense uses to cryptographically authenticate itself as a service account to Google. It is linked to a Google Cloud service account that has access to your Google Drive.

In short:
  1. Authentication
    When creating a backup, OPNsense connects to the Google Drive API.

  2. Signing a JWT (JSON Web Token)
    OPNsense generates a specially formatted token (JWT) and signs it with the private key from the P12 file.

  3. Token exchange with Google
    The signed JWT is sent to Google’s OAuth 2.0 token endpoint, and in return, OPNsense receives an access token.

  4. Access to Google Drive
    With that access token, OPNsense can upload or download files from Google Drive on behalf of the service account.


Why is this necessary?

Unlike user-based authentication (which uses a browser and interactive OAuth consent), this is a server-to-server authentication method. That’s ideal because OPNsense needs to perform automated backups without requiring manual login or user consent each time.


What happens during a restore?

During a restore:

  1. OPNsense follows the same authentication process to access Google Drive.

  2. It retrieves the list of XML backup files.

  3. The user selects a file, and OPNsense downloads it via the API (authorized through the same token process).


Important security note

2. How to restore a backup from Google Drive when using Linux?

With kio-Gdrive installed in Dolphin is not working because Google blocks this

That’s a known limitation of kio-gdrive in combination with Google’s stricter security policies. Google now blocks applications that are not verified or have not gone through OAuth validation, which applies to many open-source or locally installed apps like kio-gdrive.


Why does Google block kio-gdrive?

Google sees kio-gdrive as an "unverified app" requesting access to sensitive scopes (such as full access to your Drive). Because of that, Google refuses to complete the OAuth flow.


Solutions

1. Use rclone instead of kio-gdrive (recommended)

As mentioned earlier, rclone is the most robust and Google-compliant way to access Google Drive locally without running into OAuth issues. Rclone is recognized by Google, uses approved scopes, and just works.

➡️ Advantage: Stable and compatible with service accounts.

Installeren en instellen

Install rclone:

sudo apt install rclone

Configure rclone for Google Drive:

rclone config

Choose:

Verify your setup:

rclone ls gdrive:

Download a backup file:

rclone copy gdrive:opnsense-backups/config-2025-05-28.xml .

Upload the file via the OPNsense web interface:

Go to:
SystemConfigurationBackupsRestore → Upload the .xml file.


2. Create your own Google API project (advanced)

If you really want to keep using kio-gdrive (not recommended), then you’ll need to:

  1. Go to the Google Cloud Console.

  2. Create a new project.

  3. Enable the Google Drive API.

  4. Create OAuth 2.0 client credentials.

  5. Manually configure these credentials in kio-gdrive.

➡️ Google will still show a warning ("unverified app") and you’ll need to bypass it by clicking “Advanced” → “Proceed to...”.

⚠️ This is unstable and error-prone, especially if you use 2FA.


3. Download backups manually via your browser 

This is the easiest method for occasional use: just log in to Google Drive via your browser and download the XML backup file manually. Because I have no need for frequent accessing the backup files I use this method and select the downloaded file under Restore:

Screenshot_20250528_091752.png

You don't need the P12 key to restore, because it is already known in OPNsense.

Run frequent Speedtest in OPNsense

To be able to use the Speedtest plugin, you need to install the Mimugmail repository:

https://github.com/mimugmail/opn-repo

Then go to System>Firmware>Plugins and install the 'os-speedtest-community' plugin in OPNsense.

Screenshot_20250530_111529.png

Yes, there is a "misconfigured" notice, but everything will work fine :-)

In OPNsense "Reporting > Speedtest", locate desired server and make note of server ID, (the numbers between the brackets in "(#####) Server Name")

go to "System > Settings > Cron" create/edit the speedtest entry.
Set "Command" field to "Run speedtest [serverid]"
Set "Parameters" field to "#####" you dont need to append with "--server"... literally... just the numbers. 

Screenshot_20250530_112046.png

Under Reporting>Speedtest you can find the results. Just click on the little "show log" switch.

Screenshot_20250530_111351.png

 

support-gert.jpg

Voorgestelde waarden voor Advanced tab in Unbound

Screenshots staan onderaan deze post.

Basisinstellingen voor privacy en veiligheid:

  1. Hide Identity:

    • Aan: Verbergt de identiteit van de Unbound-server (zoals het feit dat je Unbound gebruikt) in DNS-responses. Dit is handig voor privacy.

  2. Hide Version:

    • Aan: Verbergt de versie van Unbound die wordt gebruikt in de DNS-responses. Dit voorkomt dat een aanvaller de versie van je server kan achterhalen.

  3. Prefetch DNS Key Support:

    • Aan: Verbetert de prestaties van DNSSEC-queries door vooraf de sleutels van de domeinen in te laden, wat de latentie kan verminderen.

  4. Harden DNSSEC Data:

    • Aan: Zorgt ervoor dat DNSSEC-resolutie strikt wordt gehandhaafd. Dit betekent dat alle DNSSEC-handtekeningen strikt worden gecontroleerd, wat de veiligheid verhoogt.

  5. Aggressive NSEC:

    • Aan: Verhoogt de veiligheid door gebruik te maken van de agressieve NSEC-beveiliging, wat voorkomt dat er onterechte 'NXDOMAIN' antwoorden worden gegeven voor niet-bestaande domeinen.

  6. Strict QNAME Minimisation:

    • Aan: Minimaliseert de hoeveelheid informatie die Unbound naar upstream DNS-servers stuurt, wat kan helpen om je privacy te beschermen en gegevenslekken te verminderen.

  7. Rebind protection networks:

    • Aan: Activeer dit om rebind-aanvallen te voorkomen, waarbij een aanvaller je DNS-resolver probeert te misleiden door interne IP-adressen te maskeren.

Prestatiesettings:

  1. Outgoing TCP Buffers:

    • Standaardinstellingen zijn vaak prima, maar je kunt het verhogen als je een snelle verbinding hebt met veel gelijktijdige queries. Dit kan helpen bij het omgaan met grotere verzoeken via TCP.

  2. Incoming TCP Buffers:

    • Eveneens kun je de standaardinstellingen gebruiken, maar bij hoge verkeersvolumes kan het verhogen van de bufferwaarde helpen om betere prestaties te bereiken.

  3. Number of queries per thread:

    • 2 tot 4 is een goede instelling voor de meeste omgevingen, afhankelijk van de belasting. Verhoog dit als je veel queries verwerkt.

  4. Outgoing Range:

    • Standaard is 10-20 prima. Verhoog dit om grotere hoeveelheden gelijktijdige uitgaande verzoeken te verwerken.

  5. Jostle Timeout en Discard Timeout:

    • Deze zijn goed ingesteld op default, maar als je last hebt van time-outs bij het resolven van verzoeken, kun je experimenteren met langere time-outs.

Cachinginstellingen:

  1. Message Cache Size:

    • Dit kan verhoogd worden voor grotere netwerken (bijv. 50-100 MB), afhankelijk van de hoeveelheid DNS-verkeer die je genereert.

  2. RRset Cache Size:

    • Vergroot deze als je veel verzoeken hebt naar dezelfde domeinen. Standaardwaarden zijn vaak voldoende, maar grotere netwerken kunnen baat hebben bij een grotere cache.

  3. Maximum TTL for RRsets and messages:

    • Maximaal 86400 (1 dag) is een gangbare instelling voor de TTL. Dit bepaalt hoe lang records worden bewaard. Dit kan de prestaties verbeteren, maar verhoogt het risico van verouderde informatie.

  4. Minimum TTL for RRsets and messages:

    • Standaardinstelling van 0 is prima, tenzij je wilt forceren dat bepaalde records voor een minimumtijd worden bewaard.

  5. TTL for Host Cache entries:

    • Dit moet niet te hoog ingesteld worden. 900 seconden (15 minuten) is een gangbare waarde, wat een goede balans biedt tussen prestaties en actualiteit van gegevens.

  6. Keep probing down hosts:

    • Uit is vaak goed, tenzij je wilt dat Unbound blijft proberen om onbereikbare hosts te bereiken, wat de prestaties kan beïnvloeden.

  7. Number of Hosts to cache:

    • Een hogere waarde, zoals 1000, kan nuttig zijn voor grotere netwerken. Dit bepaalt hoeveel hostnamen in het cachegeheugen worden bewaard.

Logginginstellingen:

  1. Log Queries:

    • Uit voor minder logverkeer en meer privacy, tenzij je specifieke diagnostiek nodig hebt.

  2. Log Replies:

    • Uit is meestal voldoende om de belasting op je logs laag te houden.

  3. Tag Queries and Replies:

    • Uit voor betere prestaties, tenzij je een gedetailleerde audit nodig hebt.

  4. Log local actions:

    • Aan kan handig zijn voor probleemoplossing, maar dit kan leiden tot veel logverkeer.

  5. Log SERVFAIL:

    • Aan kan nuttig zijn voor diagnostiek van problemen, maar zet het uit voor meer geoptimaliseerde prestaties.

Diverse instellingen:

  1. Serve Expired Settings:

    • Aan: Verbetert de beschikbaarheid van gegevens door verlopen gegevens toch te serveren als tijdelijke oplossing (bijvoorbeeld als de upstream DNS niet reageert).

  2. Serve Expired Responses:

    • Aan zorgt ervoor dat verouderde gegevens toch kunnen worden bediend, maar dit kan veiligheidsrisico's inhouden als je vertrouwt op de validiteit van de gegevens.

  3. Extended Statistics:

    • Aan voor gedetailleerdere statistieken, maar dit verhoogt de belasting op de server.

  4. Log Level Verbosity:

    • 2 of 3 voor gedetailleerde logs. Je kunt dit verhogen naar 4 als je gedetailleerde foutopsporingsinformatie nodig hebt.

  5. Log validation level:

    • Minimaal of Fouten voor minder logverkeer, tenzij je actief DNSSEC-validatieproblemen onderzoekt.

Aanbevolen instellingen (samenvatting):

  • Privacy: Hide Identity, Hide Version, Harden DNSSEC Data, Strict QNAME Minimisation.

  • Veiligheid: Rebind protection networks, Aggressive NSEC.

  • Prestaties: Prefetch DNS Key Support, Outgoing Range, Number of queries per thread.

  • Cache: Message Cache Size, RRset Cache Size, Maximum TTL for RRsets.

  • Logging: Zet logging zoveel mogelijk uit voor betere prestaties, maar log SERVFAIL als je problemen wilt onderzoeken.

Door deze instellingen zorgvuldig af te stemmen, kun je de prestaties, privacy en veiligheid van je DNS-resolutie optimaliseren.

Screenshot_20250603_163844a.png

Screenshot_20250603_163903b.png

Setup os-ddclient for when external IP address changes

Here's a step-by-step guide in English on how to configure os-ddclient in OPNsense to automatically update your Cloudflare DNS records when your external IP address changes (e.g., from your ISP).

If you get the concept of this then you should be able to do this for DuckDNS or Dynu DNS or one of the other options in a similar way.


Prerequisites

Before you begin:


Step-by-step Configuration

1. Enable os-ddclient

Go to:

2. Add a Dynamic DNS Account

Go to:

Now fill in the required fields:

General Settings

Cloudflare API Credentials

You have two options: API Token (preferred) or Global API Key.

If you're using an API Token:

I have made a new API token. When logged in on Cloudflare, go to the top right and click on Profile . Then go to {} API Tokens and add a new token for "Edit zone DNS". Save the token on a safe place.

Screenshot_20250609_144020.png

If you're using a Global API Key:

The use of the Global API key for this is not recommended!

Hostname Details

IP Settings

Click Save, then Apply.

Screenshot_20250609_143848.png


Test the Setup

  1. After saving, go to the Services > Dynamic DNS > Log File.

  2. Click Run now next to your entry to test it.

  3. Check the log to see if the IP update succeeded.


Done!

Your OPNsense box will now monitor your WAN IP and automatically update your Cloudflare DNS A or AAAA record whenever your public IP changes.