natfreeswitchopensips

Opensips & Freeswitch IP LAN & WAN Config


I have setup a dedicated Opensips Server on a public ip xx.xx.xx.xx & Dedicated Freeswitch Server 192.168.1.2, a dedicated MySql Database Server 192.168.1.3. My router is on 192.168.1.1. I have also got a sip trunk from a provider on 192.168.1.5. All servers are on Debian 8.

I have put my gateway as 192.168.1.5 for all except the opensips server which has its own gateway xxx.xx.xx.xy.

The Opensips server has 2 ethernet ports eth0 & eth1. And I have put eth1 as 192.168.1.4 how can I enable Opensips server public ip to access the local Mysql server and also send the calls to the Freeswitch Server.

I enables packet forwarding: /etc/sysctl.conf net.ipv4.ip_forward=1

My iptables on the opensips are like this:

iptables rules:

iptables -F

iptables -t nat -F

iptables -P INPUT ACCEPT

iptables -P OUTPUT ACCEPT

iptables -P FORWARD ACCEPT

iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A FORWARD -i eth1 -s 192.168.1.0/255.255.255.0 -j ACCEPT

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Thanks.


Solution

  • As long as you define an OpenSIPS listener for each interface, the outgoing interface selection should work out of the box. Set your destination using either $ru or $du (or both!), then t_relay() and you should be good.

    If, for any reason, the chosen outbound interface is incorrect, you can force your preferred interface using force_send_socket() prior to the t_relay() call.