By the end of this you will have one real phone number that rings a softphone on your laptop through an Asterisk server you built and control. Callers hear a short menu you recorded, after-hours calls go straight to a custom greeting, voicemail lands in your inbox as a .wav file, known callers show up by name, and you can place outbound calls that show your number. The signaling is encrypted with TLS and the audio with SRTP on both legs, Twilio to Asterisk and Asterisk to your softphone.

It is a one-person “developer office” line. You can put it on a resume and have a recruiter hear your own IVR instead of a carrier’s robot voice. You will also learn how phone systems actually work, which very few developers ever get shown.

The field notes come from migrating a real office phone system from a legacy carrier to Twilio Elastic SIP Trunking, with a self-managed Asterisk server in the middle and numbers ported in waves. Everything else was checked against the Asterisk 22 source and Twilio’s current documentation.

Last verified: December 2026. Versions used: Asterisk 22.12.0 (LTS) built from source with bundled pjproject 2.17, Debian 13, fail2ban 1.1.0, certbot 4.0, MicroSIP 3.23.6, Linphone 6.2. Twilio prices are US prices at the time of writing.

How a phone call works

You need about ten terms. Learn these and every log line later makes sense.

  • PSTN (public switched telephone network): the global network that landlines and cell phones are on.
  • DID (direct inward dialing number): a phone number that routes calls into your system. When you “buy a number” from Twilio, you buy a DID.
  • SIP (Session Initiation Protocol, RFC 3261): the text protocol that sets up, changes and ends calls. It looks a lot like HTTP: request lines such as INVITE and BYE, response codes such as 200 OK and 404 Not Found, and headers. Turn on the SIP logger later in this guide and you can read the whole conversation with your eyes.
  • SIP trunk: a connection between your system and a carrier that carries calls to and from the PSTN. Twilio Elastic SIP Trunking is one.
  • PBX (private branch exchange): the switch you own. It decides where each call goes. Asterisk is the PBX here.
  • Extension and endpoint: inside Asterisk, an extension is an entry in the dialplan (a number or name that triggers instructions) and an endpoint is a configured device or trunk. People mix the two up constantly.
  • Registration: a phone tells the PBX “I am at this IP and port now” with a REGISTER request. Trunks to Twilio do not register; Twilio finds you through a fixed URI.
  • Signaling vs media: SIP only carries the setup. The voice itself travels separately as RTP (Real-time Transport Protocol) over UDP on a different port, described inside the SIP message by an SDP body (Session Description Protocol). SRTP is encrypted RTP.
  • Codec: how audio is encoded. We use G.711 μ-law (called PCMU or ulaw), uncompressed 64 kbit/s telephone audio and one of the two codecs Twilio supports by default (the other is μ-law’s European sibling, A-law).
  • E.164: the international number format, a +, the country code, then the number: +15555550100. Twilio requires it.
  • NAT (network address translation): your home router hides your laptop behind one public IP. SIP writes IP addresses inside its messages, so NAT breaks it in a specific way: calls connect but only one side hears audio. That symptom is called one-way audio, and much of VoIP debugging is chasing it.

This is what one inbound call looks like on the wire:

Sequence diagram of an inbound call from a caller through Twilio to Asterisk and then the softphone An inbound call: Twilio sends an INVITE over TLS, Asterisk answers and plays the IVR, then rings the softphone and bridges the two SRTP streams.

What you are building

Architecture diagram showing Twilio, the VPS with nftables, Asterisk, fail2ban and msmtp, and a softphone behind a home router Signaling and media take different paths. Twilio’s signaling and media come from different address ranges, and the firewall treats them separately.

Port Protocol Allowed from Purpose
22 TCP Anywhere (keys only) SSH
80 TCP Anywhere Let’s Encrypt renewal (certbot standalone)
5061 TCP (TLS) Twilio signaling ranges, plus rate-limited others SIP from Twilio and the softphone
10000-20000 UDP Anywhere SRTP media

The PBX lives on a small VPS with a public IPv4 address on its own network interface. That takes NAT out of the server side, and with it a whole class of one-way audio problems. A $6/month 1 GiB DigitalOcean droplet is enough to run it (lauden.dev runs on DigitalOcean too); any Debian 13 VPS works. If the build runs out of memory on a small box, add a swap file or build with plain make.

Why Elastic SIP Trunking and not TwiML

Twilio also sells Programmable Voice, where Twilio runs the call logic and asks your web app what to do through webhooks and TwiML (its XML call-control language). That needs no server of your own for voice, and an IVR is a few lines of XML. Elastic SIP Trunking only moves calls between the PSTN and your SIP server; everything else is yours. I chose the trunk because the point is to learn how a PBX works, and because it is cheaper per minute: local inbound is $0.0034/min on the trunk against $0.0085/min on Programmable Voice at the time of writing. The trade-off is real: you now own a server, its security and its uptime.

Before you start

Twilio account. Elastic SIP Trunking is only available after you upgrade from a trial account, and Twilio may ask for a government ID during the upgrade (it uses a vendor called Persona). Outbound calls to +1 numbers need an approved Primary Customer Profile in Trust Hub, which Twilio says can take up to 7 business days to review, so submit it on day one. New accounts without an approved Business Profile also get limited concurrent calls, and the default termination rate is 1 call per second. Neither matters for one person.

A domain name. Create a DNS A record such as pbx.example.com pointing at the VPS. If you have never done DNS or a VPS before, Self-Hosting: Why in The Fuck Did I Not Learn This in School? covers buying a domain, creating the droplet, SSH keys and basic hardening. Do that first and come back.

A Debian 13 server with SSH key login working and password login disabled. Every command below runs as a normal user with sudo. When a step edits a file, it uses vim: press i to insert, Esc then :wq to save and quit.

Step 1: the firewall

Debian 13 uses nftables. Install it and replace the default ruleset:

sudo apt update && sudo apt install -y nftables vim
sudo vim /etc/nftables.conf
#!/usr/sbin/nft -f
# /etc/nftables.conf for the PBX. Default: drop everything inbound except what is listed.
flush ruleset

table inet filter {
    # Twilio Elastic SIP Trunking signaling ranges (all edges).
    # Authoritative list: https://www.twilio.com/docs/sip-trunking/ip-addresses
    set twilio_sip {
        type ipv4_addr
        flags interval
        elements = {
            54.172.60.0/30, 54.244.51.0/30, 54.171.127.192/30, 35.156.191.128/30,
            54.65.63.192/30, 54.169.127.128/30, 54.252.254.64/30, 177.71.206.192/30
        }
    }

    # Per-source-address meter for new SIP/TLS connections from non-Twilio hosts.
    set sip_meter {
        type ipv4_addr
        flags dynamic
        timeout 5m
    }

    chain input {
        type filter hook input priority filter; policy drop;

        ct state established,related accept
        ct state invalid drop
        iif "lo" accept
        meta l4proto { icmp, ipv6-icmp } accept

        tcp dport 22 accept                                   # SSH (keys only)
        tcp dport 80 accept                                   # certbot standalone renewals

        # SIP over TLS: Twilio always, everyone else rate limited.
        ip saddr @twilio_sip tcp dport 5061 accept
        tcp dport 5061 ct state new add @sip_meter { ip saddr limit rate over 10/minute } drop
        tcp dport 5061 accept

        # RTP/SRTP media (must match rtp.conf rtpstart-rtpend).
        udp dport 10000-20000 accept
    }

    chain forward {
        type filter hook forward priority filter; policy drop;
    }

    chain output {
        type filter hook output priority filter; policy accept;
    }
}

Check it, then load it:

sudo nft -c -f /etc/nftables.conf && sudo systemctl enable --now nftables
sudo nft list set inet filter twilio_sip

Twilio publishes eight /30 signaling ranges, one per edge location, and says to allow all of them because calls can fail over between edges and “not all of these IP addresses will host active gateways at a given time.” Twilio’s media comes from 168.86.128.0/18. I leave the media ports open to everyone because the softphone sends media from wherever you happen to be, and Asterisk’s strict RTP mode (on by default) drops packets that do not come from the negotiated source. Re-check Twilio’s IP page every few months; if it changes, update this set and the identify section in pjsip.conf together.

This ruleset is IPv4 only. The Asterisk transport below also binds IPv4 only, so nothing SIP-related listens on IPv6.

Step 2: build Asterisk 22 LTS from source

Asterisk ships an LTS (long-term support) release every two years. At the time of writing, 22.x is LTS with bug fixes until October 2028, and 24.x became the new LTS on November 5, 2026. I use 22.12.0: it has two years of point releases behind it, and every option in this article was checked against its source. I have not checked these configs against 24. Check the Asterisk versions page for the current state.

Debian 13 does not ship an Asterisk package; it exists only in unstable. So we build from source, using the project’s own script to install the build dependencies:

sudo apt install -y build-essential wget curl libsystemd-dev
cd /usr/local/src
sudo wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-22.12.0.tar.gz
sudo tar xzf asterisk-22.12.0.tar.gz
cd asterisk-22.12.0
sudo ./contrib/scripts/install_prereq install

install_prereq installs libsrtp2-dev, which Asterisk needs for SRTP. I add libsystemd-dev myself because the systemd unit we use later expects Asterisk to report readiness to systemd, and the script does not install it.

Configure, then enable the μ-law versions of the English prompts and hold music so Asterisk does not have to transcode them on every call:

sudo ./configure
grep -c 'define HAVE_SYSTEMD 1' include/asterisk/autoconfig.h
sudo make menuselect.makeopts
sudo menuselect/menuselect --enable CORE-SOUNDS-EN-ULAW --enable MOH-OPSOUND-ULAW menuselect.makeopts

The grep must print 1. If it prints 0, libsystemd-dev was missing when you ran configure.

configure uses the bundled pjproject (the SIP stack under chan_pjsip) by default and downloads that tarball as part of configure, so the server needs internet access. Build and install:

sudo make -j"$(nproc)"
sudo make install
sudo make samples
sudo make install-logrotate

make samples installs example configs into /etc/asterisk. We replace four of them below.

Run Asterisk as its own user

Asterisk runs as root unless you tell it otherwise, and a phone server that faces the internet should not. Create a system user and give it only what it needs to write:

sudo useradd --system --user-group --home-dir /var/lib/asterisk --shell /usr/sbin/nologin asterisk
sudo chown -R asterisk:asterisk /var/lib/asterisk /var/spool/asterisk /var/log/asterisk /var/cache/asterisk
sudo mkdir -p /etc/asterisk/keys
sudo chown -R root:asterisk /etc/asterisk
sudo chmod 750 /etc/asterisk /etc/asterisk/keys
sudo find /etc/asterisk -type f -exec chmod 640 {} \;

Configs are readable by Asterisk but not writable, except voicemail.conf, which we make writable later so you can change your PIN from the phone.

Install the systemd unit. This is the unit Asterisk ships in contrib/systemd/asterisk.service, with one line uncommented so systemd creates /run/asterisk for the control socket on each boot:

sudo vim /etc/systemd/system/asterisk.service
[Unit]
Description=Asterisk PBX and telephony daemon.
After=network.target

[Service]
Type=notify
Environment=HOME=/var/lib/asterisk
WorkingDirectory=/var/lib/asterisk
User=asterisk
Group=asterisk
RuntimeDirectory=asterisk
ExecStart=/usr/sbin/asterisk -mqf -C /etc/asterisk/asterisk.conf
ExecReload=/usr/sbin/asterisk -rx 'core reload'
LimitCORE=infinity
Restart=always
RestartSec=4
StandardOutput=null
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Two small changes to the sample configs before the first start. Stop the modules that would open listeners we do not use (chan_iax2 on UDP 4569, pbx_dundi on UDP 4520, chan_unistim on UDP 5000), and turn on Asterisk’s security log, which fail2ban will read:

printf 'noload = chan_iax2.so\nnoload = pbx_dundi.so\nnoload = chan_unistim.so\n' | sudo tee -a /etc/asterisk/modules.conf
sudo sed -i 's/^;security.log => security/security.log => security/' /etc/asterisk/logger.conf
sudo systemctl daemon-reload
sudo systemctl enable --now asterisk
sudo asterisk -rx 'core show version'

Expected output starts with Asterisk 22.12.0 built by root. Confirm SRTP support is loaded:

sudo asterisk -rx 'module show like res_srtp'

You should see res_srtp.so with status Running. If it is missing, libsrtp2-dev was not installed when you ran configure; install it and rebuild.

Step 3: a TLS certificate

Twilio and your softphone both connect to Asterisk over TLS, so Asterisk needs a certificate for pbx.example.com. If you followed the self-hosting article you already know certbot. Here we use its standalone mode, which briefly runs its own web server on port 80, because nothing else on this box serves HTTP.

First, the deploy hook. Certbot runs every executable in /etc/letsencrypt/renewal-hooks/deploy/ after it gets a certificate, and since certbot 3.2 that includes the first issuance. This hook copies the files where the asterisk user can read them and tells PJSIP to pick them up:

sudo apt install -y certbot
sudo mkdir -p /etc/letsencrypt/renewal-hooks/deploy
sudo vim /etc/letsencrypt/renewal-hooks/deploy/asterisk.sh
#!/bin/sh
# Copy the renewed certificate for Asterisk and reload the PJSIP transport.
set -e
DOMAIN="pbx.example.com"

case "$RENEWED_LINEAGE" in
  */"$DOMAIN") ;;
  *) exit 0 ;;
esac

install -m 640 -o root -g asterisk "$RENEWED_LINEAGE/fullchain.pem" /etc/asterisk/keys/fullchain.pem
install -m 640 -o root -g asterisk "$RENEWED_LINEAGE/privkey.pem" /etc/asterisk/keys/privkey.pem

if systemctl is-active --quiet asterisk; then
  asterisk -rx 'module reload res_pjsip.so'
fi
sudo chmod 755 /etc/letsencrypt/renewal-hooks/deploy/asterisk.sh
sudo certbot certonly --standalone -d pbx.example.com
sudo ls -l /etc/asterisk/keys/

You should see fullchain.pem and privkey.pem owned by root:asterisk. Renewals run from a systemd timer; confirm it exists with systemctl list-timers 'certbot*'.

Why module reload res_pjsip.so is enough: Asterisk’s TLS transport is not reloadable for most settings, but when the certificate and key filenames stay the same and the files change on disk, a reload restarts the TLS listener with the new certificate. That is why the hook copies to fixed names instead of pointing Asterisk at certbot’s versioned paths.

Twilio’s docs do not say whether your server certificate must come from a public CA. On the office build I ran a self-signed certificate on the Twilio-facing side. Here a Let’s Encrypt certificate is the right call anyway, because your softphone should verify the server it sends a password to.

Step 4: set up the Twilio trunk and buy a number

All of this is in the Twilio Console under Elastic SIP Trunking. Console labels change; the Elastic SIP Trunking docs are the reference.

  1. Create the trunk. Elastic SIP Trunking > Trunks > Create New Trunk. Name it.
  2. General tab. Turn on Secure Trunking. With it on, Twilio rejects unencrypted calls, uses SRTP (AES_CM_128_HMAC_SHA1_80 on inbound calls), and accepts TLS 1.2 and above only. Leave Symmetric RTP off; Twilio’s docs call the off setting more secure.
  3. Termination tab (calls from you to the PSTN). Pick a Termination SIP URI such as example-dev-office.pstn.twilio.com; Twilio suggests dashes, not dots. Under Authentication, create a Credential List with a username and a long random password (Twilio requires at least 12 characters, a digit and mixed case). Also create an IP Access Control List with your VPS’s public IP. When both exist, Twilio enforces both.
  4. Origination tab (calls from the PSTN to you). Add the origination URI sip:pbx.example.com:5061;transport=tls. Twilio puts the dialed number in the user part for you, so Asterisk receives sip:+15555550100@pbx.example.com. Use sip with transport=tls; Twilio does not support the sips: scheme.
  5. Numbers tab. Buy a local number (Phone Numbers in the Console), then click Associate a Number with this Trunk and pick it. On the number’s own configuration page, the Voice section should show SIP Trunking with your trunk selected.

Generate the credential password on the server so it never touches a clipboard history on your laptop:

openssl rand -base64 24 | tr -d '/+='

Rerun it if the result has no digit or lacks either case.

Emergency address. On the trunk’s Numbers tab (or the number’s page), click Add emergency address and enter the street address where you will use this phone. The address has to match the national 911 street database (MSAG), which often differs from your postal address, so accept a suggested alternative if Twilio offers one. Then check the number’s Emergency Address Status says registered. On the office build, numbers attached to the trunk showed unregistered, and one showed a registration failure, so check every number rather than assuming. Twilio charges a $75 fee per 911 call from a number with no registered address, plus $0.75/month for each registered number. A softphone address is fixed: if you are traveling, 911 gets your home address. Use your cell phone for real emergencies.

Disaster Recovery URL (optional). On the General tab you can point the trunk at a TwiML Bin that forwards calls to your cell phone if Twilio cannot reach your server. Calls that take this path are billed at normal Programmable Voice rates.

Fraud controls, before you enable outbound:

  • Voice > Settings > Geo permissions: these apply to Elastic SIP Trunking too. Enable only United States/Canada, low-risk numbers. Several Caribbean countries share the +1 country code, so “+1” does not mean “domestic.” Twilio does not publish its high-risk ranges; use the permission check tool on that page if you need to test a number.
  • Billing and Usage > Usage and Spend > Usage Triggers: create a trigger that emails you when voice spend passes a small daily amount.
  • Billing: decide on auto-recharge. With it off, your prepaid balance is your ceiling. The cost of that ceiling: at zero balance Twilio suspends the whole account, inbound calls included.

Step 5: pjsip.conf

This file defines the transport (how Asterisk listens), the Twilio trunk and the softphone. Back up the sample and write a new one:

sudo mv /etc/asterisk/pjsip.conf /etc/asterisk/pjsip.conf.sample
sudo vim /etc/asterisk/pjsip.conf
; /etc/asterisk/pjsip.conf  (Asterisk 22, chan_pjsip)

[global]
type=global
user_agent=pbx                       ; do not advertise the Asterisk version

; ---------------------------------------------------------------- transport
[transport-tls]
type=transport
protocol=tls
bind=0.0.0.0:5061
cert_file=/etc/asterisk/keys/fullchain.pem
priv_key_file=/etc/asterisk/keys/privkey.pem
method=tlsv1_2                       ; TLS 1.2 exactly; Twilio accepts 1.2 and above
verify_server=yes                    ; check Twilio's certificate when we connect out
allow_wildcard_certs=yes             ; Twilio presents a wildcard certificate; without this, verification fails
ca_list_file=/etc/ssl/certs/ca-certificates.crt
; Behind NAT instead of on a public VPS? Add:
;external_signaling_address=<PUBLIC_IP>
;external_media_address=<PUBLIC_IP>
;local_net=192.168.1.0/24

; ---------------------------------------------------------------- Twilio trunk
[twilio]
type=endpoint
transport=transport-tls
context=from-twilio                  ; inbound calls land here and nowhere else
disallow=all
allow=ulaw
aors=twilio
outbound_auth=twilio-auth            ; answers Twilio's 407 challenge on our INVITEs
identify_by=ip                       ; Twilio is recognized by source address only
direct_media=no                      ; media always flows through Asterisk
media_encryption=sdes                ; SRTP, keys carried in the SDP (so keep signaling on TLS)
media_encryption_optimistic=no       ; refuse the call rather than fall back to plain RTP
dtmf_mode=rfc4733                    ; Twilio sends keypresses as RFC 2833/4733 events
send_pai=yes                         ; also send caller ID in P-Asserted-Identity
rtp_timeout=60                       ; hang up a call whose media has been dead for 60 s
; Do NOT set callerid= here: it would replace every caller's number.

[twilio]
type=aor
contact=sip:<YOUR_TRUNK>.pstn.twilio.com:5061;transport=tls
qualify_frequency=60                 ; OPTIONS ping; Twilio asks for no more than one per 10-15 s

[twilio-auth]
type=auth
auth_type=digest
username=<TWILIO_CREDENTIAL_USERNAME>
password=<TWILIO_CREDENTIAL_PASSWORD>

[twilio-identify]
type=identify
endpoint=twilio
match=54.172.60.0/30,54.244.51.0/30,54.171.127.192/30,35.156.191.128/30
match=54.65.63.192/30,54.169.127.128/30,54.252.254.64/30,177.71.206.192/30

; ---------------------------------------------------------------- softphone
[softphone]
type=endpoint
transport=transport-tls
context=from-softphone
disallow=all
allow=ulaw
aors=softphone
auth=softphone-auth
direct_media=no
media_encryption=sdes
rtp_symmetric=yes                    ; send media back to where it actually comes from
force_rport=yes                      ; reply to the source port, not the one in Via
rewrite_contact=yes                  ; store the NAT's public address as the contact
mailboxes=100@default                ; message-waiting light on the softphone

[softphone]
type=aor
max_contacts=1
remove_existing=yes
qualify_frequency=30

[softphone-auth]
type=auth
auth_type=digest
username=softphone
password=<LONG_RANDOM_PASSWORD>

Notes on the choices:

  • auth_type=digest. Most older guides say userpass. In Asterisk 22 userpass is deprecated and converted to digest.
  • How Asterisk decides who is calling. For each request, Asterisk tries identifiers in order ip, then username. A packet from a Twilio range matches twilio-identify and lands in from-twilio. Your softphone, coming from your home IP, is matched by the username in its From header and must pass the password check. Anything else gets rejected with no matching endpoint. Twilio’s own troubleshooting page says a 401 or 407 sent back to Twilio on inbound calls means the PBX does not recognize Twilio’s addresses; this identify section is the fix.
  • The NAT trio (rtp_symmetric, force_rport, rewrite_contact) belongs on the softphone because it sits behind your home router. Twilio does not need it. direct_media=no matters on both: with direct media, Asterisk would try to make the two ends send audio straight to each other, which fails between Twilio and a laptop behind NAT.
  • verify_server=yes and allow_wildcard_certs=yes. Twilio says your side must trust its certificate authority; its CA bundle lists DigiCert root certificates that are also in Debian’s system store. Twilio’s servers present a wildcard certificate (a *. name that covers the per-customer trunk hostnames), and PJSIP rejects wildcards by default, citing RFC 5922. Twilio’s own docs quote that log line and say calls still work, but only because verification is off by default. With verify_server=yes and no allow_wildcard_certs=yes, every outbound connection to Twilio fails the name check. If outbound calls still fail at the TLS handshake, read the console warning before you touch these settings. Turning verification off lets anyone in the network path impersonate Twilio.

Apply it:

sudo chown root:asterisk /etc/asterisk/pjsip.conf && sudo chmod 640 /etc/asterisk/pjsip.conf
sudo systemctl restart asterisk
sudo asterisk -rx 'pjsip show transports'
sudo asterisk -rx 'pjsip show endpoints'

twilio should show Avail within a minute once the qualify ping gets an answer. Use a restart here, not a reload. Transport settings other than the certificate are not reloadable. On the office build a reload also failed silently: one option placed in the wrong section made every pjsip reload fail, Asterisk kept running the old config, and only a full restart printed the error. If a change “doesn’t take,” restart and read the startup output.

Step 6: rtp.conf

sudo vim /etc/asterisk/rtp.conf
[general]
rtpstart=10000        ; must match the UDP range open in nftables
rtpend=20000
strictrtp=yes         ; default; drop media from anyone but the negotiated source
sudo chown root:asterisk /etc/asterisk/rtp.conf && sudo chmod 640 /etc/asterisk/rtp.conf
sudo asterisk -rx 'module reload res_rtp_asterisk.so'

Step 7: voicemail.conf and email delivery

Asterisk emails voicemail by piping a message to /usr/sbin/sendmail -t. Debian has no mail transfer agent by default, and you do not want to run a full mail server on a phone box. msmtp-mta provides a sendmail that relays through an account you already have (any provider with SMTP submission on port 587 and an app password):

sudo apt install -y msmtp-mta
sudo vim /etc/msmtprc
defaults
auth           on
tls            on
tls_trust_file system
syslog         on

account        relay
host           <SMTP_HOST>
port           587
from           pbx@example.com
user           <SMTP_USERNAME>
password       <SMTP_APP_PASSWORD>

account default : relay
sudo chown root:asterisk /etc/msmtprc && sudo chmod 640 /etc/msmtprc
printf 'Subject: pbx test\n\nhello\n' | sudo -u asterisk /usr/sbin/sendmail -t you@example.com

Set from here and serveremail below to an address your provider lets this account send as, or it may reject the mail. The file holds a password, so only root and the asterisk group can read it. Use an app-specific password that can only send mail, never your main account password. If the test mail does not arrive, journalctl -t msmtp shows why.

Now the mailbox:

sudo mv /etc/asterisk/voicemail.conf /etc/asterisk/voicemail.conf.sample
sudo vim /etc/asterisk/voicemail.conf
[general]
format=wav                         ; 16-bit 8 kHz PCM: plays on every phone and laptop
attach=yes                         ; attach the recording to the email
serveremail=pbx@example.com
fromstring=Dev Office PBX
emailsubject=New voicemail from ${VM_CALLERID}
emailbody=${VM_DUR} long message from ${VM_CALLERID} on ${VM_DATE}.\n
mailcmd=/usr/sbin/sendmail -t
maxsecs=180                        ; longest message, in seconds
minsecs=2                          ; discard messages shorter than 2 seconds
maxgreet=60
maxlogins=3

[zonemessages]
eastern=America/New_York|'vm-received' Q 'digits/at' IMp

[default]
; mailbox => PIN,name,email,pager,options
100 => <4_TO_8_DIGIT_PIN>,Your Name,you@example.com,,tz=eastern|attach=yes
; add |delete=yes to the options to remove messages from the server once emailed
sudo chown root:asterisk /etc/asterisk/voicemail.conf && sudo chmod 660 /etc/asterisk/voicemail.conf
sudo asterisk -rx 'module reload app_voicemail.so'

Mode 660 lets Asterisk save your PIN when you change it from the phone. A minute of voicemail is about 960 KB.

Step 8: extensions.conf, the dialplan

The dialplan is where Asterisk decides what happens to a call. It is split into contexts (the names in brackets), and an endpoint can only reach extensions in its own context and whatever that context jumps to. That property is your main defense against toll fraud: the Twilio endpoint lands in from-twilio, and nothing reachable from there can dial out.

sudo mv /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.sample
sudo vim /etc/asterisk/extensions.conf
[general]
static=yes
writeprotect=yes            ; "dialplan save" cannot overwrite this file

; ================================================================ inbound
[from-twilio]
; Twilio sends the dialed number, in E.164, as the extension.
exten => +15555550100,1,NoOp(Inbound from ${CALLERID(num)} ${CALLERID(name)})
 same => n,Gosub(sub-callername,s,1)
 same => n,Answer()
 same => n,GotoIfTime(09:00-17:00,mon-fri,*,*,America/New_York?ivr,s,1)
 same => n,Goto(after-hours,s,1)

[ivr]
exten => s,1,Set(TIMEOUT(digit)=3)
 same => n(menu),Background(custom/main-menu)   ; plays while listening for a key
 same => n,WaitExten(5)
exten => 1,1,Goto(ring-me,s,1)                  ; 1: talk to me
exten => 2,1,Playback(custom/about-me)          ; 2: a short pitch about you
 same => n,Goto(s,menu)
exten => 3,1,Goto(leave-message,s,1)            ; 3: straight to voicemail
exten => i,1,Playback(pbx-invalid)              ; key that is not on the menu
 same => n,Goto(s,menu)
exten => t,1,Goto(ring-me,s,1)                  ; no key pressed: try to reach me

[ring-me]
exten => s,1,Dial(PJSIP/softphone,25)
 same => n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy)
 same => n,VoiceMail(100@default,u)             ; unavailable greeting
 same => n,Hangup()
 same => n(busy),VoiceMail(100@default,b)       ; busy greeting
 same => n,Hangup()

[leave-message]
exten => s,1,VoiceMail(100@default,u)
 same => n,Hangup()

[after-hours]
exten => s,1,Playback(custom/after-hours)
 same => n,VoiceMail(100@default,s)             ; s: skip the "leave a message" instructions
 same => n,Hangup()

[sub-callername]
; Replace the caller's name with your own label if you know the number.
exten => s,1,GotoIf(${DB_EXISTS(contacts/${CALLERID(num)})}?known)
 same => n,Return()
 same => n(known),Set(CALLERID(name)=${DB_RESULT})
 same => n,Return()

; ================================================================ from the softphone
[from-softphone]
exten => *97,1,VoiceMailMain(100@default)       ; check voicemail, record greetings
 same => n,Hangup()

exten => 911,1,Goto(outbound,911,1)
exten => 933,1,Goto(outbound,933,1)             ; Twilio's 911 address test line

; Normalize North American numbers to E.164. Anything else matches nothing (404).
exten => _NXXNXXXXXX,1,Goto(outbound,+1${EXTEN},1)
exten => _1NXXNXXXXXX,1,Goto(outbound,+${EXTEN},1)
exten => _+1NXXNXXXXXX,1,Goto(outbound,${EXTEN},1)

[outbound]
exten => _+1NXXNXXXXXX,1,GotoIf($["${EXTEN:2:3}" = "900"]?blocked,1)   ; premium-rate
 same => n,Set(CALLERID(num)=+15555550100)
 same => n,Set(CALLERID(name)=Dev Office)
 same => n,Dial(PJSIP/${EXTEN}@twilio)
 same => n,Hangup()

exten => 911,1,Set(CALLERID(num)=+15555550100)  ; must be the number with the registered address
 same => n,Dial(PJSIP/911@twilio)
 same => n,Hangup()
exten => 933,1,Set(CALLERID(num)=+15555550100)
 same => n,Dial(PJSIP/933@twilio)
 same => n,Hangup()

exten => blocked,1,Playback(pbx-invalid)
 same => n,Hangup()

Replace +15555550100 everywhere with your Twilio number and America/New_York with your time zone, then load it:

sudo chown root:asterisk /etc/asterisk/extensions.conf && sudo chmod 640 /etc/asterisk/extensions.conf
sudo asterisk -rx 'dialplan reload'
sudo asterisk -rx 'dialplan show from-twilio'

How to read it:

  • Pattern matching. An extension starting with _ is a pattern. N is any digit 2-9, X any digit 0-9. _NXXNXXXXXX is a 10-digit North American number. In North America, area codes and exchanges never start with 0 or 1, which is what N enforces.
  • E.164 normalization. You can dial 5555550111, 15555550111 or +15555550111 and all three leave as +15555550111, which is the only format Twilio accepts (anything else gets 400 Bad Request). International numbers do not match any pattern, so the softphone gets 404 Not Found and nothing reaches Twilio.
  • Background vs Playback. Background plays a file while listening for keypresses; WaitExten waits a few more seconds after it ends. A keypress jumps to the matching extension in the same context. i handles invalid keys and t handles silence.
  • GotoIfTime. Arguments are times, weekdays, days of month, months and an optional time zone. Without the time zone it uses the server’s clock, which on a VPS is usually UTC.
  • Caller ID out. Twilio rejects calls whose From number is not a Twilio number on your account or a verified caller ID. Setting CALLERID(num) puts your Twilio number in From, and send_pai=yes copies it to P-Asserted-Identity.
  • Emergency calls. Twilio expects the Request-URI sip:911@<your-trunk>.pstn.twilio.com and a From number that has a registered emergency address. Dial 933 once to hear your number and address read back.

Step 9: record your prompts

You need four recordings: main-menu (“You’ve reached the dev office of … press 1 to talk to me, 2 to hear what I build, 3 to leave a message”), about-me, after-hours and your voicemail greeting.

The quick way: record from the softphone. Dial *97, enter your PIN, press 0 for mailbox options, then 1 to record the unavailable greeting or 2 for the busy greeting. This saves the voicemail greetings into the mailbox for you.

The good way: record on your laptop, convert, upload. Asterisk plays .wav files only if they are PCM, 16-bit, mono, 8 kHz (or 16 kHz with the .wav16 extension), with a lowercase .wav extension. Record each prompt in any app, then convert on your laptop with ffmpeg:

ffmpeg -i main-menu.m4a -ar 8000 -ac 1 -c:a pcm_s16le -map_metadata -1 main-menu.wav

Or with sox, starting from a WAV recording:

sox main-menu-raw.wav -r 8000 -c 1 -b 16 -e signed-integer main-menu.wav norm -3

norm -3 normalizes the level to 3 dB below full scale, so quiet laptop recordings are not quieter still on a phone. If you prefer, ffmpeg can also write raw μ-law (ffmpeg -i main-menu.m4a -ar 8000 -ac 1 -f mulaw main-menu.ulaw; keep -ar 8000 -ac 1, because a raw file has no header to tell Asterisk the rate), which matches the codec on the wire and needs no conversion at call time; upload .ulaw files the same way. I ran both ffmpeg variants on a test file and checked the output: mono, 16-bit, 8000 Hz for the .wav, and exactly one byte per sample for the .ulaw.

Copy the files up from your laptop:

scp main-menu.wav about-me.wav after-hours.wav unavail.wav <USER>@pbx.example.com:/tmp/

Then install them on the server:

sudo install -d -o asterisk -g asterisk /var/lib/asterisk/sounds/custom
sudo install -o asterisk -g asterisk -m 640 /tmp/main-menu.wav /tmp/about-me.wav /tmp/after-hours.wav /var/lib/asterisk/sounds/custom/
sudo install -d -o asterisk -g asterisk /var/spool/asterisk/voicemail/default/100
sudo install -o asterisk -g asterisk -m 640 /tmp/unavail.wav /var/spool/asterisk/voicemail/default/100/unavail.wav

In the dialplan you refer to prompts without the extension (custom/main-menu); Asterisk picks the best format it finds. The voicemail greetings live in the mailbox directory as unavail, busy and temp. A temp greeting, if it exists, plays instead of the others, which is handy for “I’m at a conference this week.”

I would keep the menu under 20 seconds. Callers who hear “press 2 to hear what I build” will press 2, so make that recording worth the press.

Step 10: the softphone

Two free softphones that support TLS and SRTP and are actively maintained:

  • MicroSIP (Windows, GPL v2). Version 3.23.6 was released November 17, 2026.
  • Linphone (Windows, macOS, Linux, Android, iOS, open source). Linphone 6.2, which covers the desktop and mobile apps, was released in July 2026.

MicroSIP, Account settings:

Field Value
SIP server pbx.example.com:5061
SIP proxy empty
Username softphone
Domain pbx.example.com
Login empty (uses Username)
Password the password from softphone-auth
Display name anything
Transport TLS
Media encryption Mandatory SRTP
Public address, ICE empty / off

Linphone: choose the Third-Party SIP Account option on the start screen. Enter username softphone, the password, domain pbx.example.com:5061, and set transport to TLS. Then find the media encryption setting in the call settings and set it to SRTP. The exact menu has moved between Linphone versions, so I won’t promise a path. Linphone warns that some of its features, such as group chat, need a Linphone account; calling does not.

After saving, check on the server:

sudo asterisk -rx 'pjsip show contacts'

You should see a contact line starting with softphone/sip:softphone@ followed by your home IP and port, with status Avail. Call your Twilio number from your cell phone. You should hear the menu, press 1, and the softphone rings.

Debugging: reading what Asterisk tells you

Open a live console with:

sudo asterisk -rvvv

Each v raises the verbosity. Type commands at the *CLI> prompt and exit to leave (Asterisk keeps running). Do not paste two commands into the console at once. They run interleaved with scrolling log output and you lose track of what ran. For anything multi-step, run one command per shell call with asterisk -rx:

sudo asterisk -rx 'pjsip show endpoints'
sudo asterisk -rx 'core show channels'

The commands I use most:

  • pjsip show endpoints: every endpoint, its contacts and whether they answer qualify pings.
  • pjsip show contacts: where each registered device actually is.
  • core show channels: calls in progress right now.
  • pjsip set logger on / off: print every SIP message. pjsip set logger host 203.0.113.50 limits it to one address.
  • rtp set debug on: print every media packet. Very noisy, but it is the fastest way to see one-way audio.

Reading a SIP trace

With the logger on, an inbound call starts like this (trimmed, example values):

<--- Received SIP request (1342 bytes) from TLS:54.172.60.1:41234 --->
INVITE sip:+15555550100@pbx.example.com:5061;transport=tls SIP/2.0
Via: SIP/2.0/TLS 54.172.60.1:5061;branch=z9hG4bK...
From: "+15555550111" <sip:+15555550111@example-dev-office.pstn.twilio.com>;tag=...
To: <sip:+15555550100@pbx.example.com>
Contact: <sip:+15555550111@54.172.60.1:5061;transport=tls>
...
c=IN IP4 168.86.130.20
m=audio 18562 RTP/SAVP 0 101
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:...
a=rtpmap:101 telephone-event/8000

The Request-URI user (+15555550100) is the extension Asterisk looks up in from-twilio. From carries the caller’s number and, if you enable the lookup, their name. In the SDP, c= and m= say where to send audio, RTP/SAVP plus the a=crypto line mean SRTP, payload 0 is PCMU and 101 is the DTMF event stream. When you debug one-way audio, the c= line in each direction is the first thing to read: if it ever holds a private address (10.x, 172.16-31.x, 192.168.x) on a message going to the internet, the far end is sending audio into the void.

401, 407 and 403

  • 401 Unauthorized comes from a server that wants credentials (WWW-Authenticate header). Asterisk sends it to your softphone on every first REGISTER; that is normal. A second 401 after the softphone answered the challenge means a wrong password.
  • 407 Proxy Authentication Required is the same idea from a proxy (Proxy-Authenticate). Twilio challenges your outbound INVITEs with 407 when a credential list is configured, and Asterisk answers it using outbound_auth. If Twilio is sending calls to you and you answer 401 or 407, Asterisk did not recognize Twilio’s address: check identify.
  • 403 Forbidden means “I know who you are, and no.” Twilio’s docs say a 403 on the first INVITE usually means your IP is not in the trunk’s ACL, and a 403 after a 407 challenge means bad credentials. A 403 can also mean the From number is not yours.

The field note here: on the office build, outbound calls from the production server failed with 407 while an identical test server worked. Twilio’s docs would lead you to expect a 403 for an address outside the ACL, and the credentials were correct. The firewall had two internet connections and picked the outbound one by hashing source and destination, so the production box left through the address that was not in Twilio’s ACL. The clue was in Twilio’s 100 Trying: the received= parameter on the Via header showed the address Twilio actually saw. When an auth error makes no sense, compare received= with the IP you put in the ACL before you touch a password.

One-way audio

On this design the server has a public IP, so one-way audio almost always comes from the softphone side:

  1. rtp set debug on, make a call, and look for packets in both directions. If you see Sent RTP packet to lines for the softphone’s address but no Got RTP packet from lines, its media is not arriving. (The real output has two spaces after Got, which matters if you grep for it.)
  2. Confirm rtp_symmetric=yes on the softphone endpoint, so Asterisk answers to where packets come from instead of the private address in the softphone’s SDP.
  3. Check the UDP range is open: sudo nft list chain inet filter input.
  4. If you moved Asterisk behind NAT, set external_media_address, external_signaling_address and local_net on the transport and forward the UDP range. Twilio’s troubleshooting page describes the classic case: the PBX puts its LAN address in the SDP, so the PSTN caller hears you but you never hear them.

Number format mismatches

One call carries numbers in the Request-URI, To, From, P-Asserted-Identity and sometimes Diversion, each possibly in a different format. A mismatch shows up as:

... Call (TLS:54.172.60.1:41234) to extension '+15555550100' rejected because extension not found in context 'from-twilio'.

Asterisk answers that with a 404, and the caller hears a failure message from Twilio. Compare the extension in the log character by character with dialplan show from-twilio. If Asterisk answers 484 Address Incomplete, the number partly matches a pattern, which usually means a digit is missing.

Both directions bit me on the office build. An early outbound test left the PBX as eleven digits without the +, matched nothing in Asterisk’s outbound pattern, and failed before reaching Twilio. Inbound, the PBX behind Asterisk wanted numbers without +1, so I stripped them from the Request-URI, and the Diversion header still carried the +1 form: the same call presented two different numbers to the next hop. When you normalize, look at every header that carries a number.

Security

Expect a SIP port on a public IP to be scanned. The people scanning are after toll fraud: making expensive international calls on your account. Every layer below exists for that.

Trunk traffic only from Twilio. Asterisk only treats a request as Twilio if it comes from a Twilio signaling range, and that endpoint can only reach from-twilio. On Twilio’s side, outbound calls need both your server’s IP and the credential list.

Strong softphone credentials. Use a long random password (the openssl command from Step 4 works). The username is not a secret; the password does all the work.

Rate limiting and fail2ban. nftables already drops sources opening more than 10 new connections per minute to 5061. fail2ban bans addresses that fail authentication. Install it and add a jail:

sudo apt install -y fail2ban
sudo vim /etc/fail2ban/jail.d/asterisk.local
[asterisk]
enabled  = true
backend  = auto
logpath  = /var/log/asterisk/messages.log
           /var/log/asterisk/security.log
maxretry = 5
findtime = 10m
bantime  = 1d
action   = nftables[type=allports, name=asterisk]
sudo systemctl restart fail2ban
sudo fail2ban-client status asterisk

Three details in that file are easy to miss. fail2ban’s stock jail points at /var/log/asterisk/messages, but Asterisk 22’s sample logger.conf writes messages.log, so the stock jail watches a file that never exists. backend = auto makes fail2ban read files; a journal backend would see nothing, because the Asterisk unit sends its output to /dev/null. And the security log is cheap insurance. If you ever add auth_username to PJSIP’s endpoint_identifier_order, Asterisk batches unknown-endpoint attempts into a line ending No matching endpoint found after 5 tries in 4.120 ms, and the stock filter’s regex does not match that variant. The InvalidAccountID event in the security log covers it either way. I tested the fail2ban 1.1.0 filter against log lines in the exact format Asterisk 22 writes: the plain “No matching endpoint found” and “Failed to authenticate” lines matched, the “after N tries” line did not, and the security log events did. The PJSIP “extension not found” line for a misrouted Twilio call does not match, so a dialplan mistake will not get Twilio banned.

allports means a banned address loses SSH too. Five wrong softphone passwords from home in ten minutes lock your home IP out of the server for a day. If your home address is static, add ignoreip = 127.0.0.1/8 ::1 <YOUR_HOME_IP> to the jail; otherwise keep your VPS provider’s web console handy and run sudo fail2ban-client set asterisk unbanip <IP> from it.

fail2ban puts its bans in its own nftables table. If you later run systemctl restart nftables, the flush ruleset at the top of your config removes that table too, so restart fail2ban afterward.

What probing looks like. In /var/log/asterisk/messages.log:

[Dec  1 10:00:01] NOTICE[2211] res_pjsip/pjsip_distributor.c: Request 'REGISTER' from '<sip:100@203.0.113.10>' failed for '198.51.100.24:5070' (callid: ...) - No matching endpoint found
[Dec  1 10:00:02] NOTICE[2211] res_pjsip/pjsip_distributor.c: Request 'REGISTER' from '<sip:softphone@203.0.113.10>' failed for '198.51.100.23:51234' (callid: ...) - Failed to authenticate

The first is someone guessing extension numbers. The second is someone who knows your username and is guessing the password; if that address is not yours, your password is the only thing between them and your Twilio balance. Nothing listens on UDP 5060, the default SIP port, so that traffic dies at the firewall.

Or keep registration off the internet. If you never want 5061 open to the world, run a WireGuard tunnel from your laptop to the VPS and register the softphone over it. In nftables, delete the last two 5061 rules, then accept WireGuard’s UDP port and iifname "wg0" tcp dport 5061. Twilio still reaches 5061 through its own allow rule. WireGuard Tunnel: Connecting Your Home Network to AWS covers the WireGuard side. The tunnel address is not in your certificate, so keep using pbx.example.com in the softphone and make it resolve to the tunnel address on your laptop (an /etc/hosts entry does it). The cost: the softphone only works while the tunnel is up.

Dialplan limits. Only North American patterns exist in from-softphone, 900 numbers are blocked, and Twilio’s geo permissions only allow United States/Canada. For destinations outside +1, two independent layers have to fail before a call goes out. For the Caribbean countries inside +1 (Jamaica’s 876, the Dominican Republic’s 809, and so on), the dialplan pattern matches and geo permissions are the only block. Add a GotoIf for those area codes in [outbound] if you want a second layer there too.

Check what is listening:

sudo ss -lntup

You should see Asterisk on TCP 5061 and SSH on 22. Anything else listening on a public address deserves a second look, even though the firewall drops it.

Caller ID: number vs name

Two separate things travel with a call, and people use “caller ID” for both:

  • ANI / calling number: the digits. It arrives in the SIP From header. Asterisk puts it in CALLERID(num).
  • CNAM (Caller ID Name): the name. It is not sent by the caller’s carrier at all. The receiving side looks the number up in a CNAM database.

Seeing names on inbound calls. On the trunk’s Origination tab, turn on CNAM Lookup. Twilio then looks up each US or Canadian caller and puts the name in the From, Contact and P-Asserted-Identity headers, which Asterisk shows as CALLERID(name). Twilio bills per lookup even when no name is found; its published caller name rate is $0.01 per request at the time of writing. Many mobile numbers have no CNAM entry, so expect a lot of calls to show only a number or a city.

Your own contacts beat any database. The sub-callername routine in the dialplan checks Asterisk’s built-in key-value store (AstDB) and overrides the name when you know the number:

sudo asterisk -rx 'database put contacts +15555550111 "Recruiter Example Co"'
sudo asterisk -rx 'database show contacts'

Keys are E.164, because that is how Twilio delivers CALLERID(num). The database lives in /var/lib/asterisk/astdb.sqlite3 and survives restarts.

Your name on outbound calls. Set(CALLERID(name)=Dev Office) does not put your name on the other person’s screen. US carriers display what the CNAM database says for your number, so you register it. Twilio’s CNAM registration (Trust Hub > Registrations > CNAM) is free, allows 15 characters (letters, digits, periods, commas and spaces, starting with a letter), and takes 48 to 72 hours to spread after approval. It requires a Business Profile tied to an EIN or DUNS number, and only works for US local numbers. Landlines show CNAM by default; on most US mobile carriers the person you call has to opt in.

Attestation and spam labels. STIR/SHAKEN is the system US carriers use to sign calls with how confident the originating carrier is that you own the number you are showing: A (full), B (partial) or C (gateway). Twilio signs with C if you have no approved Business Profile and SHAKEN/STIR Trust Product, B with an approved primary Business Profile and Trust Product, and A only for numbers assigned to both. Twilio’s documentation describes this path in terms of a Business Profile; if you are an individual, check in Trust Hub what your profile type qualifies for. Low attestation is one input carrier analytics use when they label calls “Spam Likely.” Twilio’s Voice Integrity product registers your numbers with the analytics providers for AT&T, T-Mobile and Verizon. For a number you mostly receive calls on, none of this matters much; it matters the day you call a hiring manager back.

Moving an existing number to Twilio

Porting (moving) a number you already have takes days and has rules. From Twilio’s porting guidelines:

  • What you submit. The name and service address exactly as the current carrier has them on its Customer Service Record (CSR), your account number with that carrier, a PIN if they use one, and a phone bill from the last 30 days. In Twilio’s current port-in flow, Twilio generates the Letter of Authorization (LOA) from the details you enter, and the authorized person has 30 days to sign it. Start at Phone Numbers > Port & Host in the Console.
  • Mobile numbers need the account number and usually a port-out PIN, which you request from the mobile carrier. Porting your cell number moves it off your phone: your mobile plan loses that number.
  • Timing. Twilio quotes 5 to 15 days for standard ports, up to 4 weeks or more if the losing carrier rejects the request. Twilio emails you the port date.
  • Keep the old service running until the port completes. Twilio’s instructions are explicit: do not close the old account while the request is in progress.
  • Configure before the date. Associate the number with the trunk and add its extension to from-twilio before the port date. Calls start arriving at Twilio the moment the port completes.

Field notes from porting an office’s numbers:

  • Copy the CSR character for character. The most common rejection is a name or address that does not match, and “Suite 100” vs “Ste 100” counts.
  • Port in waves, low-risk numbers first. The first wave shows you how your losing carrier behaves, and a mistake costs a few numbers instead of all of them.
  • Confirm a number actually moved before you debug routing. During the migration, calls that reached the new system before its route for that number existed got a 404, and a number that has not finished porting never reaches your server at all. Both look like routing faults. Check the port status in the Console, then call the number from outside with pjsip set logger on. No INVITE in the log means the call is not reaching your server: the number is still at the old carrier, is not on your trunk, or the origination URI or firewall is wrong. Dialplan edits fix none of those.
  • There is no fallback after a port. Once the number lives at Twilio, the old carrier no longer routes it anywhere. If your server is down, callers get an error unless you set the trunk’s Disaster Recovery URL.

If the number gets texts, Twilio’s messaging on US local numbers requires A2P 10DLC registration, which is a separate process from everything here.

What it costs

A light month: 200 minutes of inbound calls, 100 minutes of outbound calls to the lower 48 states, 50 inbound calls with name lookup. US prices from Twilio’s Elastic SIP Trunking and Lookup pricing pages at the time of writing, before taxes and fees:

Item Rate Usage Monthly
Local phone number $1.15/month 1 $1.15
Inbound (origination), local $0.0034/min 200 min $0.68
Outbound (termination), 48 states $0.0100/min 100 min $1.00
Emergency address on the number $0.75/month 1 $0.75
Inbound CNAM lookup $0.01/lookup 50 $0.50
Twilio subtotal $4.08
VPS (DigitalOcean Basic, 1 GiB) $6.00/month 1 $6.00
Total $10.08

Secure trunking is included at no extra charge. Toll-free numbers cost $2.15/month and $0.013/min inbound if you want one. Prices change; check Twilio’s US SIP trunking pricing and your own usage page before you trust this table.

Sources and further reading