DEV Community

Moisi Trungu
Moisi Trungu

Posted on • Originally published at flixzone.icu

SIP 503 Service Unavailable — Carrier & Server-Side Fixes

SIP 503 Service Unavailable — Carrier & Server-Side Fixes

Learn how to diagnose and resolve SIP 503 errors in ViciDial and Asterisk production environments, with carrier-side and server-side remediation strategies

Prerequisites

Before implementing the fixes in this tutorial, ensure you have:

  • Root or sudo access to your ViciDial/Asterisk server
  • SSH terminal access to the production system
  • Basic understanding of SIP protocol and VoIP call flow
  • Access to /etc/asterisk/ configuration directory
  • MySQL/MariaDB access to the asterisk database
  • Asterisk CLI knowledge (asterisk -rx commands)
  • A working ViciDial installation (tested on 2.14+)
  • Network monitoring tools: tcpdump, tshark, or similar
  • Carrier/trunk documentation and support contact information

Understanding SIP 503 Service Unavailable

What Is a 503 Error?

A SIP 503 Service Unavailable response indicates that the server (or the route to it) is temporarily unable to handle the request. In ViciDial and Asterisk environments, this typically means:

  • Carrier side: The carrier's SIP infrastructure is overloaded, under maintenance, or rejecting calls
  • Server side: Your Asterisk instance is overloaded, channels are exhausted, or no available trunks exist
  • Routing side: The dial plan cannot find a valid route to the destination

The 503 is not a call rejection due to invalid credentials or blocked numbers—those are 401, 403, or 486. A 503 means "temporarily unavailable, try again later."

Common Causes in ViciDial

  1. Insufficient trunk channels on carrier connections
  2. Carrier API/service outage or maintenance window
  3. Max channels exceeded on the Asterisk server
  4. Codec mismatch between endpoints
  5. NAT/firewall blocking SIP responses
  6. DNS resolution failure for carrier SIP servers
  7. Asterisk resource exhaustion (memory, file descriptors, SIP slots)
  8. Load-balanced trunk pool misconfiguration (all trunks unavailable)
  9. Carrier rate-limit or threshold hit
  10. Bad SIP header or malformed request from ViciDial

Carrier-Side Diagnostics and Fixes

Step 1: Verify Carrier Trunk Configuration in ViciDial

Log into the ViciDial web admin panel and navigate to System Admin → Carriers.

# Query the carrier configuration directly
mysql -u root -p asterisk -e "
SELECT carrier_id, carrier_name, active, outbound_sip_ip, outbound_sip_port, 
       max_channels, carrier_protocol FROM vicidial_carrier_log 
WHERE active='Y' 
ORDER BY carrier_id;"
Enter fullscreen mode Exit fullscreen mode

Check the following fields:

  • carrier_name: Ensure the carrier is active and correctly named
  • outbound_sip_ip: Verify IP matches carrier documentation
  • outbound_sip_port: Default is 5060; some carriers use 5061 (TLS) or custom ports
  • max_channels: Should match carrier's license/plan (not 1 or 0)
  • carrier_protocol: Should be SIP for modern deployments

Step 2: Test Carrier Connectivity

# Perform basic connectivity test to carrier SIP server
# Replace CARRIER_IP and PORT with your carrier's details
timeout 5 nc -zv 203.0.113.50 5060

# For TLS (port 5061)
timeout 5 nc -zv 203.0.113.50 5061

# DNS resolution test
nslookup sip.carrier.example.com
dig sip.carrier.example.com +short
Enter fullscreen mode Exit fullscreen mode

If the connection times out or DNS fails, contact your carrier immediately. If connectivity is good, continue to step 3.

Step 3: Monitor Real-Time SIP Traffic

Use tcpdump to capture SIP traffic to the carrier:

# Capture SIP traffic to specific carrier IP (replace with actual IP)
tcpdump -i any -n 'host 203.0.113.50 and (port 5060 or port 5061)' -A -v | head -100

# Alternatively, use tshark for more detailed SIP analysis
tshark -i any -f 'host 203.0.113.50 and port 5060' -O SIP | head -50
Enter fullscreen mode Exit fullscreen mode

Look for:

  • INVITE messages sent (should see FROM/TO headers)
  • SIP/2.0 100 Trying (carrier acknowledges receipt)
  • SIP/2.0 503 Service Unavailable (where the failure occurs)
  • SIP/2.0 200 OK (successful calls, for comparison)

A 503 response without "100 Trying" suggests the carrier is rejecting at gateway level, not downstream.

Step 4: Check Carrier Account Status and Limits

Contact your carrier's technical support and request:

  1. Account/trunk status — Is the account active? Any blocks?
  2. Current channel utilization — Are you at max concurrent channels?
  3. Rate limits — CPS (calls per second) or PPS (packets per second) limits
  4. IP allowlist — Is your ViciDial server IP whitelisted?
  5. Maintenance windows — Any scheduled maintenance today?
  6. Recent changes — Any recent carrier-side configuration changes?

Step 5: Review ViciDial Trunk Configuration File

Check the SIP trunk definition:

# View the carrier-specific SIP context
grep -A 50 "carrier_" /etc/asterisk/sip-vicidial.conf | head -100
Enter fullscreen mode Exit fullscreen mode

Look for your carrier's SIP registration block. It should resemble:

[carrier_mycarrier]
type=peer
host=203.0.113.50
port=5060
username=youraccountid
secret=yoursecretkey
fromdomain=sip.carrier.example.com
fromuser=youraccountid
context=from-carrier
canreinvite=no
dtmfmode=rfc2833
disallow=all
allow=ulaw
allow=alaw
qualifyfreq=60
insecure=port,invite
nat=yes
register=>youraccountid:yoursecretkey@203.0.113.50:5060/youraccountid
Enter fullscreen mode Exit fullscreen mode

Critical checks:

  • username/secret: Match carrier account credentials
  • host/port: Match carrier's primary SIP server (not a secondary or failover)
  • register line: Must be present and correct; it registers your trunk with the carrier
  • allow codecs: Must match carrier's supported codecs (ulaw is safest)
  • nat=yes: Enable if your ViciDial server is behind NAT
  • insecure=port,invite: May be required by some carriers for IP-based auth

Step 6: Force Trunk Re-registration

After correcting configuration, force Asterisk to re-register with the carrier:

# Reload SIP configuration
asterisk -rx "sip reload"

# Unregister and re-register
asterisk -rx "sip unregister carrier_mycarrier"
sleep 2
asterisk -rx "sip register carrier_mycarrier"

# Verify registration status
asterisk -rx "sip show registry"
Enter fullscreen mode Exit fullscreen mode

Expected output from sip show registry:

Host                            dnsmgr Username       State       Reg.Expires ID
203.0.113.50:5060               N      youraccountid  Registered  60
Enter fullscreen mode Exit fullscreen mode

If the state is "Unregistered" or "Rejected," review the carrier credentials and contact support.

Step 7: Check Carrier-Specific Rate Limits

Some carriers enforce strict CPS (calls per second) or concurrent channel limits. Query your recent call volume:

# Check concurrent calls in the last hour
mysql -u root -p asterisk -e "
SELECT DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00') as hour,
       COUNT(*) as total_calls,
       SUM(IF(call_duration > 0, 1, 0)) as connected_calls,
       SUM(IF(call_duration = 0, 1, 0)) as failed_calls
FROM vicidial_log
WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
AND carrier_id = 'CARRIER_ID_HERE'
GROUP BY hour
ORDER BY hour DESC;"
Enter fullscreen mode Exit fullscreen mode

If you see a spike corresponding to 503 errors, you may have exceeded the carrier's threshold. Request higher limits or implement call-rate throttling.

Server-Side Diagnostics and Fixes

Step 1: Check Asterisk Channel Availability

# View current SIP channel status
asterisk -rx "sip show channels"

# Count active channels
asterisk -rx "sip show channels" | grep -c "sip:"

# View max channels setting
asterisk -rx "sip show settings" | grep -i "maxcallbitrate\|max"
Enter fullscreen mode Exit fullscreen mode

Check if channels are approaching the configured maximum:

# Query Asterisk config for max channels
grep -i "^maxchannels" /etc/asterisk/asterisk.conf

# Default is usually unlimited or 1000; for ViciDial, set explicitly
cat /etc/asterisk/asterisk.conf | grep -A 5 "\[options\]"
Enter fullscreen mode Exit fullscreen mode

Step 2: Monitor System Resources

A 503 often indicates resource exhaustion. Check:

# Memory usage
free -h

# CPU load
uptime

# Disk I/O
iostat -x 1 5

# File descriptors in use
lsof -p $(pgrep -f "asterisk -p") | wc -l

# Network connections by state
netstat -an | grep SIP | wc -l
netstat -an | grep ESTABLISHED | wc -l
Enter fullscreen mode Exit fullscreen mode

Critical thresholds:

  • Memory: If free memory < 500 MB, Asterisk may fail to allocate SIP slots
  • CPU: Load > 80% of cores indicates saturation
  • File descriptors: If approaching the system limit (usually 1024 or more), increase with ulimit -n
  • Network: If SIP connections > 5000, you may hit kernel limits

Step 3: Increase File Descriptor Limits

Edit the Asterisk systemd service or init script:

# For systemd-based systems (modern ViciDial)
cat > /etc/systemd/system/asterisk.service.d/limits.conf << 'EOF'
[Service]
LimitNOFILE=65536
LimitNPROC=65536
EOF

systemctl daemon-reload
systemctl restart asterisk

# Verify
cat /proc/$(pgrep -f "asterisk -p")/limits | grep files
Enter fullscreen mode Exit fullscreen mode

For older init.d systems:

# Edit /etc/init.d/asterisk
# Add before asterisk startup:
ulimit -n 65536
ulimit -u 65536
Enter fullscreen mode Exit fullscreen mode

Step 4: Review Asterisk SIP Channel Limits

Check the main SIP configuration:

# View SIP channel configuration
grep -E "^maxexpire|^minexpire|^defaultexpire|^srvlookup" /etc/asterisk/sip.conf
Enter fullscreen mode Exit fullscreen mode

Add or adjust these settings in /etc/asterisk/sip.conf:

[general]
; Increase SIP slot capacity
maxchannels = 2000

; Enable DNS SRV lookups for carrier failover
srvlookup = yes

; Optimize timers
minexpire = 60
defaultexpire = 3600
maxexpire = 3600

; Enable call completion on busy subscriber (CCBS) to reduce rejections
; This requires carrier support
ccbsmode = core

; Increase UDP buffer size
udpbuffersize = 262144

; Session timers to detect dead calls
session_expires = 1800
session_minse = 90
sessiontimeout = 0
Enter fullscreen mode Exit fullscreen mode

After changes, reload:

asterisk -rx "sip reload"
Enter fullscreen mode Exit fullscreen mode

Step 5: Optimize Codec Selection

Codec negotiation failures can trigger 503s. Enforce a single, widely-supported codec:

# Current codec configuration for a trunk
grep -A 10 "carrier_mycarrier\]" /etc/asterisk/sip-vicidial.conf | grep -E "allow|disallow"
Enter fullscreen mode Exit fullscreen mode

Update to use only G.711 µ-law (most universal):

[carrier_mycarrier]
disallow=all
allow=ulaw
Enter fullscreen mode Exit fullscreen mode

Reload:

asterisk -rx "sip reload"
Enter fullscreen mode Exit fullscreen mode

Step 6: Monitor Asterisk Logs for Errors

Real-time log monitoring:

# Tail Asterisk messages log
tail -f /var/log/asterisk/messages | grep -i "503\|service\|unavailable"

# Search for recent errors
grep -i "service.*unavailable\|503" /var/log/asterisk/messages | tail -20

# Full SIP debug output (verbose, use sparingly)
asterisk -rx "sip set debug on"
# ... make a test call ...
asterisk -rx "sip set debug off"

# Check debug output
grep -i "sip.*debug\|<--" /var/log/asterisk/messages | tail -50
Enter fullscreen mode Exit fullscreen mode

Step 7: Enable and Check Asterisk Queue Logs

ViciDial relies on queue logs to track call outcomes. Verify they're being written:

# Check queue logging
grep -i "^queue_log" /etc/asterisk/logger.conf

# Ensure this line exists:
# queue_log => queue_log

# Restart logger if needed
asterisk -rx "logger reload"

# Verify queue_log file exists and is being written
ls -lh /var/log/asterisk/queue_log
tail -20 /var/log/asterisk/queue_log | grep -i "COMPLETE\|503"
Enter fullscreen mode Exit fullscreen mode

Step 8: Check ViciDial Dial Plan Logic

Review the outbound dial plan for the carrier. In ViciDial, this is controlled by extensions-vicidial.conf:

# Search for outbound call routing
grep -A 30 "^exten => _[0-9]" /etc/asterisk/extensions-vicidial.conf | grep -A 30 "Dial\|SIP"
Enter fullscreen mode Exit fullscreen mode

Look for a pattern like:

exten => _1NXXNXXXXXX,1,Set(OUTBOUND_GROUP=${CHANNEL(group)})
exten => _1NXXNXXXXXX,2,Set(GROUP_COUNT_LIMIT=10)
exten => _1NXXNXXXXXX,3,CheckGroup()
exten => _1NXXNXXXXXX,4,Dial(SIP/${EXTEN}@carrier_mycarrier,45,TM(custom_hangup))
exten => _1NXXNXXXXXX,5,Hangup()
Enter fullscreen mode Exit fullscreen mode

If CheckGroup() is blocking calls due to GROUP_COUNT_LIMIT, increase the limit:

exten => _1NXXNXXXXXX,2,Set(GROUP_COUNT_LIMIT=100)
Enter fullscreen mode Exit fullscreen mode

Reload dialplan:

asterisk -rx "dialplan reload"
Enter fullscreen mode Exit fullscreen mode

Step 9: Monitor ViciDial Call Log for Patterns

Use the ViciDial database to identify 503 error rates:

-- Find all calls with 503 or similar SIP errors in the last hour
SELECT call_date, phone_number, length(call_duration) as duration_sec, 
       SIP_RESPONSE, carrier_id, user_id
FROM vicidial_log
WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
AND SIP_RESPONSE IN ('503', '500', '502')
ORDER BY call_date DESC
LIMIT 20;
Enter fullscreen mode Exit fullscreen mode

If SIP_RESPONSE is NULL, check the call_result field:

-- Alternative: filter by call_result
SELECT call_date, phone_number, call_result, carrier_id, 
       COUNT(*) as count
FROM vicidial_log
WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
GROUP BY call_result
ORDER BY count DESC;
Enter fullscreen mode Exit fullscreen mode

If you see a spike in "FAILED" or "SERVICE_UNAVAILABLE" call results, correlate with the time of the 503 errors.

Step 10: Implement Call Rate Throttling

If you're generating calls too quickly for the carrier or your own system, implement rate limiting in the ViciDial dial plan:

; In extensions-vicidial.conf, add before the Dial() command
exten => _1NXXNXXXXXX,2,Set(GROUP_COUNT_LIMIT=20)
exten => _1NXXNXXXXXX,3,Set(OUTBOUND_GROUP=${CHANNEL(group)})
exten => _1NXXNXXXXXX,4,CheckGroup()
exten => _1NXXNXXXXXX,5,Wait(0.5)
exten => _1NXXNXXXXXX,6,Dial(SIP/${EXTEN}@carrier_mycarrier,45,TM())
Enter fullscreen mode Exit fullscreen mode

Adjust the Wait() duration to throttle call initiation (0.5 = 500ms delay per call).

Alternatively, set a CPS limit in ViciDial's carrier config:

# In ViciDial web admin, set the carrier's "CPS Limit" field to a conservative value
# (e.g., 10 calls/second) and reload the carrier
Enter fullscreen mode Exit fullscreen mode

Advanced Troubleshooting

Scenario 1: 503 Only on Specific Destinations

If 503 errors occur only for certain phone numbers or prefixes:

# Query logs filtered by destination prefix
mysql -u root -p asterisk -e "
SELECT phone_number, COUNT(*) as attempts, 
       SUM(IF(SIP_RESPONSE = '503', 1, 0)) as sip_503_count
FROM vicidial_log
WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
GROUP BY SUBSTR(phone_number, 1, 3)
ORDER BY sip_503_count DESC;"
Enter fullscreen mode Exit fullscreen mode

This may indicate a route-specific issue on the carrier. Contact support for that specific destination or region.

Scenario 2: 503 During Peak Hours

If 503s only occur during peak call volumes (e.g., 9 AM - 5 PM):

# Identify peak hour patterns
mysql -u root -p asterisk -e "
SELECT DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00') as hour_block,
       COUNT(*) as total_calls,
       SUM(IF(SIP_RESPONSE = '503', 1, 0)) as sip_503_count,
       ROUND(100 * SUM(IF(SIP_RESPONSE = '503', 1, 0)) / COUNT(*), 2) as fail_rate_pct
FROM vicidial_log
WHERE call_date >= DATE_SUB(NOW(), INTERVAL 7 DAY)
GROUP BY hour_block
ORDER BY fail_rate_pct DESC;"
Enter fullscreen mode Exit fullscreen mode

Solutions:

  • Request carrier to increase allocated channels
  • Implement call queuing: instead of rejecting with 503, queue calls and retry when capacity available
  • Load-balance across multiple carrier trunks

Scenario 3: 503 + High Latency

If network latency to the carrier is high (> 200ms), SIP timeouts may trigger 503s:

# Measure latency to carrier SIP server
ping -c 10 203.0.113.50

# For UDP latency (more accurate for SIP)
mtr -c 10 203.0.113.50
Enter fullscreen mode Exit fullscreen mode

If latency > 200ms:

  • Contact your ISP or network provider
  • Request a dedicated link to the carrier
  • Implement connection pooling in Asterisk to reduce RTT

Increase SIP timeout in asterisk.conf:

[options]
; Increase SIP transaction timeout from default (6 seconds) to 10 seconds
maxcallbitrate = 384
Enter fullscreen mode Exit fullscreen mode

Unfortunately, Asterisk's SIP timeout is not easily configurable per-trunk; you may need to upgrade to PJSIP channel driver (Asterisk 13+) for finer control.

Scenario 4: 503 + High Memory Usage

If system memory is near capacity:

# Check memory by process
ps aux --sort=-%mem | head -10

# Monitor Asterisk memory specifically
watch -n 1 'ps aux | grep -i asterisk | grep -v grep'
Enter fullscreen mode Exit fullscreen mode

Solutions:

  • Restart Asterisk during a maintenance window
  • Increase server RAM
  • Reduce call queue size or max concurrent calls

Restart Asterisk cleanly:

asterisk -rx "core stop gracefully"
# Wait for all calls to complete (check status)
sleep 30
/etc/init.d/asterisk start

# Verify restart
asterisk -rx "core show version"
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

Issue: "Registration failed" for carrier trunk

Cause: Incorrect SIP credentials or carrier doesn't recognize the IP.

Fix:

# Verify credentials in sip-vicidial.conf
grep -A 5 "username=\|secret=" /etc/asterisk/sip-vicidial.conf

# Confirm with carrier documentation
# Reload SIP and check registration
asterisk -rx "sip reload"
asterisk -rx "sip show registry"

# Check detailed registration attempt
asterisk -rx "sip set debug on"
# Reload SIP
asterisk -rx "sip reload"
# Wait 10 seconds
sleep 10
asterisk -rx "sip set debug off"
# Review logs
grep -i "register\|auth" /var/log/asterisk/messages | tail -30
Enter fullscreen mode Exit fullscreen mode

Issue: Calls fail immediately with 503, no "100 Trying" response

Cause: Carrier is rejecting at gateway level (possibly due to IP allowlist or account block).

Fix:

  1. Verify your server's public IP:
   dig @8.8.8.8 myserver.example.com +short
   # or
   curl -s https://ifconfig.me
Enter fullscreen mode Exit fullscreen mode
  1. Contact carrier and request they whitelist your IP

  2. Check if carrier requires specific SIP headers or authentication method:

   # Enable detailed SIP logging
   asterisk -rx "sip set debug on"
   # Attempt a call
   # Check logs for authentication challenges
   grep -i "401\|407" /var/log/asterisk/messages
Enter fullscreen mode Exit fullscreen mode

Issue: Random 503s, no correlation with load or time

Cause: Intermittent carrier connectivity or DNS resolution failures.

Fix:

# Test carrier DNS continuously
watch -n 1 'dig sip.carrier.example.com +short'

# Verify DNS resolution doesn't change
for i in {1..20}; do dig sip.carrier.example.com +short; sleep 1; done

# If DNS is inconsistent, set static IP in sip.conf
# Instead of: host=sip.carrier.example.com
# Use: host=203.0.113.50 (static IP)

# Reload SIP
asterisk -rx "sip reload"
Enter fullscreen mode Exit fullscreen mode

If carrier's DNS is unreliable, request their static SIP server IP.

Issue: 503 after Asterisk restart

Cause: SIP registration hasn't completed yet.

Fix:

# Monitor registration status during startup
watch -n 2 'asterisk -rx "sip show registry"'

# Wait for all trunks to show "Registered" status
# This typically takes 10-30 seconds

# If any trunk remains "Unregistered" after 1 minute, check:
asterisk -rx "sip show peers" | grep carrier_mycarrier

# Force re-registration
asterisk -rx "sip unregister carrier_mycarrier"
sleep 3
asterisk -rx "sip register carrier_mycarrier"
Enter fullscreen mode Exit fullscreen mode

Issue: 503 for international calls only

Cause: Carrier may not have routing to that destination, or special handling required.

Fix:

# Query international call attempts
mysql -u root -p asterisk -e "
SELECT phone_number, COUNT(*) as attempts,
       SUM(IF(SIP_RESPONSE = '503', 1, 0)) as sip_503_count
FROM vicidial_log
WHERE call_date >= DATE_SUB(NOW(), INTERVAL 1 DAY)
AND phone_number LIKE '00%' OR phone_number LIKE '+%'
GROUP BY SUBSTR(phone_number, 1, 3)
ORDER BY sip_503_count DESC;"

# Contact carrier and verify:
# 1. International routing is enabled on account
# 2. Destination country is in approved list
# 3. Specific prefix handling (e.g., +1 vs 1)
Enter fullscreen mode Exit fullscreen mode

Issue: Carrier returns 503 with "Temporarily Unavailable" message

Cause: Carrier is overloaded or performing maintenance.

Fix:

# Check carrier status page or contact support
# In the meantime, implement automatic failover:

# In extensions-vicidial.conf, add a secondary carrier
exten => _1NXXNXXXXXX,4,Dial(SIP/${EXTEN}@carrier_mycarrier,30,TM())
exten => _1NXXNXXXXXX,5,Dial(SIP/${EXTEN}@carrier_backup,30,TM())
exten => _1NXXNXXXXXX,6,Hangup()

# Reload dialplan
asterisk -rx "dialplan reload"

# Verify both carriers are registered
asterisk -rx "sip show registry"
Enter fullscreen mode Exit fullscreen mode

Summary

Resolving SIP 503 Service Unavailable errors requires systematic diagnosis of both carrier-side and server-side factors:

Carrier-side fixes:

  1. Verify trunk configuration (IP, port, credentials)
  2. Test connectivity to carrier SIP server
  3. Monitor SIP traffic for 503 responses
  4. Contact carrier for account status, channel limits, and rate limits
  5. Force trunk re-registration
  6. Check for geographic or destination-specific routing issues

Server-side fixes:

  1. Monitor Asterisk channel availability and resource usage
  2. Increase file descriptor limits and SIP maxchannels
  3. Optimize codec selection for carrier compatibility
  4. Review and fix dial plan logic (CheckGroup limits)
  5. Enable call rate throttling to prevent overload
  6. Monitor ViciDial logs for error patterns
  7. Implement call queuing and failover to secondary carriers
  8. Address network latency and DNS issues

Prevention:

  • Set up continuous monitoring of SIP registration status and channel utilization
  • Implement alerting when carrier registration fails or channel usage exceeds 80%
  • Schedule regular carrier connectivity tests
  • Maintain redundant carrier connections
  • Document carrier SIP configurations with clear comments
  • Keep Asterisk and ViciDial updated to latest stable versions

Most 503 errors resolve quickly once you identify whether the issue is carrier-side (contact support) or server-side (resource scaling or configuration). Use the diagnostic commands in this tutorial to pinpoint the root cause and apply targeted fixes.

Top comments (0)