Introduction and Setup Assumptions
This guide provides practical exercises for configuring firewall rules and Network Address Translation (NAT) in pfSense. Mastering these concepts is crucial for securing your network and enabling necessary services.
We assume the following basic setup:
- You have a working pfSense installation.
- The WAN interface is connected to the "internet" (or your upstream network).
- The LAN interface is connected to your internal network.
- Your internal LAN subnet is 192.168.1.0/24. Adjust IPs in the examples if your network differs.
- You can access the pfSense web interface.
Task 1: Allow Basic Web Access (HTTP/HTTPS) from LAN
Goal: Ensure users on your internal network (192.168.1.0/24) can browse standard websites on the internet.
Rationale: This is the most fundamental requirement for most networks. We need to explicitly permit traffic using the HTTP (port 80) and HTTPS (port 443) protocols originating from the LAN and going out to any destination on the internet. While pfSense often has a default allow rule on LAN, understanding how to create this manually is essential.
Steps:
- Log in to your pfSense web interface.
- Navigate to Firewall > Rules.
- Select the LAN interface tab. (This is where traffic *enters* pfSense *from* your internal network).
- Click the Add button with the UP arrow (to add the rule to the TOP of the list). Adding to the top ensures it gets evaluated first, which is useful for testing, although its final position might be different in a complex ruleset.
-
Configure the rule settings carefully:
- Action: Pass (Allow the traffic)
- Interface: LAN (Rule applies to traffic entering pfSense on this interface)
- Address Family: IPv4
- Protocol: TCP (HTTP and HTTPS both use TCP)
- Source:
- Type: LAN net (This automatically uses the network defined for the LAN interface - 192.168.1.0/24 in our case. More flexible than hardcoding the IP range.)
- Destination:
- Type: Any (Allow access to any IP address on the internet)
- Destination Port Range:
- From: HTTP (pfSense knows this is port 80)
- To: HTTPS (pfSense knows this is port 443)
- (This creates a range covering both common web ports)
- Description: Enter something clear, e.g., Allow LAN HTTP/HTTPS Outbound. (Good descriptions are crucial for later understanding!)
- Click the Save button at the bottom.
- A message will appear at the top: "The firewall rule configuration has been changed." Click the Apply Changes button to make the rule active. Rules are not active until you apply changes!
- Verification: From a computer on your LAN (with an IP like 192.168.1.x), try browsing to `http://example.com` and `https://google.com`.
Task 2: Block Incoming ICMP (Ping) on WAN
Goal: Prevent external hosts on the internet from successfully pinging your pfSense firewall's public WAN IP address.
Rationale: Blocking incoming ICMP echo requests (pings) can make your network slightly less visible to basic network scans conducted by potential attackers. While not a high-security measure on its own ("security through obscurity"), it's a common hardening practice. We need a rule on the WAN interface to explicitly block this traffic type.
Steps:
- Navigate to Firewall > Rules.
- Select the WAN interface tab. (This is where traffic *enters* pfSense *from* the internet).
- Click the Add button (using the UP arrow to add to the top is usually safest for block rules targeting the firewall itself, ensuring they match before any potential 'allow' rules).
-
Configure the rule:
- Action: Block (Silently discard the packet)
- Interface: WAN
- Address Family: IPv4
- Protocol: ICMP
- ICMP Subtypes: (Optional but recommended) Click "Display Advanced" and select Echo request from the list. This specifically blocks pings but allows other potentially useful ICMP types (like 'Destination Unreachable'). If unsure, leaving it as 'Any' will block all ICMP types.
- Source:
- Type: Any (Block pings from any IP address on the internet)
- Destination:
- Type: WAN address (Specifically block pings directed *to* your firewall's public IP address)
- (Using 'Any' here would also work but 'WAN address' is more precise for this goal).
- Description: Block Incoming Ping on WAN.
- Click Save.
- Click Apply Changes.
- Verification: Try pinging your pfSense WAN IP address from a machine *outside* your network (e.g., using an online ping tool, or from a different internet connection). The pings should time out. Note: This rule does *not* prevent machines *inside* your LAN from pinging external addresses.
Task 3: Allow Remote SSH Access ONLY from a Specific IP
Goal: Enable secure remote administration of the pfSense firewall itself via SSH (port 22), but strictly limit access to only your trusted administrative workstation IP address (10.0.0.100 - adjust this to your *actual* external IP if accessing from the internet, or an internal IP if accessing from another internal network).
Rationale: Opening management ports like SSH to the entire internet is extremely risky. This rule implements the principle of least privilege by allowing access only from a known, trusted source IP.
Steps:
- Navigate to Firewall > Rules.
- Select the WAN interface tab (assuming access from the internet).
- Click the Add button (use the UP arrow to place it at the TOP). This rule MUST be placed *before* any general block rules on the WAN interface, otherwise, the block rule would match first and deny access.
-
Configure the rule:
- Action: Pass
- Interface: WAN
- Address Family: IPv4
- Protocol: TCP
- Source:
- Type: Single host or alias
- Address: 10.0.0.100 (Replace with YOUR trusted source IP)
- Destination:
- Type: WAN address (The traffic is destined for the firewall itself)
- Destination Port Range:
- From: SSH (Port 22)
- To: SSH (Port 22)
- Description: Allow SSH from Admin IP [Your IP].
- Click Save.
- Click Apply Changes.
- Verification: Try connecting via SSH to your pfSense WAN IP address from the specified source IP (10.0.0.100). It should connect. Try connecting from any *other* IP address; the connection should fail (timeout or be refused).
Task 4: Block Tor Traffic using an Alias
Goal: Prevent users on your LAN from accessing the Tor anonymity network by blocking connections to known Tor exit nodes.
Rationale: Some organizations block Tor access due to policy or concerns about bypassing security controls. Since Tor exit node IPs change frequently, using an Alias populated from a dynamic list is the most effective way to manage this. We will block outbound traffic from the LAN destined for IPs listed in our alias.
Steps:
- Part 1: Create the Alias
- Navigate to Firewall > Aliases.
- Select the IP tab (usually the default).
- Click the Add button.
-
Configure the Alias:
- Name: Tor_Exit_Nodes (Must be one word, use underscores if needed. Be descriptive.)
- Description: List of known Tor Exit Nodes (Optional but helpful)
- Type: Network(s)
- Content: In the "Network or FQDN" text area, paste the IP addresses or network ranges of the Tor exit nodes, one entry per line. Example:
(Use a few example IPs for practice if you don't have a full list readily available).
1.2.3.4 5.6.7.0/24 9.10.11.12
- Click Save.
- Click Apply Changes (Aliases also need changes applied).
- Part 2: Create the Firewall Rule
- Navigate to Firewall > Rules.
- Select the LAN interface tab.
- Click the Add button. Place this rule BEFORE your general "Allow Web Access" rule (Task 1). Why? Because you want to specifically block Tor *before* potentially allowing general web traffic that might include Tor destinations if this rule didn't exist or was lower down.
-
Configure the rule:
- Action: Reject (or Block)
- Interface: LAN
- Address Family: IPv4
- Protocol: Any (Tor can use various ports/protocols)
- Source:
- Type: LAN net
- Destination:
- Type: Single host or alias
- Address: Start typing Tor_ and select your alias Tor_Exit_Nodes from the dropdown list.
- Description: Block LAN access to Tor Exit Nodes.
- Click Save.
- Click Apply Changes.
- Verification: This is harder to test without a Tor client and a reliable, current list in the alias. In principle, attempts from the LAN to connect to any IP listed in the Tor_Exit_Nodes alias should now be blocked or rejected.
Task 5: Port Forwarding for an Internal Web Server
Goal: Make an internal web server, running at 192.168.1.200 on port 80 (HTTP), accessible to users from the internet via your pfSense firewall's public WAN IP address.
Rationale: Network Address Translation (NAT), specifically Port Forwarding, is used to direct incoming traffic on a specific port on your public WAN IP to a specific internal server and port. This allows you to host services internally while only exposing the necessary ports externally.
Steps:
- Navigate to Firewall > NAT.
- Select the Port Forward tab.
- Click the Add button.
-
Configure the port forward rule:
- Interface: WAN (Traffic arrives from the internet on this interface)
- Address Family: IPv4
- Protocol: TCP (HTTP uses TCP)
- Source: Leave as Any (Unless you want to restrict access to specific external IPs)
- Destination:
- Type: WAN address (The traffic is initially aimed at your public IP)
- Destination Port Range:
- From: HTTP (The external port clients connect to)
- To: HTTP
- Redirect target IP: 192.168.1.200 (The internal IP address of your web server)
- Redirect target port: HTTP (The internal port your web server listens on)
- Description: Forward HTTP to Internal Web Server.
- NAT reflection: Keep default (usually 'Use system default'). This helps internal clients access the server via the public IP.
- Filter rule association: Keep default ('Add associated filter rule' or similar). This is crucial! pfSense will automatically create a linked firewall rule on the WAN interface to *allow* the traffic that this NAT rule forwards. Without this associated rule, the NAT rule would exist, but the firewall would still block the incoming traffic.
- Click Save.
- Click Apply Changes.
- Verification:
- Go to Firewall > Rules and select the WAN tab. You should see a new rule automatically created by pfSense (often marked with 'NAT') allowing traffic to destination 192.168.1.200 on port 80.
- From a device *outside* your network, try accessing http://[Your_pfSense_WAN_IP]. You should see the webpage served by your internal server at 192.168.1.200.
General Tips for Success
- Apply Changes: Always remember to click Apply Changes after saving any firewall or NAT rule.
- Rule Order: Rules are evaluated top-down. The first match wins. Place more specific rules *before* more general rules. Block rules often go near the top, especially if blocking traffic *to* the firewall itself.
- Descriptions: Use clear, concise descriptions for every rule and alias. Your future self will thank you!
- Test Thoroughly: After adding or changing a rule, test from relevant source/destination IPs to confirm it works as expected and hasn't broken anything else.
- Backup: Before making significant changes, consider backing up your pfSense configuration (Diagnostics > Backup & Restore).