Rules — OPNsense documentation (2024)

  • »
  • Firewall »
  • Rules

OPNsense contains a stateful packet filter, which can be used to restrict or allow traffic from and/or to specific networksas well as influence how traffic should be forwarded (see also policy based routing in “Multi WAN”).

The rules section shows all policies that apply on your network, grouped by interface.

Overview

Our overview shows all the rules that apply to the selected interface (group) or floating section.For every rule some details are provided and when applicable you can perform actions, such as move, edit, copy, delete.

Below you will find some highlights about this screen.

  1. Interface name

    The name of the interface is part of the normal menu breadcrumb

  2. Category

    If categories are used in the rules, you can select which one you will show here.

  3. Toggle inspection

    You can toggle between inspection and rule view here, when in inspection mode, statistics of the rule are shown.(such as packet counters, number of active states, …)

  4. Show / hide automatic rules

    Some rules are automatically generated, you can toggle here to show the details. If a magnifying glassis shown you can also browse to its origin (The setting controlling this rule).

  5. Automatic rules

    The contents of the automatic rules

  6. User rules

    All user defined rules

The basics

Before creating rules, it’s good to know about some basics which apply to all rules.

States

By default rules are set to stateful (you can change this, but it has consequences), which means that the state ofa connection is saved into a local dictionary which will be resolved when the next packet comes in.The consequence of this is that when a state exists, the firewall doesn’t need to process all its rules again to determinethe action to apply, which has huge performance advantages.

The use of states can also improve security particularly in case of tcp type traffic, since packet sequence numbers and timestamps are also checked in orderto pass traffic, it’s much harder to spoof traffic.

Note

When changing rules, sometimes its necessary to reset states to assure the new policies are used for existing traffic.You can do this in Firewall ‣ Diagnostics ‣ States.

Note

In order to keep states, the system need to reserve memory. By default 10% of the system memory is reserved for states,this can be configured in Firewall ‣ Settings ‣ Firewall Maximum States.(The help text shows the default number of states on your platform)

States can also be quite convenient to find the active top users on your firewall at any time, as of 21.7 we addedan easy to use “session” browser for this purpose. You can find it under Firewall ‣ Diagnostics ‣ Sessions.

Action

Rules can be set to three different action types:

  • Pass –> allow traffic

  • Block –> deny traffic and don’t let the client know it has been dropped (which is usually advisable for untrusted networks)

  • Reject –> deny traffic and let the client know about it. (only tcp and udp support rejecting packets, which in case of TCP means a RST is returned, for UDP ICMP UNREACHABLE is returned).

For internal networks it can be practical to use reject, so the client does not have to wait for a time-out when access is not allowed.When receiving packets from untrusted networks, you usually don’t want to communicate back if traffic is not allowed.

Processing order

Firewall rules are processed in sequence per section, first evaluating the Floating rules section followed by all rules whichbelong to interface groups and finally all interface rules.

Internal (automatic) rules are usually registered first.

Rules — OPNsense documentation (3)

Rules can either be set to quick or not set to quick, the default is to use quick. When set to quick, the rule ishandled on “first match” basis, which means that the first rule matching the packet will take precedence over rules following in sequence.

When quick is not set, last match wins. This can be useful for rules which define standard behaviour.Our default deny rule uses this property for example (if no rule applies, drop traffic).

Note

Internally rules are registered using a priority, floating uses 200000,groups use 300000 and interface rules land on 400000 combined with the order in which they appear.Automatic rules are usually registered at a higher priority (lower number).

Warning

NAT rules are always processed before filter rules!So for example, if you define a NAT : port forwarding rules without a associated rule, i.e. Filter rule association set to Pass, this has the consequence, that no other rules will apply!

Tip

The interface should show all rules that are used, when in doubt, you can always inspect the raw output of the ruleset in /tmp/rules.debug

Rule sequence

The sequence in which the rules are displayed and processed can be customized per section:

  • Select one or more rules using the checkbox on the left side of the rule.

  • Use the arrow button in the action menu on the right side of a rule in order to move selected rules before the rule where the action button is pressed.

  • Or you can use the arrow button on the top in the heading row to move the selected rules to the end.

Direction

Rules — OPNsense documentation (4)

Traffic can be matched on in[coming] or out[going] direction, our default is to filter on incoming direction.In which case you would set the policy on the interface where the traffic originates from.

For example, if you want to allow https traffic coming from any host on the internet,you would usually set a policy on the WAN interface allowing port 443 to the host in question.

Note

Traffic leaving the firewall is accepted by default (using a non-quick rule), when Disable force gateway inFirewall ‣ Settings ‣ Advanced is not checked, the connected gateway would be enforced as well.

Settings

Traffic that is flowing through your firewall can be allowed or denied using rules, which define policies.This section of the documentation describe the different settings, grouped by usage.

Descriptive settings

Some settings help to identify rules, without influencing traffic flow.

Category

The category this rule belongs to, can be used as a filter in the overview

Description

Descriptive text

Basic settings

Below are the settings most commonly used:

Action

The action to perform.

Disabled

Disable a rule without removing it, can be practical for testing purposes andto support easy enablement of less frequently used policies.

Interface

Interface[s] this rule applies on. You can easily copy rules between interfacesand change this field to the new target interface.(remember to check the order before applying)

TCP/IP Version

Does this rule apply on IPv4, IPv6 or both.

Protocol

Protocol to use, most common are TCP and UDP

Source

Source network or address, when combining IPv4 and IPv6 in one rule, you can usealiases which contain both address families.

Source / Invert

Invert source selection (for example not 192.168.0.0/24)

Destination

Destination network or address, like source you can use aliases here as well.

Destination / Invert

When the filter should be inverted, you can mark this checkbox

Destination port range

For TCP and/or UDP you can select a service by name (http, https)or number (range), you can also use aliases here to simplify management.

Log

Create a log entry when this rule applies, you can useFirewall ‣ Log Files ‣ Live View to monitor if your ruleapplies.

Tip

The use of descriptive names help identify traffic in the live log view easily.

Tip

With the use of the eye button in the right top corner of the screen you can find statistics about the rule inquestion (number of evaluations, number of active states and traffic counters).

Less commonly used

Some settings are usually best left default, but can also be set in the normal rule configuration.

Source port range

In case of TCP and/or UDP, you can also filter on the source port (range) that isused by the client. Since in most cases you can’t influence the source port,this setting is usually kept default (any).

Quick

If a packet matches a rule specifying quick, the first matching rule wins.When not set to quick the last matching rule wins. When not sure, best usequick rules and interpret the ruleset from top to bottom.

Direction

Direction of the traffic,see also Direction.

High Availability

The following options are specifically used for HA setups.

No XMLRPC Sync

Disable configuration sync for this rule, when Firewall Rules sync isenabled in System ‣ High Availability ‣ Settings

State Type / NO pfsync

Prevent states created by this rule to be synced to the other node

Schedule

Rules can also be scheduled to be active at specific days or time ranges, you can create schedules inFirewall ‣ Advanced ‣ Schedules and select one in the rule.

Policy based routing

This feature can be used to forward traffic to another gateway based on more fine grained filters than static routescould (OSI layer 4 verses OSI layer 3) and can be used to build multi-wan scenario’s using gateway groups.

More information about Multi-Wan can be found in the “Multi WAN” chapter.

Gateway

When a gateway is specified, packets will use policy based routing usingthe specified gateway or gateway group. Usually this option is set on thereceiving interface (LAN for example), which then chooses the gatewayspecified here. (This ignores default routing rules). Only packets flowing inthe same direction of the rule are affected by this parameter, the oppositedirection (replies) are not affected by this option.

reply-to

By default traffic is always send to the connected gateway on the interface.If for some reason you don’t want to force traffic to that gateway, youcan disable this behaviour or enforce an alternative target here.

Note

When using policy based routing, don’t forget to exclude local traffic which shouldn’t be forwarded.You can do so by creating a rule with a higher priority, using a default gateway.

Tip

In our experience the packet capture function (Interfaces ‣ Diagnostics ‣ Packet capture) canbe a valuable tool to inspect if traffic is really heading the direction you would expect it to go, justchoose a host to monitor and try to exchange some packets. When selecting all interfaces, it’s easy to seewhere traffic headed.

Connection limits

The advanced options contains some settings to limit the use of a rule or specify specific timeouts forthe it. Most generic (default) settings for these options can be found under Firewall ‣ Settings ‣ Advanced

Max states

Limits the number of concurrent states the rule may create.When this limit is reached, further packets that would create state willnot match this rule until existing states time out.

Max source nodes

Limits the maximum number of source addresses which can simultaneouslyhave state table entries.

Max established

Limits the maximum number of simultaneous TCP connections which havecompleted the 3-way handshake that a single host can make.

Max source states

Limits the maximum number of simultaneous state entries thata single source address can create with this rule.

Max new connections

Limit the rate of new connections over a time interval. Theconnection rate is an approximation calculated as a moving average.(number of connections / seconds) Only applies on TCP connections

State timeout

State Timeout in seconds (applies to TCP only)

Advanced

Some less common used options are defined below.

Source OS

Operating systems can be fingerprinted based on some tcp fields fromthe originating connection. These fingerprints can be used as wellto match traffic on. (more detailed information can be found in thepf.os man page)

allow options

By default the firewall blocks IPv4 packets with IP options or IPv6packets with routing extension headers set.If you have an application that requires such packets(such as multicast or IGMP)you can enable this option.

TCP flags

If specific TCP flags need to be set or unset, you can specify those here.

Set priority

Packets matching this rule will be assigned a specific queueing priority.If the packet is transmitted on a VLAN interface, the queueing prioritywill be written as the priority code point in the 802.1Q VLANheader. If two priorities are given, packets which have a TOS oflowdelay and TCP ACKs with no data payload will be assigned to the second one.

Match priority

Only match packets which have the given queueing priority assigned.

Set local tag

Packets matching this rule will be tagged with the specified string.The tag acts as an internal marker that can be used to identify thesepackets later on. This can be used, for example, to provide trust betweeninterfaces and to determine if packets have been processed by translation rules.Tags are “sticky”, meaning that the packet will be tagged evenif the rule is not the last matching rule.Further matching rules can replace the tag with a new one but will notremove a previously applied tag. A packet is only ever assignedone tag at a time.

Match local tag

Match packets that are tagged earlier (using set local tag)

State Type

Influence the state tracking mechanism used, the following options are available.When in doubt, it’s usually best to preserve the default keep state

  • Keep state is used for stateful connection tracking.

  • Sloppy state works like keep state,but it does not check sequence numbers.Use it when the firewall does not see all packets.

  • Synproxy state proxies incoming TCP connections to helpprotect servers from spoofed TCP SYN floods.This option includes the functionality of keep stateand modulate state combined.

  • None Do not use state mechanisms to keep track.

Troubleshooting

While building your ruleset things can go wrong, it’s always good to know where to look for signs of an issue.One of the most common mistakes is traffic doesn’t match the rule and/or the order of the rule doesn’t make sensefor whatever reason.

With the use of the “inspect” button, one can easily see if a rule is being evaluated and traffic did pass usingthis rule. As of 21.7 it’s also possible to jump directly into the attached states to see if your host is in the listas expected.

Another valuable tool is the live log viewer, in order to use it, make sure to provide your rule with an easy toread description and enable the “log” option.

If your using source routing (policy based routing), debugging can sometimes get a bit more complicated. Since the normalsystem routing table may not apply, it helps to know which flow the traffic actually followed. The packet capture is a usefultool in that case.

Common issues in this area include return traffic using a different interface than the one it came into, since trafficfollows the normal routing table on it’s way out (reply-to issue), or traffic leaving the wrong interface due to overselection(matching internal traffic and forcing a gateway).

Inspecting used netmasks is also a good idea, intending to match a host but providing a subnet is a mistake easily made(e.g. 192.168.1.1/32 vs 192.168.1.1/24 is in reality all of 192.168.1.x).

Last but not least, remember rules are matched in order and the default (inbound) policy is block if nothing elseis specified, since we match traffic on inbound, make sure to add rules where traffic originates from(e.g. lan for traffic leaving your network, the return should normally be allowed by state).

API access

Partial API access is described in more detail in the firewall api reference manual.

Rules — OPNsense  documentation (2024)

FAQs

What is the sequence of firewall rules in OPNsense? ›

Firewall rules are processed in sequence per section, first evaluating the Floating rules section followed by all rules which belong to interface groups and finally all interface rules.

How to set up port forwarding on OPNsense? ›

To configure the port forwarding in OPNsense you may navigate to Firewall → NAT → Port Forward. An overview of port forwarding rules can be found here. To add new port forwarding rules, you may click the + button in the upper right corner. Check this option to disable the rule without removing it.

What is carp in OPNsense? ›

OPNsense employs the Common Address Redundancy Protocol (CARP) to enable hardware failover. A failover group is created by configuring two or more firewalls. The secondary becomes active if one interface fails on the master firewall or the primary firewall entirely goes down.

How to disable firewall in OPNsense? ›

Re: How do I turn off OPNSense firewall? like windows firewall..... It's really not that complicated. You can disable outbound NAT and keep the firewall rules functionality, or you can uncheck the firewall filter in the advanced settings, lose rules and NAT at the same time.

What order should firewall rules be? ›

Typically, a firewall policy starts with a default rule like “deny all,” and then specific “allow” rules are added on top. Specific Over General: Place more specific rules first.

Which is better, OPNSense or pfSense? ›

Ultimately, pfSense offers more flexibility for seasoned users, but OPNsense provides a more polished out-of-box experience.

What is the default port of OPNSense? ›

By default, LAN is assigned to port 0 and WAN is assigned to port 1. Assignments can be changed by going to Interfaces ‣ Assignments. This lists existing interfaces, with the interface name on the left and the physical port selected in the dropdown.

How do I set port forwarding rules? ›

How to open ports on a router
  1. Access your router's web interface. Navigate to your router's configuration page by typing the router's IP address into your browser.
  2. Log in to your router. ...
  3. Find the port forwarding section. ...
  4. Add a new port forwarding rule. ...
  5. Save the changes.
Jun 19, 2023

What is lagg opnsense? ›

LAGG. LAGG ( lagg(4) ) allows for link aggregation, bonding and fault tolerance. This works best if your network switches support. Only unassigned interfaces can be added to LAGG.

What is pfsync? ›

pfsync is a computer protocol used to synchronise firewall states between machines running Packet Filter (PF) for high availability.

How to setup OPNsense firewall rules? ›

Navigate to the Firewall → Rules on OPNsense web GUI. Select the interface that you want to define a rule, such as WAN, LAN, VLAN10 or WireGuard, etc. This will list the existing firewall rules on the selected interface. Click the orange square with + icon at the top right corner of the rule list.

How do you stop Zenarmor? ›

You can start/stop/restart the Zenarmor-related services on the dashboard by following the next steps:
  1. Hover your mouse over the service pane where you want to change the status.
  2. To stop/start/restart one of the services, click the Stop/Start/Restart button in the service pane.

How do I permanently turn off my firewall? ›

Turning off the Windows firewall
  1. Select Start > Control Panel > System and Security > Windows Firewall. ...
  2. Select Turn Windows Firewall on or off. ...
  3. Select Turn off Windows Firewall (not recommended) for both Home or work (private) network location settings and Public network location settings, and then click OK.

What is the path of firewall rules? ›

In which places should I check for Firewall Rules in Windows 10?
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules.
  • HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\WindowsFirewall\FirewallRules.
Jan 24, 2024

What is order of rules in Windows Firewall? ›

Rule precedence for inbound rules
  1. Explicitly defined allow rules take precedence over the default block setting.
  2. Explicit block rules take precedence over any conflicting allow rules.
  3. More specific rules take precedence over less specific rules, except if there are explicit block rules as mentioned in 2.
Sep 6, 2024

What is the priority of a firewall rule? ›

The firewall rule priority is an integer from 0 to 65535 , inclusive. Lower integers indicate higher priorities. If you do not specify a priority when creating a rule, it is assigned a priority of 1000 . The relative priority of a firewall rule determines whether it is applicable when evaluated against others.

Top Articles
How to Read and Analyze a Balance Sheet
GOBankingRates | Personal Finance Site To Help You Find More Ways To Save Money And Make Money
#ridwork guides | fountainpenguin
Fat Hog Prices Today
Craigslist Free En Dallas Tx
Uti Hvacr
Holly Ranch Aussie Farm
Nordstrom Rack Glendale Photos
Naturalization Ceremonies Can I Pick Up Citizenship Certificate Before Ceremony
Owatc Canvas
Wfin Local News
Calamity Hallowed Ore
Zachary Zulock Linkedin
Jessica Renee Johnson Update 2023
“In my day, you were butch or you were femme”
Cbs Trade Value Chart Fantasy Football
Download Center | Habasit
Gdlauncher Downloading Game Files Loop
NHS England » Winter and H2 priorities
Icommerce Agent
Silive Obituary
Pickswise Review 2024: Is Pickswise a Trusted Tipster?
Graphic Look Inside Jeffrey Dahmer
Maxpreps Field Hockey
Soulstone Survivors Igg
Www.patientnotebook/Atic
Sienna
Chicago Based Pizza Chain Familiarly
Pain Out Maxx Kratom
Urbfsdreamgirl
Horses For Sale In Tn Craigslist
Ocala Craigslist Com
Stickley Furniture
Sinai Sdn 2023
Fastpitch Softball Pitching Tips for Beginners Part 1 | STACK
Los Amigos Taquería Kalona Menu
Newsday Brains Only
Ducky Mcshweeney's Reviews
1-800-308-1977
Craigslist Car For Sale By Owner
Keeper Of The Lost Cities Series - Shannon Messenger
The best specialist spirits store | Spirituosengalerie Stuttgart
Clausen's Car Wash
Pathfinder Wrath Of The Righteous Tiefling Traitor
Ghareeb Nawaz Texas Menu
Theater X Orange Heights Florida
Home | General Store and Gas Station | Cressman's General Store | California
Noelleleyva Leaks
Marion City Wide Garage Sale 2023
Craigslist Centre Alabama
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 6284

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.