Configuring a pfSense Firewall with 3CX
Introduction
This document describes the configuration of pfSense v2.5.2+ for use with 3CX. This guide is written for PBX administrators on networks with a single WAN IP, or who are using their primary WAN IP for 3CX. We assume the 3CX Server in our example has an internal IP address of 192.168.3.155 and pfSense is listening on 192.168.3.1. We also use a public IP address of 1.2.3.4 and an FQDN of “service.tigunia.com” in the screenshots of the Split Brain DNS example.
Step 1: Configure Port Forwarding (NAT)
Login to the pfSense web management console and:
- Navigate to “Firewall” > “NAT”.
- Use the “Add” button on the right to add a new rule.
- Create NAT rules for all required ports that need to be forwarded, based on this list.
- “Protocol”: Set the protocol type depending on the port(s) you are forwarding.
- “Destination port range”: Select the port / port range for the NAT entry. If the port is not predefined as shown for SIP, enter the custom port number(s).
- “Redirect target IP”: Enter the internal IP address of the 3CX Phone System.
- “Redirect target port”: Enter the internal port, commonly the same as the external port.
- “Description”: Label the rule for easier identification.
- “NAT reflection”: Use system default.
- “Filter rule association”: Add associated filter rule.
- Click on “Save” and then “Apply” to activate the configuration and repeat these steps for each required NAT entry.
- Repeat step #3 for every forwarded port.
- After adding all port forward rules, they should look similar to the example below.
Step 2: Port Preservation (Full Cone NAT)
- Navigate to “Firewall” > “NAT” > “Outbound”.
- Set the type from automatic to “Hybrid” and press “Save”.
- Now create a new “Mapping Rule” as in the example above to set:
- “Source” for the 3CX host LAN IP, e.g. 192.168.3.155.
- “Port or Range” - enable “Static Port”.
- Move the rule to the first position in your “Mappings NAT table” to ensure operation, as shown in the first screenshot in this section.
- Make sure you have now applied settings on both the “Port Forward” and “Outbound” pages.
Step 3: FQDN Management
In the next step of this guide, you need to choose how you want to handle 3CX FQDN management inside your network. There are 2 options - Split Brain DNS or Hairpin NAT. Split Brain DNS has the advantage of keeping your 3CX network traffic internal to your network and not sending it out the WAN interface, but has a more complicated setup. Hairpin NAT is easier to configure but will consume more WAN traffic and may result in poor call quality in some situations. We recommend using Split Brain DNS whenever possible.
Option 1: Configuring Split Brain DNS
- Navigate to “Services” > “DNS Resolver”.
- Under General Settings tab, ensure that DNS Resolver is enabled
- Ensure that “All” is selected under “Network Interfaces” (or any specific interfaces you want DNS Resolver to listen on - Typically LAN)
- Ensure DNS Query Forwarding is enabled
- At the bottom of the page, under the Host Overrides section, click “Add”
- Add the host, domain, IP address as required, then click “Save”. The host will be the first part of your 3CX FQDN and the domain will be the last part of your 3CX FQDN. The IP Address will be the internal IP address of the 3CX Phone System
- Ensure your devices are using pfSense for DNS resolution (or using a device that does forwarding to pfSense for unknown queries). This configuration is usually handled by your DHCP server and the DNS servers it hands out
Option 2: Configuring Hairpin NAT
- Navigate to “System” > “Advanced”.
- Change “NAT Reflection mode for port forwards” to “Pure NAT”, activate the “Enable NAT Reflection for 1:1 NAT” checkbox and activate the “Enable automatic outbound NAT for Reflection” checkbox.
Step 4: Validating Your Setup
To validate your NAT / Port Forwarding setup, Go to “Dashboard” > “Firewall” in 3CX Management Console to run the 3CX Firewall Checker to validate if your firewall is correctly configured for use with 3CX. See more info about the Firewall Checker.
To validate your Split Brain DNS setup, you can use the nslookup tool (inside the network / behind your pfSense firewall) to validate how DNS is resolved. Simply type “nslookup <fqdn> <dns-server>” where <fqdn> is your 3CX FQDN and <dns-server> is the IP of the DNS server you wish to query. When querying an external DNS server you should see your WAN IP returned and when querying your internal pfSense DNS Resolver you should see the internal IP address of the 3CX Phone System returned.
- The below example shows checking the external IP resolution of FQDN “service.tigunia.com” against Google’s public DNS servers (8.8.8.8):
- The below example shows checking the internal IP resolution of FQDN “service.tigunia.com” against your internal pfSense Resolver (192.168.3.1):
To validate your Hairpin NAT setup, try accessing your 3CX FQDN from a computer inside the network by FQDN. If you are able to load the webclient, NAT Hairpinning should be working.
In some cases you might have to reboot the firewall for the changes to take effect.
If your remote phones or VoIP provider mostly work but randomly disconnect, then consider changing this option.
- Go to “System” > “Advanced”.
- Set “Firewall Optimization Options” to “Conservative”.
- Click on “Save”.
Special thanks to 3CX Titanium Partner, Managed IT & Document Technologies of Arizona and Brentt Graeb for the NAT/Port Forwarding and Port Preservation sections of this guide. Special thanks to 3CX Gold Partner, Tigunia, and Martin Twerski for the Split Brain DNS and Hairpin NAT sections of this guide.
See Also
- The Firewall & Router Configuration Guide explains how to configure your firewall.
Last Updated
This document was last updated on 20 June 2023