OPNsenseXXXIII · Logging and Remote LoggingLog retention
Log retention and rotation — keeping what you need, deleting what you do not
What you'll learn
- Describe the daily-file retention model and what bounds it
- Configure Maximum preserved files and Maximum file size for a known disk budget
- Define retention periods aligned with legal and operational requirements
- Recognise the retention gaps between on-disk and remote-forwarded logs
- Apply the deletion discipline required for compliance
Prerequisites
Verified against OPNsense 25.x · FreeBSD 14.x · PF (FreeBSD packet filter) FreeBSD 14.x · Unbound 1.20+ · Kea DHCP OPNsense 25.x plugin · WireGuard in-kernel + OPNsense plugin · strongSwan (IPsec plugin) OPNsense 25.x plugin · OpenVPN 2.6.x · Suricata 7.x · 2026-08-18
Logs are not free. Every line stored costs disk; every line retained past its useful life is a liability. The retention model on OPNsense is two-tier: about a month of daily files on the firewall itself, and whatever the remote destination is configured to keep. The discipline is knowing which tier owns which period, setting the two knobs that bound the local tier, and applying the rules that say when logs must be kept and when they must be deleted.
The two-tier retention model
Tier 1: the daily files on the firewall
- One plain-text file per application per day under
/var/log/<application>/. - Kept for Maximum preserved files files, which defaults to 31.
- Trimmed by a housekeeping job, not overwritten in place.
- Useful life: roughly a month, and searchable for the whole of it.
- Purpose: investigation on the box, without leaving the box.
Tier 2: the remote destination
- SIEM, log server, or cloud aggregation.
- Indexed, cross-referenced against other sources, retained on the receiver’s policy.
- Useful life: months to years.
- Purpose: long-term investigation, compliance, threat hunting, correlation with the rest of the estate.
These are not redundant, and neither is a substitute for the other. Tier 1 is genuinely useful — a month of greppable firewall history is enough for most incidents — but it dies with the firewall, and a firewall that has been compromised is a firewall whose local logs cannot be trusted. Tier 2 survives the box and is the only tier that can be relied on for evidence.
The two settings
Both live under System → Settings → Logging, on the “Local” tab.
| Setting | Default | What it does |
|---|---|---|
| Enable local logging | on | Turn off to stop writing local files entirely — intended for installs on flash media, and it makes remote logging mandatory rather than optional |
| Maximum preserved files | 31 | How many files are kept per application. With one file per day this is a day count; with Maximum file size set it is a file count and no longer a day count |
| Maximum file size | empty | Size in MB at which the current file is rotated early. Empty means never |
The interaction between the last two is the part that catches people. Left at the defaults, thirty-one files means thirty-one days. Set Maximum file size to 50 MB on a firewall that writes 200 MB of filter log a day, and the file rotates four times a day, so thirty-one files is now about eight days. Bounding the disk shortens the window; the two settings cannot both be chosen freely.
$ ls /var/log/filter/ | tail -5; echo '---'; du -sh /var/log; df -h /var/logfilter_20260814.0001.log
filter_20260814.0002.log
filter_20260814.0003.log
filter_20260814.log
latest.log
---
1.4G /var/log
Filesystem Size Used Avail Capacity Mounted on
/dev/gpt/rootfs 30G 8.2G 20G 29% /
Illustrative output
What the housekeeping job actually does
Rotation on OPNsense is not size-triggered inside syslog-ng. syslog-ng starts a new file when the date changes, and everything else is done by a separate job — configctl syslog archive, which appears in the cron action picker as “Rotate log files”. OPNsense schedules it automatically once an hour. For each log directory it:
- Checks the newest file against Maximum file size. If it is over, renames it with a four-digit sequence suffix —
filter_20260814.0001.log— and restartssyslog-ngso a fresh unsuffixed file starts. - Sorts the files newest first and deletes everything past Maximum preserved files.
- Repoints the directory’s
latest.logsymlink at the newest file.
Two consequences are worth holding on to. Deletion is permanent and unattended: a file trimmed by step 2 is unlinked, not archived, not compressed, not moved. And because step 1 restarts the daemon, a very small Maximum file size on a very busy firewall means frequent restarts, which is a reason to keep the value generous rather than tight.
$ configctl syslog archive; echo '---'; ls /var/log/filter/ | wc -lOK
---
32
Illustrative output
What still uses newsyslog
A handful of components write their own files rather than going through syslog-ng, and those are rotated by FreeBSD’s newsyslog on its own schedule and its own generation count. Suricata’s /var/log/suricata/eve.json is the significant one; the Squid access log behaves the same way when the plugin is configured to write directly rather than through syslog.
This matters when planning disk. The Maximum preserved files setting has no effect on these files at all — their retention is configured on the component that owns them, on the IDS settings page in Suricata’s case. A firewall sized on the assumption that one setting governs all of /var/log will be surprised by the IDS.
Remote retention
The remote destination owns its own retention, typically in tiers:
- Hot: indexed and fast, 30 to 90 days.
- Warm: indexed on slower storage, 90 days to a year.
- Cold: archived and not indexed, needing re-ingestion to query, one to seven years.
- Legal hold: exempt from expiry for the duration of an investigation.
Anything beyond the local month lives here. This is also the tier that survives the firewall being rebuilt, replaced, or compromised.
Defining the retention policy
Retention is a business question with technical consequences. The inputs:
- Legal requirements: regulated industries have mandatory periods. PCI DSS requires a year of audit history with three months immediately available. Some healthcare regimes require six years. The UK GDPR sets no fixed period but requires that retention be no longer than necessary for the stated purpose.
- Operational needs: how far back investigations actually reach, and how long post-mortems take to start.
- Storage cost: the marginal cost per month per terabyte, which is what makes cold tiers worth having.
- Risk: longer retention widens the blast radius of a breach of the log store itself.
A worked policy matrix:
| Log type | Firewall (local) | Hot | Warm | Cold |
|---|---|---|---|---|
| Filter | 31 days | 30 days | 90 days | 1 year |
| Audit and authentication | 31 days | 30 days | 90 days | 1 year |
| IDS alerts | per IDS settings | 90 days | 1 year | 3 years |
| Web proxy | per plugin settings | 30 days | 90 days | 1 year |
| VPN | 31 days | 30 days | 90 days | 1 year |
| System and service | 31 days | 7 days | 30 days | — |
The numbers depend on the estate. The discipline is to write the policy down, configure both tiers to enforce it, and audit the actual retention against it — including confirming that the firewall’s local window is what the policy assumes rather than what the defaults happen to give.
Deletion discipline
The policy defines when logs must be deleted. The discipline around it:
- Automatic deletion: both tiers expire on their own. Verify it is actually happening rather than assuming — a SIEM whose expiry job has been failing silently for a year is a compliance finding, not a bonus.
- Legal hold override: an investigation must be able to exempt specific data from expiry, and lift that exemption afterwards. On the firewall’s local tier there is no such mechanism, which is another reason evidence is collected from the remote tier.
- Right to erasure: logs recording only addresses, ports, and counts are generally not personal data; logs naming a user usually are. There must be a process that can satisfy an erasure request without destroying unrelated records.
- Audit of deletion: a record of what was deleted, when, and under which policy. The deletion record is itself a log, and it outlives what it describes.
Summary
- The local tier is about thirty-one daily files per application, trimmed hourly by
configctl syslog archiveand readable for the whole window. - Maximum preserved files bounds the file count, not the disk footprint. Maximum file size bounds each file, at the cost of shortening the window in days.
- Deletion by the housekeeping job is immediate and permanent; lowering the retention setting destroys the difference on the next run.
- Suricata and the proxy rotate their own files with
newsyslogand are not governed by these settings. - Long-term retention, correlation, and anything that must survive the firewall belong on the remote destination.
- Retention policy is a business question — legal, operational, cost, risk — not a technical default.
Knowledge check · 3 questions
Q1. The operator must be able to produce firewall logs for any date in the past year. Where should that retention be configured?
Q2. Once Maximum file size is set, Maximum preserved files stops being a number of days and becomes a number of files, so the retained window in days gets shorter as rotation gets more frequent.
Q3. Which of the following are required components of a log retention policy? Select all that apply.
Passing score: 75%. Answers are checked in this browser.