If you need to connect a few SIP devices in a local network, or via the internet without using a commercial SIP server, you can do it on a small VPS, Raspberry Pi. (I suppose you already have VPS or Raspberry Pi and know how to use command line)
Step 1. Install
1 2
sudo apt update sudo apt install asterisk
Check that asterisks started (You should see “active (running)”)
[transport-udp] type=transport protocol=udp bind=0.0.0.0:5060; you can change default port external_media_address=[ip address of VPS] external_signaling_address=[ip address of VPS] local_net=192.168.0.0/16;optional local_net=10.0.0.0/8;optional
; ----- User 1 ----- [1001] type=endpoint context=internal disallow=all allow=ulaw auth=1001 aors=1001 direct_media=no; Force RTP through Asterisk rtp_symmetric=yes; Important for NAT force_rport=yes; Important for NAT rewrite_contact=yes; Important for NAT
; ----- User 2 ----- [1002] type=endpoint context=internal disallow=all allow=ulaw auth=1002 aors=1002 direct_media=no; Force RTP through Asterisk rtp_symmetric=yes; Important for NAT force_rport=yes; Important for NAT rewrite_contact=yes; Important for NAT media_encryption=sdes ; Enable SRTP for encrypted audio, which can be not supported on old devices, set no for old devices or apps. Or sdes, or dtls, or srtp
[1002] type=auth auth_type=userpass password=strongpassword2 username=1002 ;realm=[your domain] ; in some cases if you set defaul-realm you need to set the same for all clients
RTP Media Ports (Optional) You can reduce numbers of ports for RTP in /etc/asterisk/rtp.conf
1 2 3
[general] rtpstart=10000 rtpend=20000
Check logs
1
sudo asterisk -rvvv
On my old Ubuntu server, I needed additional changes for using PJSIP instead of chan_sip (the legacy SIP channel driver). Without these changes, settings from above will not work (because settings for chan_sip should be placed in /etc/asterisk/sip.conf instead).
Config of Load PJSIP Module in /etc/asterisk/modules.conf update list of modules for loading:
[global] max_forwards=70 user_agent=Asterisk PBX default_realm=[your domain or asterisk]
; UDP Transport (keep for backward compatibility) [transport-udp] ....
; TLS Transport (secure) [transport-tls] type=transport protocol=tls bind=0.0.0.0:5061 cert_file=/etc/letsencrypt/live/[your domain]/fullchain.pem priv_key_file=/etc/letsencrypt/live/[your domain]/privkey.pem ; OR for self-signed: ; cert_file=/etc/asterisk/keys/asterisk.combined.pem ; priv_key_file=/etc/asterisk/keys/asterisk.combined.pem ;cipher=ALL ; use only if you know which format is supported method=sslv23 ; or tlsv1_2 for modern devices verify_server=no verify_client=no external_media_address=[server ip] external_signaling_address=[server ip]
; Update endpoints to use TLS [1001] type=endpoint context=internal ;transport=transport-tls ;optional to force use TLS disallow=all allow=ulaw allow=alaw auth=1001 aors=1001 direct_media=no rtp_symmetric=yes force_rport=yes rewrite_contact=yes media_encryption=sdes ; Enable SRTP for encrypted audio, which can be not supported on old devices, set no for old devices or apps. Or sdes, or dtls
[1001] type=auth auth_type=userpass password=YourStrongPassword username=1001 ;realm=[your domain] ; in some cases if you set defaul-realm you need to set the same for all clients