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.
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.4with a public gateway (xxx.xx.xx.xy), add a static route to ensure it can reach the internal192.168.1.0/24subnet:
To make this persistent across reboots, editip route add 192.168.1.0/24 dev eth1/etc/network/interfacesand add to theeth1config 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 to192.168.1.5withip route show. - SIP Relay: Ensure the supplier’s relay can ping OpenSIPS’s
192.168.1.4and FreeSWITCH’s192.168.1.2.
Configure OpenSIPS to route calls to/from your supplier’s SIP relay by editing /etc/opensips/opensips.cfg:
- 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 - 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; } - Restart OpenSIPS:
service opensips restart
Set up call forwarding between OpenSIPS and FreeSWITCH, and ensure FreeSWITCH accepts traffic from OpenSIPS:
- 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; } - Configure FreeSWITCH to allow OpenSIPS traffic:
Edit/etc/freeswitch/sip_profiles/internal.xmland add OpenSIPS’s eth1 IP to allowed networks:<param name="allow-ip" value="192.168.1.4/24"/> - Restart FreeSWITCH:
service freeswitch restart
Connect OpenSIPS to your MySQL server for user authentication, call detail records (CDRs), and more:
- Install the OpenSIPS MySQL module:
apt-get install opensips-mysql-module - 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; - Import OpenSIPS’s default database schema:
On the OpenSIPS server, run:
Selectopensipsdbctl createMySQLwhen prompted, then enter your database credentials (192.168.1.3,opensips, and your password). - Enable MySQL integration in OpenSIPS:
Add this toopensips.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")
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
subscribertable to ensure the record is saved.
- Firewall Rules: Open SIP (UDP 5060) and media ports (UDP 10000-20000) on all servers with
ufw allow 5060/udpandufw 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 dispatcherto verify trunk status, andsip show peersin the FreeSWITCH console to check connections.
内容的提问来源于stack exchange,提问作者Menpress Malatae




