opn-diag.sh is a comprehensive, non-intrusive diagnostics and data collector designed specifically for the OPNsense® firewall platform. Its primary function is to gather a wide array of system, hardware, network, firewall, service, and configuration information and save it into a set of well-structured, timestamped files.
The collected data is intended to aid in troubleshooting complex issues, performing system health checks, or providing detailed information for support purposes without altering the system's configuration.
-
Comprehensive Data Collection: Gathers detailed information across 19 distinct diagnostic sections, from system info and hardware details to firewall rules and network connectivity.
-
Sanitization Mode: Includes a
--sanitizeflag to redact sensitive information (IP addresses, MACs, hostnames, serial numbers) from the output, making it safe to share.- Dynamic & Modular: The script's execution flow is controlled by arrays, making it easy for developers to reorder, add, or remove diagnostic sections without breaking the script's structure.
-
Detailed Logging & Timestamps: Every command is logged with its full output, exit status, and execution duration. Each major section's cumulative execution time is also calculated and logged.
-
User-Friendly Output:
-
Index of Sections: The main output file begins with a clickable index, allowing for easy navigation to any specific section in a large log file.
-
Live Console Feedback: Provides clean, real-time progress updates to the terminal as the script runs.
-
-
Externalized Checksums: Generates separate
.md5and.sha256files to verify the integrity of the main output log without altering it. -
Graceful Degradation: The script intelligently checks for optional dependencies (
jq,lscpu,drill, etc.) and skips relevant tests gracefully if they are not installed, providing a suggestion to install them. -
Targeted Captures: Includes specialized data captures, such as a
tcpdumpthat excludes common web traffic to highlight other protocols.
-
Operating System: OPNsense® / FreeBSD
-
Required Shell: GNU Bash (
/usr/local/bin/bash). The script is not compatible withsh. -
Required Privileges: Root user. The script will exit if not run with UID 0.
-
Optional Dependencies: For maximum data collection, the following utilities are recommended:
-
jq(for robust JSON parsing) -
lscpu,lsblk(pkg install sysinfo) -
drill(pkg install ldns) -
mtr(pkg install mtr-nox11) -
dmidecode(pkg install dmidecode)
-
Clone this repository or download the opn-diag.sh script to your OPNsense firewall, for example, in the /root directory.
Open a shell on your OPNsense machine (e.g., via SSH) and run the following command:
chmod +x opn-diag.sh
As the root user, execute the script using bash:
bash ./opn-diag.sh
--sanitize: Runs the script in sanitization mode. This will redact sensitive information from the output file, including IP addresses (v4/v6), MAC addresses, FQDNs, hostnames, and disk serial numbers. The resulting file is generally safe to share for public troubleshooting.
bash ./opn-diag.sh --sanitize
The script will print live progress to the terminal and inform you when it has finished.
The script will generate three files in the directory where it was run, all sharing the same timestamp:
-
opnsense_diagnostics_output_[timestamp].txt: The main, verbose log file containing all collected diagnostic data. -
opnsense_diagnostics_output_[timestamp].txt.md5: A text file containing only the MD5 hash of the main log file. -
opnsense_diagnostics_output_[timestamp].txt.sha256: A text file containing only the SHA256 hash of the main log file.
The main .txt log file is structured for readability:
-
Header: Contains the script version, execution date, and OPNsense version.
-
Initial Checks: Logs the presence and permissions of required utilities.
-
Index of Sections: A table of contents listing all diagnostic sections and their corresponding section numbers. You can search for
SECTION X:to jump to a specific part of the report. -
Diagnostic Sections: Each section follows a consistent format:
-
A major header (e.g.,
SECTION 1: System Information). -
A series of command blocks for each step within that section.
-
Each command block clearly states the step number, the descriptive label for the command, the exact command string that was run, its full output, its exit status, and its duration.
-
A summary at the end of each section stating its total execution time.
-
-
Footer: A final confirmation that the script has finished.
The script currently collects the following sections in order:
-
System Information:
uname, FreeBSD version, uptime, boot messages, OPNsense system status, and sensor data. -
Hardware Diagnostics: CPU info (
lscpu), block devices (lsblk), hardware status (hwstat),dmidecodefor system and BIOS info, disk list (geom), andsmartctlhealth status for all disks. -
Interface Configuration & Status: Verbose
ifconfig,configctlinterface summaries and stats, CARP status, and recent kernel messages related to networking. -
Routing Table & ARP:
netstatrouting tables, routing statistics, ARP and NDP tables, andconfigctlgateway status. -
ARP Timeout Configuration: System-wide ARP settings from
sysctl. -
DNS Configuration & Resolution:
resolv.conf, configured nameservers, DNS service status (Unbound/Dnsmasq), socket status, anddrilltests for external and local hostnames. -
Firewall (PF) Diagnostics: Verbose
pfctloutput for rules, NAT, states, info, and tables. -
Network Connections & Services:
netstatandsockstatfor active sockets and protocol statistics, plus mbuf usage and interrupt stats. -
System Logs: The last 100-200 lines from key OPNsense logs (system, filter, routing, resolver, dhcpd, ntpd).
-
Connectivity Tests (General):
ping,traceroute, andmtrtests to common internet hosts (e.g., 8.8.8.8). -
TCPDump Non-Web Traffic: A short packet capture on the WAN interface that filters out standard HTTP/HTTPS traffic (ports 80/443) to highlight other protocols.
-
OPNsense Health & Disk Space:
configctlhealth checks, firmware status, disk usage (df), ZFS pool status, and partition layout. -
Package Information & Integrity: Lists installed packages and performs a system integrity check with
pkg check. -
WAN Gateway Connectivity & Health: Iterates through all configured gateways, determines the correct interface and source IP, and performs a targeted
pingtest to check reachability, latency, and packet loss. -
Running Processes Snapshot: A snapshot of the current process list from
top. -
NTP/Time Service Status: Status of
ntpd/chronydand peer information. -
OPNsense Services Status: A list and status of all services managed by
configctl. -
Key Configuration Files: The content of important system configuration files (e.g.,
/etc/hosts,/etc/fstab, etc.). -
Kernel Environment (sysctl): A full dump of all kernel state variables from
sysctl -a.
Contributions are welcome! Please feel free to submit a pull request.
When developing, please adhere to the following project standards:
-
All shell code must be compatible with GNU Bash and should not rely on
sh. -
All lines in the
opn-diag.shscript file should attempt to be no more than 80 characters wide. -
Follow the modular design by adding new functionality in self-contained
collect_*functions and adding them to the main execution arrays.