Howwise RSS
VoIP & Phone Systems9 min read

Asterisk Remote Extension Securely: VPN, TLS and SRTP

Short answer

To run an Asterisk remote extension securely, put the phone on a WireGuard or OpenVPN tunnel if you can. If you can't, use PJSIP TLS 5061 with SRTP, a long unique secret, firewall zones, fail2ban and locked-down outbound routes.

Key takeaways
  • Use a VPN first, PJSIP TLS plus SRTP second, and never expose plain UDP 5060 to the whole internet.
  • Toll fraud comes from weak secrets and permissive outbound routes, so fix both before opening any port.
  • Remote NAT needs external_signaling_address, external_media_address, local_net, rtp_symmetric, force_rport, rewrite_contact and direct_media=no.
  • Fail2ban only works if security_log is enabled, and it can lock out a remote user behind CGNAT.
  • Prove the setup from outside with nmap, sngrep and a two-way test call that shows TLS and RTP/SAVP.

Which method runs an Asterisk remote extension securely?

Three designs exist for an Asterisk remote extension: a VPN, direct exposure with PJSIP TLS and SRTP, and an SBC or SIP proxy in front of the PBX. The deciding factor is how much of the PBX you let strangers reach. A VPN exposes only one UDP port that stays silent to unauthenticated packets. Direct SIP exposes a service that answers every scanner on the internet.

Plain UDP 5060 open to the world is the worst option. Scanners find it within hours, brute-force extension secrets, and the signalling and audio cross the internet in clear text. Anyone on the path can read the calls and harvest credentials.

MethodSecurityEffortBest when
VPN (WireGuard/OpenVPN) on phone, softphone or home routerHighest. SIP port is never publicMedium. Key per user or deviceStaff you control, any size. Recommended first
Direct PJSIP TLS 5061 + SRTPGood if hardened and monitoredMedium. Certificate, firewall and fail2banPhones that can't run a VPN, or mobile softphones with push
SBC or SIP proxy (Kamailio, OpenSIPS, commercial SBC)High. Absorbs scans and floodsHigh. A second system to runMany remote users, or compliance needs
Plain UDP 5060 and RTP forwarded to the PBXPoorLowNever
Tip: WireGuard is small and quick to roam between networks, which suits laptops and mobile softphones. A router-based tunnel (a small GL.iNet or similar router at the home) lets any desk phone work with no VPN client on the phone.

How does toll fraud happen, and how do you limit the damage?

Attackers scan for SIP on 5060, try extension numbers with common passwords, then place calls to premium-rate or international destinations, often at night or on weekends. One compromised extension can run up a large bill before anyone looks at the CDR. The fix is to make that call fail even if a secret leaks.

Limit what any extension can dial, not only who can register. International dialing should be off by default and enabled per user, with a route that needs a PIN or a separate class of service.

  1. In Connectivity > Outbound Routes, make the international route the last one and give it a Route Password or restrict it with dial patterns for approved countries only.
  2. Block premium prefixes (for example 900, 976 and country-specific premium ranges) with a route that goes to a congestion tone.
  3. Set per-extension limits: in Extension > Advanced, set Max Contacts to 1 or 2, and cap simultaneous calls with a dialplan check that uses GROUP() and GROUP_COUNT() to reject calls above a per-extension concurrency (example below). Also ask your SIP trunk provider to set a concurrent-channel limit on the trunk.
  4. Ask your SIP trunk provider for a daily spend cap and a destination country allow-list. This is the only control that works if the PBX itself is compromised.
  5. Review the CDR weekly for after-hours international calls.
; /etc/asterisk/extensions_custom.conf (illustrative; call this from your outbound route's custom context)
[limit-concurrent]
exten => s,1,Set(GROUP(outbound)=${CALLERID(num)})
 same => n,GotoIf($[${GROUP_COUNT(${CALLERID(num)}@outbound)} > 2]?toomany)
 same => n,Return()
 same => n(toomany),NoOp(Concurrency limit hit for ${CALLERID(num)})
 same => n,Congestion()

What makes a strong secret for a remote extension?

Use 16 or more random characters, unique per device. Never use the extension number as the password, and never reuse the voicemail PIN, which is short and often leaked in email. FreePBX generates a strong secret when you create the extension, so keep it.

Do not reuse one secret across a user's desk phone and softphone. If one device is lost you can then rotate one secret without reprovisioning the other.

Brute-force tools try extension number as password first, then common words. A random 16-character secret takes that attack from minutes to practically impossible, which is why this is the cheapest control on the page.

# generate a 20-character secret
openssl rand -base64 18 | tr -d '/+=' | cut -c1-20

How do you set up PJSIP TLS and SRTP on FreePBX?

Start with a real certificate whose name matches the FQDN the phones register to. In FreePBX, Admin > Certificate Manager > New Certificate > Generate Let's Encrypt Certificate. This needs port 80 reachable for the challenge and a public DNS name. Then set it as the default certificate.

Phones validate that the certificate name matches the server they dial. If they register to an IP address or a different name, validation fails, so register to the FQDN.

  1. Settings > Asterisk SIP Settings > Chan PJSIP: set the TLS transport to listen on 0.0.0.0 port 5061 and enable it. Turn off transports you do not use (for example UDP and TCP on 5060) if every remote device uses TLS.
  2. On the TLS/SSL/SRTP tab, select the certificate and set the SSL method to TLSv1.2 (or the highest your phones support). Verify server is fine to leave on; avoid enabling client verification unless you issue client certificates.
  3. Edit the extension > Advanced: set Transport to the TLS transport and Media Encryption to SRTP via in-SDP (SDES). Use DTLS-SRTP only for WebRTC-style clients.
  4. On a Yealink desk phone, set Account > Register > Transport to TLS, server host to the FQDN and port 5061, SRTP Mode to Compulsory, and enable Only Accept Trusted Certificates. On Polycom, set transport TLS and media SRTP offer and require, with a CA list that includes the issuer.
  5. Softphones such as Zoiper, Linphone and Acrobits support TLS plus SRTP. Pick TLS transport, enable SRTP as mandatory, and the FQDN as domain.
; /etc/asterisk/pjsip.transports_custom.conf (illustrative; FreePBX normally builds this from the GUI)
[0.0.0.0-tls]
type=transport
protocol=tls
bind=0.0.0.0:5061
cert_file=/etc/asterisk/keys/pbx.example.com.crt
priv_key_file=/etc/asterisk/keys/pbx.example.com.key
method=tlsv1_2
external_signaling_address=pbx.example.com
external_media_address=203.0.113.10
local_net=192.168.1.0/24

; extension endpoint (set via GUI)
; media_encryption=sdes
; media_encryption_optimistic=no
Warning: A Let's Encrypt certificate lasts 90 days. If renewal fails and the certificate expires, every TLS phone stops registering at once. Confirm that the Certificate Manager renewal works, and alert on the expiry date.

Which NAT settings does a remote extension need?

Remote phones sit behind home NAT, and the PBX usually sits behind its own. The classic symptom is registration that works but one-way or no audio, because the SDP or Contact header advertises a private address. Most remote problems come from here, not from TLS.

On the transport set the PBX's public address so Asterisk rewrites its own SDP and Via headers. On each remote extension tell Asterisk to answer to where packets actually came from.

SettingValueWhy
external_signaling_addresspublic FQDN or IPCorrect Contact and Via headers sent to remote phones
external_media_addresspublic IPCorrect RTP address in SDP
local_netevery internal subnetStops Asterisk rewriting addresses for LAN phones
rtp_symmetricyesSend RTP back to the source it came from
force_rportyesReply to the source port of the request
rewrite_contactyesUse the real source address, not the private one in Contact
direct_medianoKeep audio through the PBX so NAT does not break it
qualify_frequency30 to 60Keeps the NAT mapping alive and detects dead contacts
Tip: Turn off SIP ALG on the home router. It rewrites SIP packets badly and is the most common cause of registration drops and one-way audio. Also forward and allow only the RTP range you configured, such as 10000-20000 UDP, narrowed to the minimum the call count needs.

How do you lock down the firewall and fail2ban?

In FreePBX, the Firewall module (Connectivity > Firewall) works by zones. Set the interface zone to Internet, then enable only the services remote users need: PJSIP TLS (5061) and RTP (10000-20000, which you can narrow in Asterisk SIP Settings). Leave the web GUI, SSH, UCP and plain SIP closed to Internet. Add known home IPs to Trusted or Other zones when they are static, so those can use more services without opening them to everyone.

Enable Responsive Firewall, which lets a device that registers successfully reach the media ports, and enable Intrusion Detection, which is the fail2ban integration. Leave Allow Anonymous Inbound SIP off so unauthenticated calls cannot reach the dialplan.

Do not look for an allow_guests option in PJSIP, because it does not exist. The old chan_sip setting was allowguest=no. PJSIP rejects unknown callers when no anonymous endpoint is defined, which is what FreePBX does when Allow Anonymous Inbound SIP is off.

On a custom fail2ban install, Asterisk needs a security log first. Add the line below to logger_logfiles_custom.conf, reload logger, then enable the jail.

; /etc/asterisk/logger_logfiles_custom.conf
security_log => security

# /etc/fail2ban/jail.d/asterisk.local
[asterisk]
enabled  = true
filter   = asterisk
logpath  = /var/log/asterisk/security_log
maxretry = 5
findtime = 600
bantime  = 3600
ignoreip = 127.0.0.1/8 203.0.113.50

# check
asterisk -rx 'logger reload'
fail2ban-client status asterisk
fail2ban-client set asterisk unbanip 198.51.100.7
Warning: Staff behind CGNAT or a shared office IP share an address with strangers. Repeated failures from one user, such as a phone with an old password, can ban everyone on that address. Fix stale phones quickly, use ignoreip for known static addresses, and keep a way to unban over the VPN.

How do you verify the setup from outside and monitor it afterwards?

Test from a network outside yours, such as a phone hotspot, because an inside scan shows nothing useful. You want proof that only the intended ports answer and that calls are encrypted.

Extension-level restrictions also help. Restrict by IP with a PJSIP identify or ACL (permit and deny) when the user has a static address, set Max Contacts to 1 or 2, and treat a non-default port as obscurity only, not security.

  1. From outside run the scan below. Expect 5060 closed or filtered, 5061 open, and nothing on 22, 80, 443 or 5038 unless you chose them.
  2. On the PBX run pjsip show endpoints and confirm the contact shows the public source address and a good qualify time.
  3. Run sngrep and confirm the registration came over TLS (port 5061) and that the SDP in INVITE shows RTP/SAVP with a crypto line.
  4. Place calls in both directions and check audio both ways. One-way audio points to external_media_address, a wrong local_net, a blocked RTP range or SIP ALG.
  5. Watch the fail2ban status and the Asterisk log for failed registrations, and keep FreePBX and Asterisk updated with security patches.
nmap -sU -p 5060 pbx.example.com
nmap -sS -p 22,80,443,5038,5060,5061 pbx.example.com
asterisk -rx 'pjsip show endpoints'
sngrep -d any port 5061 or port 5060
fail2ban-client status asterisk
Tip: Set alerts for bursts of failed registrations, for calls outside business hours, and for any call to a destination nobody uses. A daily CDR report of international calls costs nothing and catches fraud early.

What are the most common mistakes?

Most breaches come from a short list of errors, and each is easy to check.

Forwarding 5060 UDP and 10000-20000 straight to the PBX with no firewall zone. Leaving Allow Anonymous Inbound SIP on. Using weak or number-based secrets. Letting the certificate expire. Leaving international routes open. Exposing the Asterisk manager port 5038 or log files, which leak extension names and addresses.

Common questions

Is a VPN better than SIP TLS for remote phones?

For most small businesses, yes. A VPN keeps SIP off the public internet, so scanners never see the PBX, while TLS leaves a reachable service that needs fail2ban and strong secrets. TLS with SRTP is the right fallback when phones cannot run a VPN.

Do I still need SRTP if the phone is on a VPN?

Not for confidentiality, since the tunnel encrypts the audio. SRTP adds a second layer and matters if the tunnel ends before the PBX. On a router-to-PBX tunnel it is optional.

Can I change port 5060 to hide the PBX?

It cuts log noise from naive scanners, but it does not stop a determined scan, which finds SIP on any port. Treat it as a minor extra layer and rely on TLS, strong secrets and firewall rules.

Why does the phone register but have no audio?

Signalling and media take different paths, so registration can work while RTP fails. Check external_media_address, local_net, direct_media=no, rtp_symmetric and the RTP range in the firewall, then look for SIP ALG on the home router.

Why do mobile softphones miss calls when the app is closed?

The OS suspends background apps, so the registration lapses and the PBX cannot reach them. You need push notifications through the softphone vendor's gateway, which has its own setup and privacy trade-offs.

Related topics:asteriskfreepbxpjsipsip securityfail2ban