Port-Scrambling Asterisk Servers

You have already heard that making calls between two different geographical places in VoIP network might encounter different problems. So there would be no connection between UAs. There are some solutions like VPN, Tunnel and so on. Here another solution is explained which is more secure and convinient.
Most VoIP protocols like SIP and IAX2 are among Application layer protocols and UDP or TCP is used to tranfer data. IAX2 uses only UDP so with some modifications we will get a good result.
IAX2 protocol and PortScrambling Techniqe is used to ease the process.
Consider this topology:

As you can see Asterisk servers are not connected directly but they are connected through a PS service.
Now we need to code the PS service. The codes are simple and consider that if you need other configurations you have to modify it. The code is Python.
Creat a new file and name it “ps.py”, then add these codes:
import socket
import sys
import subprocess
import time
try:
host = ‘Local-IP’;
port = 65432;
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((host, port))
except socket.error:
print ‘Failed to create socket’
sock.close()
sys.exit()
while(1) :
try :

receive data from client (data, addr)

data, addr = sock.recvfrom(1024)
if (addr[0] == “Local-IP”):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(data, (“Remote-IP”,65432))
s.close()
elif(addr[0] == “Remote-IP”):
sock.sendto(data, (“Local-IP”,4569))
print str(addr[0]) + “:” + str(addr[1])
except socket.error, msg:
print 'Error Code : ’ + str(msg[0]) + ’ Message ’ + msg[1]
sock.close()
s.close()
sys.exit()

Instead of “Remote-IP” and “Local-IP” add your server IPs. You need to creat this file on both servers and run it.
Now we need to have an IAX-Trunk on each server on PS service with any possible port, in our example 654321:
[peer]
type=friend
host= Local-IP
port = 65432
trunk=yes
username=peer
secret=123123
context=from-local
deny=0.0.0.0/0.0.0.0
permit=0.0.0.0/0.0.0.0
qualify=yes
disallow=all
allow=ulaw,alaw

Now run the PS service: python ps.py &
Then restart IAX madoul. If you command “iax show peers” yo’ll see that IAX-Trunk in registered on PS service. This way you can make calls easily without any call lost.
Bear in mind that in this method both servers must have static IP.

Mojtaba Esfandiari.S