SIP B2BUA with Asterisk in Docker, where the upstream SIP trunk is only reached through WireGuard.
Call path:
PBX -> Asterisk (this container) -> real SIP trunk
Asterisk handles:
- SIP trunk authentication
- SIP signaling and RTP anchoring
- header handling (including
P-Asserted-Identity)
The real SIP trunk sees the public IP of your WireGuard egress peer.
- A Docker image with WireGuard and Asterisk
- A startup script that:
- brings up
wg0 - auto-creates
pjsip.confandextensions.conffrom sample files if needed - starts Asterisk in foreground
- brings up
- sample configs for:
- PJSIP trunking (
config/asterisk:/pjsip.sample.conf) - dialplan routing (
config/asterisk:/extensions.sample.conf) - WireGuard (
config/wireguard/wg0.sample.conf)
- PJSIP trunking (
- Copy and edit:
config/asterisk:/pjsip.sample.conf->config/asterisk:/pjsip.confconfig/asterisk:/extensions.sample.conf->config/asterisk:/extensions.conf
- In
pjsip.conf, set these placeholders:YOUR_PBX_IPYOUR_PBX_TRUNK_USERYOUR_PBX_TRUNK_PASSWORDREAL_TRUNK_FQDN_OR_IPREAL_TRUNK_USERNAMEREAL_TRUNK_PASSWORDREAL_TRUNK_IP_OR_SBC_IP
- Copy and edit:
config/wireguard/wg0.sample.conf->config/wireguard/wg0.conf
- Replace placeholders:
<CLOUD_PRIVATE_KEY><EGRESS_PEER_PUBLIC_KEY><EGRESS_PEER_PUBLIC_IP><REAL_TRUNK_SIGNALING_IP>/32<REAL_TRUNK_RTP_NET_CIDR>
Important: AllowedIPs must include the real trunk signaling and RTP destination ranges so traffic is forced through wg0.
docker compose up -d --buildLogs:
docker compose logs -f wireguard-sip-proxyOpen Asterisk CLI:
docker exec -it wireguard-sip-proxy asterisk -rvvvUseful checks:
pjsip show registrations
pjsip show endpoints
dialplan show from-pbx
dialplan show from-realtrunk
WireGuard and routes in container:
docker exec -it wireguard-sip-proxy sh -c "wg show && ip route"direct_media=nokeeps media anchored on Asterisk (B2BUA behavior)send_pai=yesandtrust_id_outbound=yesallow PAI forwarding- dialplan subroutine
add-paiforwards incomingP-Asserted-Identityor builds one from caller ID
If your provider requires strict identity format, adjust the add-pai context in extensions.conf.
- SIP: UDP 5060
- RTP: UDP 10000-10100
- This project currently uses only UDP SIP in the sample config.
- If your PBX and provider require TCP/TLS, add dedicated transports and endpoint settings in
pjsip.conf.