You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Opensips与Freeswitch的LAN/WAN配置:多服务器部署启用咨询

Alright, let's break down how to get your SIP infrastructure fully functional with the setup you've laid out. I’ll walk through each critical component step by step, tailored to your Debian 8 environment.

Step 1: Validate Network Connectivity First

Network reachability is the foundation of your SIP stack—let’s lock this down first:

  • OpenSIPS Server: Since its eth1 is on 192.168.1.4 with a public gateway (xxx.xx.xx.xy), add a static route to ensure it can reach the internal 192.168.1.0/24 subnet:
    ip route add 192.168.1.0/24 dev eth1
    
    To make this persistent across reboots, edit /etc/network/interfaces and add to the eth1 config block:
    up ip route add 192.168.1.0/24 dev eth1
    
  • Other Devices: Confirm FreeSWITCH (192.168.1.2) and MySQL (192.168.1.3) can ping the SIP relay (192.168.1.5) and OpenSIPS’s eth1. Verify their gateway is set to 192.168.1.5 with ip route show.
  • SIP Relay: Ensure the supplier’s relay can ping OpenSIPS’s 192.168.1.4 and FreeSWITCH’s 192.168.1.2.
Step 2: Connect OpenSIPS to the SIP Trunk

Configure OpenSIPS to route calls to/from your supplier’s SIP relay by editing /etc/opensips/opensips.cfg:

  1. Load required modules and define the trunk:
    # Load dispatcher module for trunk routing
    loadmodule "dispatcher.so"
    modparam("dispatcher", "list_file", "/etc/opensips/dispatcher.list")
    
    # Define trunk destination in dispatcher.list
    # Format: group_id, SIP URI, flags, priority
    # Add this line to /etc/opensips/dispatcher.list
    1 sip:192.168.1.5:5060 0 1
    
  2. Add routing logic for trunk traffic:
    Insert this into your main route block:
    # Handle incoming calls from the SIP trunk
    if(src_ip == "192.168.1.5") {
        route(forward_to_freeswitch);
        exit;
    }
    
    # Handle outbound calls to external numbers via the trunk
    if($rU =~ /^\+?[0-9]{10,15}$/) { # Match E.164 number format
        ds_select_dst(1, 0); # Pick a trunk from dispatcher group 1
        t_relay();
        exit;
    }
    
  3. Restart OpenSIPS:
    service opensips restart
    
Step 3: Integrate OpenSIPS with FreeSWITCH

Set up call forwarding between OpenSIPS and FreeSWITCH, and ensure FreeSWITCH accepts traffic from OpenSIPS:

  1. Add FreeSWITCH routing in OpenSIPS:
    Create a dedicated route to forward calls to FreeSWITCH:
    route(forward_to_freeswitch) {
        $du = "sip:192.168.1.2:5060"; # FreeSWITCH's SIP address
        t_relay();
        exit;
    }
    
  2. Configure FreeSWITCH to allow OpenSIPS traffic:
    Edit /etc/freeswitch/sip_profiles/internal.xml and add OpenSIPS’s eth1 IP to allowed networks:
    <param name="allow-ip" value="192.168.1.4/24"/>
    
  3. Restart FreeSWITCH:
    service freeswitch restart
    

Connect OpenSIPS to your MySQL server for user authentication, call detail records (CDRs), and more:

  1. Install the OpenSIPS MySQL module:
    apt-get install opensips-mysql-module
    
  2. Set up the MySQL database and user:
    Log into your MySQL server (192.168.1.3) and run these commands:
    CREATE DATABASE opensips;
    GRANT ALL PRIVILEGES ON opensips.* TO 'opensips'@'192.168.1.4' IDENTIFIED BY 'your_secure_password_here';
    FLUSH PRIVILEGES;
    
  3. Import OpenSIPS’s default database schema:
    On the OpenSIPS server, run:
    opensipsdbctl create
    
    Select MySQL when prompted, then enter your database credentials (192.168.1.3, opensips, and your password).
  4. Enable MySQL integration in OpenSIPS:
    Add this to opensips.cfg:
    loadmodule "db_mysql.so"
    modparam("db_mysql", "db_url", "mysql://opensips:your_secure_password_here@192.168.1.3/opensips")
    
    # Optional: Enable user authentication
    loadmodule "auth.so"
    loadmodule "auth_db.so"
    modparam("auth_db", "calculate_ha1", yes)
    modparam("auth_db", "password_column", "password")
    
Step 5: Test Core Functions

Verify each part of your stack works as expected:

  • Outbound Call: Use a softphone registered to OpenSIPS to dial an external number. Check if the call routes through the SIP relay and FreeSWITCH handles media.
  • Inbound Call: Ask your supplier to send a test call to the SIP relay. Confirm it’s forwarded to FreeSWITCH and reaches your endpoint.
  • Database Sync: Register a new user via your softphone, then check MySQL’s subscriber table to ensure the record is saved.
Troubleshooting Quick Wins
  • Firewall Rules: Open SIP (UDP 5060) and media ports (UDP 10000-20000) on all servers with ufw allow 5060/udp and ufw allow 10000:20000/udp.
  • Logs: Check OpenSIPS logs at /var/log/opensips/, FreeSWITCH logs at /var/log/freeswitch/, and MySQL logs at /var/log/mysql/ for errors.
  • Status Checks: Use opensips-cli -x mi show dispatcher to verify trunk status, and sip show peers in the FreeSWITCH console to check connections.

内容的提问来源于stack exchange,提问作者Menpress Malatae

火山引擎 最新活动