When running a FreePBX server behind a NAT firewall, your router or firewall may aggressively close idle UDP or TCP connections to your SIP provider (such as Twilio) if there is no continuous traffic. This connection drop typically results in failed inbound calls, one-way audio, or unreachable trunks. To prevent the firewall from timing out and closing these ports, you must send periodic “keep-alive” packets. For SIP trunks, this is achieved by periodically sending SIP OPTIONS. The following guide explains how to enable and configure these keep-alives—referred to as the “Qualify” setting in FreePBX—for a PJSIP trunk to maintain stable, uninterrupted connectivity.
How to Configure the Qualify Frequency in FreePBX
Because FreePBX 17 uses PJSIP exclusively (chan_sip is deprecated), you will be adjusting the advanced settings on your PJSIP trunk.
- Log into your FreePBX Web Interface.
- Navigate to Connectivity > Trunks.
- Click the edit (pencil) icon next to your Twilio PJSIP trunk.
- Select the pjsip Settings tab, and then click on the Advanced sub-tab.
- Scroll down to find the setting named Qualify Frequency.
- **Set the value to
30**:
- A value of
30(seconds) is widely recommended. It is frequent enough to keep typical NAT bindings open (most firewalls drop idle UDP sessions after 30-60 seconds) but spaced out enough to avoid being rate-limited or banned by Twilio for spamming. - Note: Setting this value to
0disables the SIP OPTIONS keep-alives entirely.
- Click the Submit button at the bottom of the page.
- Click the red Apply Config button at the top right to reload the dialplan.
Verifying the Keep-Alives via the Asterisk CLI
Once applied, Asterisk will begin sending SIP OPTIONS to Twilio every 30 seconds. As long as Twilio responds with a 200 OK, Asterisk considers the trunk reachable. You can verify that this is working properly by checking the endpoint status in the Asterisk CLI.
Open your server’s terminal or SSH into your FreePBX machine and connect to the Asterisk CLI:
asterisk -rvvv
Once inside the Asterisk CLI, run the following command to check the status of your PJSIP endpoints:
pjsip show endpoints
Look for your Twilio trunk in the output. If the SIP OPTIONS are successfully reaching Twilio and returning, the endpoint’s status will show as Avail along with the current round-trip ping time (latency), proving the connection is actively being kept alive.
To exit the Asterisk CLI when you are finished, type:
exit
