In today's interconnected world, robust network security is more crucial than ever. A well-configured firewall is the first line of defense, and OPNsense, a powerful open-source firewall platform, offers granular control and flexible rule management. Let's explore some practical OPNsense firewall rules examples to enhance your network security.
Before delving into specific rules, it's essential to understand the fundamentals. OPNsense uses a straightforward rule syntax that includes fields like protocol, source/destination IP, port range, and description. By manipulating these fields, you can create tailored rules for your network.
tocol-based Rules
OPNsense allows you to create rules based on various protocols. This targeted approach helps protect your network from malicious traffic while maintaining productivity.
Here are two examples of protocol-based rules:
Allowing Specific Protocols
To allow incoming traffic based on specific protocols, create rules like these:
Proto: TCP/UDP/ICMP TCP/UDP/ICMP
Source: any/192.168.1.0/24 10.0.0.0/8
Port: * or 22/25 22/25 SSH/SSH
Description: Allow incoming SSH connections
Blocking Certain Protocols
To block incoming traffic from specific protocols, use rules like these:
Proto: TCP/UDP TCP/UDP
Source: * any * *
Port: * 135/139 137/138
Description: Block NetBIOS traffic
Stateful Firewall Rules
OPNsense employs stateful inspection, tracking active connections and automatically allowing related traffic. This feature simplifies rule creation, reducing the need for complex rules.
Here are two examples of stateful firewall rules:
Allowing Inbound Connections
For services running on your network, like web servers, create rules that allow inbound connections. Here's an example for an HTTP server:
Proto: TCP
Source: any
Port: 80
Description: Allow HTTP traffic
Blocking Outbound Connections
To prevent malicious applications from sending traffic, create outbound block rules. For instance, to block all outbound traffic on port 1337, use the following rule:
Proto: TCP/UDP
Source: any
Port: 1337
Description: Block outbound traffic on port 1337
Direction: out
With these examples, you've seen how to create protocol-based, stateful, and outbound block rules. Expand your rule set based on your network's specific needs, and stay vigilant in maintaining a solid security posture. Regularly review and update your rules to address evolving threats.