Written for OPNsense 26.7, and checked against the OPNsense documentation and answers from the OPNsense developers. OPNsense is set up in its web interface; these are for the shell (console menu option 8, or SSH as root), mostly for troubleshooting and recovery. OPNsense shares FreeBSD and pf with pfSense, but services, updates and logs work differently, so use this guide rather than the pfSense one. Logs are kept per day under /var/log/<area>/. Interface names are FreeBSD device names such as igc1 or vtnet0. Addresses are examples, so swap in your own.

Console and shell basics #

  • Open the console menu from an SSH shellOPNsense shell
    opnsense-shell
  • Show the OPNsense versionOPNsense shell
    opnsense-version
  • Show interfaces, addresses and link stateOPNsense shell
    ifconfig
  • Show one interfaceOPNsense shell
    ifconfig igc1
  • Show uptime and loadOPNsense shell
    uptime
  • Show the busiest processes and threadsOPNsense shell
    top -aSH
  • Show disk spaceOPNsense shell
    df -h
  • RebootOPNsense shell
    opnsense-shell reboot

    Warning: Stops all traffic until it's back up.

  • Shut downOPNsense shell
    shutdown -p now

Services (configctl and pluginctl) #

  • List the services OPNsense managesOPNsense shell
    pluginctl -s
  • Restart a service (unbound, dnsmasq, openssh, ntpd)OPNsense shell
    pluginctl -s unbound restart
  • Show a service's statusOPNsense shell
    pluginctl -s unbound status
  • List the enabled OpenVPN instances with their IDsOPNsense shell
    pluginctl -S openvpn
  • Restart one OpenVPN instanceOPNsense shell
    pluginctl -s openvpn restart 1
  • Restart the DNS servicesOPNsense shell
    pluginctl dns
  • List every backend action configctl can runOPNsense shell
    configctl configd actions
  • Reload the firewall rulesOPNsense shell
    configctl filter reload
  • Reload all servicesOPNsense shell
    configctl service reload all
  • Restart SSHOPNsense shell
    configctl sshd restart
  • Reload the whole config without rebootingOPNsense shell
    opnsense-shell reload
  • Read a setting from the configOPNsense shell
    pluginctl -g OPNsense.Gateways.gateway_item.0.name

Firewall rules and states (pf) #

  • Show the loaded firewall rulesOPNsense shell
    pfctl -sr
  • Show the rules with countersOPNsense shell
    pfctl -vvsr
  • Show the NAT rulesOPNsense shell
    pfctl -sn
  • Show firewall status and countersOPNsense shell
    pfctl -si
  • Show the state tableOPNsense shell
    pfctl -ss
  • Show states for one addressOPNsense shell
    pfctl -ss | grep 192.168.1.25
  • Kill the states from one addressOPNsense shell
    pfctl -k 192.168.1.25

    Warning: Cuts that host's connections straight away.

  • Kill the states between two addressesOPNsense shell
    pfctl -k 192.168.1.25 -k 198.51.100.10
  • List the tables (aliases, bogons)OPNsense shell
    pfctl -s Tables
  • Show the addresses in an aliasOPNsense shell
    pfctl -t bogons -T show
  • Watch states and traffic liveOPNsense shell
    pftop
  • Turn the firewall off to get back inOPNsense shell
    pfctl -d

    Warning: Turns off all filtering and NAT, so the internet stops working too. Run configctl filter reload as soon as you've fixed things.

Logs #

  • List the log foldersOPNsense shell
    ls /var/log/
  • Watch today's firewall logOPNsense shell
    tail -F /var/log/filter/filter_$(date +%Y%m%d).log
  • Watch today's system logOPNsense shell
    tail -F /var/log/system/system_$(date +%Y%m%d).log
  • Search today's system log for errorsOPNsense shell
    grep -i error /var/log/system/system_$(date +%Y%m%d).log
  • Watch the backend (configd) logOPNsense shell
    tail -F /var/log/configd/configd_$(date +%Y%m%d).log
  • Watch the gateway monitoring logOPNsense shell
    tail -F /var/log/gateways/gateways_$(date +%Y%m%d).log
  • Watch the DNS resolver logOPNsense shell
    tail -F /var/log/resolver/resolver_$(date +%Y%m%d).log
  • Watch the IPsec logOPNsense shell
    tail -F /var/log/ipsec/ipsec_$(date +%Y%m%d).log
  • Watch the OpenVPN logOPNsense shell
    tail -F /var/log/openvpn/openvpn_$(date +%Y%m%d).log
  • See blocked and passed packets as pf logs themOPNsense shell
    tcpdump -n -e -ttt -i pflog0

Packet capture and testing #

  • Capture traffic to and from an addressOPNsense shell
    tcpdump -ni igc1 host 192.168.1.25
  • Capture one portOPNsense shell
    tcpdump -ni igc1 port 443
  • Save a capture to open in WiresharkOPNsense shell
    tcpdump -ni igc1 -w /tmp/capture.pcap host 192.168.1.25
  • Ping from a specific source addressOPNsense shell
    ping -S 192.168.1.1 198.51.100.10
  • Trace the route to a hostOPNsense shell
    traceroute -n 198.51.100.10
  • Look up a name with the firewall's DNSOPNsense shell
    drill www.example.com
  • Test a TCP port from the firewallOPNsense shell
    nc -vz 198.51.100.10 443

Routing, ARP and counters #

  • Show the routing tableOPNsense shell
    netstat -rn
  • Show the route to one addressOPNsense shell
    route -n get 198.51.100.10
  • Show the ARP tableOPNsense shell
    arp -an
  • Show which services are listeningOPNsense shell
    sockstat -4l
  • Show per-interface packet and error countersOPNsense shell
    netstat -i
  • Show network buffer use (mbufs)OPNsense shell
    netstat -m
  • Show traffic per interface liveOPNsense shell
    systat -ifstat 1

DNS, DHCP and NTP #

  • Look up a name in the Unbound cacheOPNsense shell
    unbound-control -c /var/unbound/unbound.conf lookup www.example.com
  • Flush one name from the Unbound cacheOPNsense shell
    unbound-control -c /var/unbound/unbound.conf flush www.example.com
  • Show Unbound statisticsOPNsense shell
    unbound-control -c /var/unbound/unbound.conf stats_noreset
  • Show the generated Dnsmasq configOPNsense shell
    cat /usr/local/etc/dnsmasq.conf
  • Restart Dnsmasq (DNS and DHCP)OPNsense shell
    pluginctl -s dnsmasq restart
  • Show NTP peers and sync statusOPNsense shell
    ntpq -pn

VPN status #

  • Show IPsec tunnels and SAsOPNsense shell
    swanctl --list-sas
  • Show IPsec connections that are configuredOPNsense shell
    swanctl --list-conns
  • Show WireGuard tunnels and peersOPNsense shell
    wg show
  • Stop WireGuardOPNsense shell
    configctl wireguard stop
  • Show OpenVPN processesOPNsense shell
    ps auxww | grep openvpn

High availability (CARP) #

  • Show CARP status on each interfaceOPNsense shell
    ifconfig | grep carp
  • Show pfsync state synchronisationOPNsense shell
    ifconfig pfsync0

Recovery #

  • Reset the root passwordOPNsense shell
    opnsense-shell password
  • List the automatic config backupsOPNsense shell
    ls -la /conf/backup/
  • Restore an earlier config backupOPNsense shell
    cp /conf/backup/config-1763985600.1234.xml /conf/config.xml

    Warning: Replaces the whole running config. Copy the current config.xml somewhere first, then reboot.

  • Back up the config to a fileOPNsense shell
    cp /conf/config.xml /root/config-$(date +%Y%m%d).xml
  • Import a config from a USB stick or another diskOPNsense shell
    opnsense-importer

Updates, packages and rollbacks #

  • Check for updatesOPNsense shell
    opnsense-update -c
  • Download updates without installing themOPNsense shell
    opnsense-update -f
  • Update the base system, kernel and packagesOPNsense shell
    opnsense-update -bkp

    Warning: Reboots may be needed. Back up config.xml first.

  • Upgrade to a new major releaseOPNsense shell
    opnsense-update -ur 26.7

    Warning: Read the release notes and back up config.xml before a major upgrade.

  • Roll a package back to the version in an earlier releaseOPNsense shell
    opnsense-revert -r 26.7 strongswan
  • Go back to the kernel from an earlier releaseOPNsense shell
    opnsense-update -kr 26.7

    Warning: Only on advice from the OPNsense team or for testing. Reboot afterwards.

  • Apply a fix from the OPNsense code repositoryOPNsense shell
    opnsense-patch a1b2c3d
  • List installed packagesOPNsense shell
    pkg info
  • List installed OPNsense pluginsOPNsense shell
    pkg info | grep os-