Opening multiple ports on Microsoft Azure (e.g. for an Asterisk deployment)

If you publish an Asterisk servers on Azure, you might find it a daunting task to open multiple ports (called endpoints) on Azure, the task is simply slow if you use the web (portal or the old one). And we RTP folks, need a lot of ports to get a single call going (at least 3 ports required)

So, let’s say you’re gonna create a default Asterisk installation and open the usual ports such as;

IAX2- UDP4569
SIP – UDP5060
RTP-UDP10000 to UDP20000 (in this article, i only needed 100 ports)

Here’s how you can open all those ports in under 10 minutes.

1) Download and install the Azure Powershell extensions.

2) Start it up – it should be called Windows Azure Powershell (this is not the usual powershell, it must read Azure Powershell). You may need to run this as admin.

3) Once in there, copy paste the following (modify where applicable)

Task inside powershell (copy paste will do)
1) Add an azure account (this will launch the authentication windows, do your thing and authenticate)


2) Now, declare which subscription this VM is tied to (My subscription is called Visual Studio Premium with MSDN)

Select-AzureSubscription -SubscriptionName “Visual Studio Premium with MSDN

3) Declare the name of the VM you wish to setup
$vm = Get-AzureVM -ServiceName myazurebox -Name myazurebox;

NOTE: ServiceName is the cloud service, if it is not part of a cloud service, just enter the actual VM name, repeat that in NAME variable like above. If you get certificates errors at this point run this; $vm | Update-AzureVM You would need to rerun from step 1. This command also clears everything incase you messed up and want to restart.

4) Add for IAX2
$VM | Add-AzureEndpoint -Name IAX2 UDP -LocalPort 4569 -PublicPort 4569

5) Add for SIP (UDP)
$VM | Add-AzureEndpoint -Name SIPUDP UDP -LocalPort 5060 -PublicPort 5060

Add for SIP TCP (if using)
$VM | Add-AzureEndpoint -Name SIPTCP TCP -LocalPort 5060 -PublicPort 5060

6) Add for RTP
Now, since RTP is a bunch of ports that needed to be opened, in a default setup would be 10000 to 20000, you can do a loop and add them like this; Note, you can only open up to 150 ports at a time, apparently. So add more into the loop if needed.

10000..10100| ForEach { $VM | Add-AzureEndpoint -Name RTP$_ -Protocol UDP -LocalPort $_ -PublicPort $_} ; $vm | Update-AzureVM

This will add ports 10000 to 10100, name them RTP10000…and so on with UDP as the protocol. You don’t really need that many RTP ports opened on Asterisk unless you have a ridiculous amount of concurrency on SIP. Otherwise, you don’t really need that many ports opened.


Freepbx: Use the GUI, look under Settings | Asterisk Sip Settings, look for RTP port range. *You might need to restart Asterisk.

7) Finally, update the VM (this is when you will see the changes on Azure’s web management portals)

$vm | Update-AzureVM

And you’re done!