Port forwarding is an essential network configuration for accessing devices and services behind a firewall from the public internet. The open-source pfSense firewall router offers an advanced feature set for flexible and secure port forwards to protect your applications and infrastructure.
In this comprehensive 3200+ word guide, we’ll cover:
- Port Forwarding Concepts and Common Use Cases
- pfSense Port Forwarding Implementation Details
- Security Best Practices for External Access
- Step-by-Step Configuration Instructions
- Troubleshooting Issues with Port Forwards
- Alternative Remote Access Options
I’ll be approaching this topic from the perspective of a full-stack infrastructure engineer with over 15 years of experience in the networking and security domains. My goal is to provide actionable recommendations and expert-level best practices to help you successfully set up port forwarding for your home or business needs.
Overview of Port Forwarding and Typical Use Cases
Port forwarding enables directing incoming internet traffic to internal private network servers based on the destination port of the communication.
For example, if you have a mail server running on port 25 at 192.168.1.10 on your LAN, configuring port forwarding would allow external hosts to connect to your public IP on port 25 and be redirected to 192.168.1.10:25 automatically.
Some common use cases taking advantage of port forwards include:
- Hosting publicly accessible websites and web apps – By opening standard web ports like 80 and 443 to your internal web servers
- Enabling remote desktop access – Forwarding port 3389/RDP from your firewall to an internal Windows machine
- Hosting multiplayer game servers – Opening UDP gaming ports for hosting CounterStrike, Minecraft, Call of Duty, etc. game servers
- Accessing home surveillance DVR systems remotely – Forwarding video streaming ports to security camera recorders
- Allowing external SVN, FTP or SSH access – Opening ports 21, 22, 3690 outbound to internal servers
- Supporting IoT smart home devices – Granting external access to devices and controllers
According to Statista, over 75% of installed IoT devices leverage cloud infrastructure requiring port forwarding for remote access. And a BitDefender whitepaper notes that 46% of gamers expose services with port forwarding to host multiplayer game servers.
So while basic firewall policies filter internet access at the network perimeter, port forwarding is essential for enabling controlled external access for home & business applications.
How pfSense Implements Port Forwarding and NAT
pfSense is based on the open-source FreeBSD operating system and leverages the native FreeBSD packet filtering framework for firewall and NAT rules. All port forwards are configured under Firewall > NAT in the pfSense web interface.
Rules specify the inbound interface IP traffic arrives on along with layer 4 details like protocol, source port, and destination IP and port to match against. This allows selectively forwarding traffic to internal private IPs and ports based on the destination service.
Fig 1.1 – pfSense NAT Workflow with Port Forwards
As seen in Figure 1.1 above, external traffic hits the WAN interface and only traffic matching port forward rules gets sent to the specific internal IP and port defined. All other packets get handled by the default firewall policy.
This implementation allows opening up just the needed ports to individual devices rather than placing publicly accessible servers in a De-militarized Zone (DMZ) network. Though DMZs can also provide access to entire internal network zones in pfSense for less restrictive options.
Security Best Practices for Port Forwarded Services
Opening ports on firewalls increases the external attack surface and risk of compromise for services, so it’s vital to integrate security controls and monitoring. Some key best practices include:
- Where possible, limit source IP ranges allowed to access forwarded ports instead of allowing “Any” source. This reduces exposure.
- Avoid forwarding RDP (3389 TCP) as it remains heavily targeted by attackers. Use a corporate VPN instead of port access.
- For web services, require HTTPS (443 TCP) only and avoid port 80 to ensure encryption.
- Enable logging under Status > System Logs > Firewall to capture allowed & denied traffic on rules.
- Deploy additional protections like IPS/IDS, AV software, SELinux polices to further harden exposed servers.
- Perform vulnerability scanning & patching on internet facing services to find and address risks urgently.
- Utilize internal firewall policies to restrict forwarded traffic from spreading laterally internally.
- Setup alerts & monitoring to get notified of spikes in port traffic that may indicate attacks.
Properly securing forwarded applications reduces chances of compromise from external threats. Work through the above checklist to achieve defense-in-depth.
Now let‘s jump into detailed pfSense configuration guidance.
Step-by-Step Guide to Setting Up pfSense Port Forwards
The following step-by-step instructions demonstrate how to set up port forwards for common scenarios:
- Forwarding a single port
- Opening a range of consecutive ports
- Forwarding multiple random ports
- Redirecting all ports to a DMZ
I’ll be assuming an interface WAN IP of 138.197.99.199 to use across examples.
Forwarding a Single Port
Let‘s start with a simple port redirect for remote SSH access:
- Login to your pfSense web console
- Navigate to Firewall->NAT then click on the + icon to add a new rule
- Configure the port forward as:
- Interface – WAN
- Protocol – TCP
- Source
- Address Family – IPv4
- Source – Any
- Port Range – Any
- Destination
- Network – Single Host
- Address – 192.168.5.122 (Internal server IP)
- Port Range – 22 (SSH port)
- Save the Rule
- Click Apply Changes
This will now redirect any public IPv4 traffic hitting your WAN interface on port 22 down to your internal server on 192.168.5.122 port 22.
You can hit the server remotely for SSH using:
ssh user@138.197.99.199 -p 22
Similarly, single forwards can be added for 80/HTTP, 443/HTTPS, 25/SMTP etc. based on required services to expose.
Forwarding a Range of Consecutive Ports
If you need contiguous ports forwarded, the process is almost identical:
Let‘s forward 10000-10005 UDP for a remote gaming server:
- Within Firewall > NAT, Click + Add
- Configure the new rule as follows:
- Interface – WAN
- Protocol – UDP
- Source – Any
- Source port range – 10000-10005
- Destination – Single Host
- Destination Address – 192.168.20.50 (Game server internal IP)
- Destination port range – 10000-10005
- Click Save
- Click Apply Changes
Now UDP traffic from any internet host to public IP ports 10000-10005 will redirect in to the game server on internal IP 192.168.20.50 ports 10000-10005.
Forwarding Multiple Random UDP/TCP Ports
If you need to open multiple random TCP/UDP ports to the same target, you can leverage port aliases like:
-
Go to Firewall > Aliases
-
Click on the Ports tab
-
Click + to add new port alias
-
Name: WebApps
Port list:
- 80, 443, 3000, 4000, 4443, 8000, 8080, 8443
-
Click Save
Then when adding forwards:
- Within Firewall > NAT, Click + Add
- Interface, protocol, etc as usual
- Source port range – WebApps
- Destination IP and port – WebApps
This allows simple centralized management for random sets of ports.
Forwarding All Ports to a DMZ
To place a server or device in a DMZ with unrestricted access, first ensure DMZ forwarding is enabled under System > Advanced on the Networking tab.
Then forwarding all ports is straightforward:
- Within Firewall > NAT, Click + Add Rule
- Configure as follows:
- Interface – WAN
- Protocol – Any
- Source: Any
- Destination: Single Host
- Address: 192.168.254.225 (DMZ subnet address)
- Click Save
- Click Apply Changes
Now the destination host/subnet should have full accessed to required services while limiting exposure for other internal servers.
I encourage you to reference the pfSense NAT article for even more examples of real-world port forward use cases.
Troubleshooting Tips for Non-Working Port Forwards
If you set up a new port redirection but find services unreachable from the public internet, follow this troubleshooting flow:
-
Confirm configured applications are accessible locally
Test servers respond properly to the source ports attempted over loopback before investigating further.
-
Validate the forward is active in the interface config
Check Interfaces > WAN to ensure the NAT forward is listed at the bottom.
-
Review logs under Status > System Logs > Firewall
Check if traffic is being Allowed/Blocked or encounters errors.
-
Temporarily forward Source=Any and Dest=Any
This confirms basic connectivity without filtering and narrow down the issue.
-
Search Status > System Logs for the internal IP
Look for hints around traffic routing failures or rejections.
-
Check external access from different public sources
Verify traffic isn’t getting blocked further upstream or by additional firewall appliance.
-
Toggle Disabled/Re-Enable a troublesome rule
Forces a clean config reload for that port forward.
Don’t forget to check both ALLOW and BLOCK log entries around the services in question during investigations for clues.
Alternative Options for Remote Access
While port forwarding enables granular access controls, alternatives like VPNs and reverse proxies are worth considering:
-
Site-to-Site VPN Tunnels – Encrypted tunnels protect all traffic between office networks, avoiding port opens completely.
-
Remote Access VPN Servers – Allow road warriors to access internal resources without increasing attack surface for each server independently.
-
Reverse Proxy Servers – Intermediary proxy can enable authentication, DDoS protection and TLS encryption while hiding backend application servers.
Weight the extra complexity against security and flexibility factors for your environment when choosing approaches.
Integrating the pfSense router into a VPN deployment with proper user permissions and certificates configured will facilitate remote connectivity without increasing external threats significantly.
Conclusion
Port forwarding remains a pivotal capability for enabling secure remote access for home and business services. Tools like pfSense simplify configuring precise firewall policies while giving visibility into network traffic.
Carefully designing rule sets focused on least privilege access paired monitoring and hardening practices helps reduce risks associated with internet connectivity. Audit your current port forwards to confirm only essential servers get exposed.
I hope this guide to properly leveraging pfSense for your port forwarding needs gives you confidence in securely deploying accessible applications. Reach out via my website happyrouter.com if you have any other questions!