OpenSIPS is a versatile and open-source SIP server that supports functions like SIP routing, load balancing, NAT traversal, registrar services, and integration with other VoIP platforms like Asterisk. It’s well-suited for medium to large-scale deployments.

1. Install OpenSIPS

Begin by downloading the latest OpenSIPS source code from http://opensips.org. Extract and place the source in /usr/src, then compile it with database module support (e.g., MySQL or PostgreSQL) depending on your use case.

Key Note: Ensure necessary development tools and libraries (e.g., gcc, bison, flex, libmysqlclient-dev) are installed before compilation.

2. Configure OpenSIPS Database Settings

Navigate to the OpenSIPS configuration directory:

cd /usr/local/etc/opensips
  • Open opensipsctlrc and configure:
    • SIP_DOMAIN
    • Uncomment and define DBENGINE, DBHOST, DBNAME, DBRWUSER, and DBRWPW.
  • Initialize the database:
opensipsdbctl create
  • Modify opensips.cfg to load and configure database-related modules.

3. Add Users

Once the database and configuration are in place, add SIP users:

opensipsctl add <username> <password>

Use SIP clients like Zoiper or Linphone to register and test basic call functionality.

4. Install Asterisk

Download and compile Asterisk from https://www.asterisk.org. Ensure required dependencies are installed. Once compiled:

  • Start Asterisk and ensure it’s running.

5. Configure ODBC

  • Install and configure ODBC drivers.
  • Edit odbc.ini and test the DSN connection using:
isql <DSN>
  • In Asterisk, configure res_odbc.conf and relevant modules to enable database support.
  • Verify ODBC connectivity within Asterisk CLI:
odbc show

6. OpenSIPS-Asterisk Integration

To forward SIP calls from OpenSIPS to Asterisk:

  • Update the routing section in opensips.cfg.
  • Use rewritehostport("Asterisk_IP:Asterisk_Port") in the route logic to redirect calls.

7. Test Integration

  • Register one user in a softphone.
  • Leave the second user unregistered.
  • Make a call to the unregistered user and verify if it’s routed to Asterisk successfully.

8. Call Forwarding Using AVPOPS Module

  • Load the avpops module.
  • Define AVP preferences in the database.
  • Use AVP attributes for call forwarding scenarios (busy, no answer, etc.).
  • Configure route logic in opensips.cfg to forward to Asterisk accordingly.

Example AVP entry:

opensipsctl avp add -T usr_preferences <username> callfwd 0 <forward_to_user>

9. NAT Traversal with RTPProxy

  • Install and run RTPproxy with appropriate flags.
  • Load nathelper and rtpproxy modules in opensips.cfg.
  • Implement NAT logic for REGISTER and INVITE requests.

Example runtime command:

./rtpproxy -l <your_ip> -s udp:<your_ip>:7890 -F
  • Enhance routing logic with flags and conditions for NAT detection and RTP handling.
  • Make sure reply routes and failure routes unforce RTPproxy correctly.

This setup establishes a reliable OpenSIPS and Asterisk-based VoIP infrastructure with NAT traversal and call forwarding capabilities.