IT-LINUXMAKER, OpenSource, Tutorials

SIP trunks, the standard connection to the public telephone network

SIP trunks in FreePBX/Asterisk are used to establish a connection between the Asterisk PBX and the public switched telephone network (PSTN) or a VoIP provider. They enable voice connections to be established over the internet, just as traditional ISDN or analog lines were used before 2018/2020. Thus, a SIP trunk represents a virtual telephone connection through which FreePBX/Asterisk can send and receive calls to landlines and mobile networks using VoiceIP. SIP trunks are the digital equivalent of traditional telephone lines.

The modular approach of FreePBX/Asterisk requires that the interface to the outside world be configured only after the SIP settings have been configured and before the extensions are created. Without a SIP trunk, Asterisk would be merely an internal telephone system—useful for internal calls, but not connected to the outside world.

SIP trunk in consumer routers

It's worth mentioning here that the consumer routers from major telephone providers (Speedport, Fritzbox, etc.) handle all SIP trunk management invisibly for the end user. The customer simply doesn't know that their access data is used for the SIP trunk. They're essentially mini-PBX systems that communicate directly with the VoIP provider—without Asterisk or additional software.
With most consumer tariffs (e.g. Telekom MagentaZuhause) you actually get individual SIP accounts per phone number and not a true SIP trunk in the business sense, where one account allows for several parallel lines plus a direct dial block.

Trunks

SIP (chan_pjsip)

General

Dialed Number Manipulation Rules

PJSIP Settings General

PJSIP Settings Advanced

PJSIP Settings Advanced

PJSIP Settings Advanced

PJSIP Settings Codecs

The SIP trunks are configured under "Connectivity => Trunks" (IP address/admin/config.php?display=trunks). On this page, select "+ Add SIP (chan_pjsip) Trunk" from the "Add Trunk" dropdown menu.

Tab "General"

In the "General" tab, under Trunk Name, you can assign any name for the trunk.
Since Telekom assigns three phone numbers and you can also register multiple providers, you can create a creative and pragmatic name here. For example, "Provider Name_Phone Number," since you want to be able to quickly identify the trunk connections used in the logs later. Therefore, it makes sense to configure the trunk in a structured manner in advance.

The corresponding phone number is entered under Outbound CallerID, firstly in angle brackets and secondly with the area code including the "0" instead of the country code "+49." This is important for internal processing. Maximum Channels contains the number of channels; at least for Telekom, this is two. All other settings can be adopted from the offered default values.

Tab “PJSIP Settings”

General

This is where you enter the information you received from your phone provider for registration. Username is your user ID (for Telekom), and Password is the password you received.

The server is entered under SIP Server. Depending on your plan, Telekom can use different servers (tel.t-online.de, sip-trunk.telekom.de, etc.). You should find out this information. And the SIP Server Port must contain the port "5061", at least for Telekom's sip-trunk.telekom.de, and the Transport should be set to "0.0.0.0-tcp", otherwise registration won't work.

Advanced

In FreePBX/Asterisk, the "Permanent Auth Rejection" option for SIP trunks refers to the behavior when handling failed authentication attempts. If a trunk from a SIP provider or a remote party attempts to authenticate with incorrect credentials, the remote party will be permanently rejected, even if it later responds with correct credentials. Therefore, this value should be set to "Yes".
"Fatal Retry Interval" is the wait time (in seconds) after a fatal error (e.g., no response from the server) before a new attempt is made. This prevents continuous requests when the server is unavailable. The value should be 300 seconds. "General Retry Interval" should be 60 seconds and is the default wait time between normal registration attempts when errors occur.
"Expiration" is 480 seconds, which represents the validity period of a successful registration with the provider until a new registration is attempted. The "Max Retries" setting of 10 attempts represents the maximum number of retries before the trunk is considered "down." After that, registration is abandoned until a manual reboot or another attempt is made.

The value under "Outbound Proxy" is only required if you have a Telekom plan with SIP trunk; otherwise, it's not required. The blue markings are only mentioned because they are very specific. In that case, this would be "sip:reg.sip-trunk.telekom.de".

The phone number of the trunk is entered under “Contact User” and “From User”, and “From Domain” contains “tel.t-online” or “sip-trunk.telekom.de”.

When using the tariff with Sip-Trunk at Telekom, the parameters "Client URI" are additionally filled with “sip:+49Callnumber@sip-trunk.telekom.de”, "Server URI" with “sip:sip-trunk.telekom.de” and “Match (Permit)” with “217.0.0.0/13”.
"Match (Permit)" is important for IP-based trunks such as sip-trunk.telekom.de, and specifies which IP addresses or network ranges can accept incoming SIP packets for this trunk. However, if authentication is register-based, as with tel.t-online.de (old T-Online SIP access), this is not necessary, as registration with username/password is used here.

Setting "Inband Progress" to "Yes" controls how early Asterisk forwards audio from the provider (trunk) to the caller—specifically, ringbacks, announcements, or error messages. Asterisk forwards audio (e.g., announcements or ringtones) even if the call hasn't been officially accepted (200 OK). This is important if the provider doesn't correctly send 180 Ringing or 183 Session Progress with SDP—in other words, simply streams tones or announcements directly.

Codecs

At Telekom, g722 and alaw should be enabled as codecs in the PJSIP trunk, because Telekom supports them for voice transmission – in particular, alaw (G.711a) is the standard in Europe. g722 offers HD Voice and is preferred if both parties can support it. The video codecs h264 and mpeg4 are generally optional and are not used by Telekom for voice calls, but can remain enabled if an internal device (such as a video phone) supports them – they do not interfere as long as they are not in use. Asterisk preferentially selects the best available codec (e.g., g722), then falls back to alaw if necessary.

Tab “Dial Number Manipulation Rules”

The "Dial Number Manipulation Rules" in the trunk are used to modify the phone number again before it is sent to the SIP provider (trunk). Even if numbers are already being manipulated in the outbound routes, there are good reasons to implement additional manipulation in the trunk. While the outbound routes regulate what comes out of the phone, trunk rules regulate what goes to the provider.
For example, you dial 089123456 internally. The outbound route then adds a leading 0, i.e. 0089123456. The trunk rule removes the leading 0 and instead appends +49 to +4989123456.

Why do both?

  • Trunks can have different requirements (e.g. +49 vs. 0049 vs. local network only).
  • Outbound routes treat all destinations equally (e.g. mobile, landline), but not every trunk needs the same format.
  • This allows you to dial consistently (e.g. always 089... or +49...), and the adjustment is only made trunk-specifically.

Dial Rules in the trunk are the final adaptation layer that ensures that the provider receives exactly the format it expects – regardless of how the route previously constructed the number. They aren't always needed, but they are important for multiple trunks or specific provider requirements.

The dial rules offered here in the screenshot are suitable for Stuttgart and can be adapted to the area code.

 


IT-LINUXMAKER, OpenSource, IT-Support, IT-Consulting

© IT-LINUXMAKER 2025