Search

Free Asterisk on the Google Cloud platform using ClouDNS

Free Asterisk on the Google Cloud platform using ClouDNS

Who among us doesn’t like to use a free application, a free website or even a free cloud machine from time to time? This time there’s a 3-in-1 treat. Free Asterisk on the Google Cloud platform using ClouDNS On the Google Cloud website you can read about a completely free computer instance. As you can see, this concerns a small machine created in one of 3 regions of the USA. However, it is enough for us to also install and run the free version of Asterisk, and the free version of the ClouDNS service will allow us to maintain the visibility of our system despite IP address changes. So let’s get started!

Table of Contents

1) Creating a free instance on Google Cloud

Go to Google Cloud Console and select from the navigation menu Compute Engine -> VM Instances and click Create Instance

NOTE: If you haven't started using Google Cloud with a billing account, you can create one now. You will also receive a pool of certain free funds to use for 90 days. If you do not choose any paid solutions, you will not incur any costs.

In your new instance, you first select the machine type as “e2-micro“. The window on the right shows the projected costs, but we do not care about this information because it will later turn out that, as previously described, it will be free.
In the Boot Disk section, select the latest stable version of Debian: GNU/Linux 12 (bookworm). Of course, you can choose any other one. We also increase the disk capacity to 30 MB
We give our system a friendly name and choose one of the following regions, in accordance with the conditions for receiving a free instance:
  • Oregon: us-west1
  • Iowa: us-central1
  • South Carolina: us-east1
Then click “Create

2) Login, update and upgrade

We will be able to access the newly created machine via SSH using the SSH button. Google Cloud uses its own SSH keys, which it transfers to the machine.
Click Authorize to allow the browser to securely connect to your virtual machine.
Your default user, whose SSH key you just connected to, has sudo permissions and is a member of the sudoers group by default. Now switch to the root account in the console and update the system.
				
					sudo -i
apt update
				
			

Then upgrade the system by clicking “y” to agree to the entire operation

				
					apt upgrade
				
			

To make it easier to connect to the machine via an external ssh client, e.g. putty, add your public key to the authorize_keys file for your user in Google Cloud.

3) Free DNS

While waiting for the upgrade to be performed (it’s a slow machine, it took about 20 minutes), we will set up a free DNS. We need this because this free version of the machine receives a public IP address, but unfortunately it changes after each restart. On the website ClouDNS we have the free one we are looking for. So let’s go to create a free entry and click Free zone.

In the Domain name field, enter a friendly name and in the Enter your current IP address field our current IP address, which is visible in the Google Cloud panel. We can also select Activate Dynamic DNS immediately. Finally, click Create
Using the WhatsMyDNS website we can check how our hotkey404-free-asterisk-gcp.cloudns.ph address is propagated around the world.

4) Asterisk installation

It will take us about an hour to complete this part on our free machine. This entire process is described in our other blog, so I encourage you to read the post: Install Asterisk 20 from source on Debian 12 and perform the steps described there. If you choose a different version of Linux, you can also use our installation tips for Ubuntu, RockyCentOS 7CentOS Stream 8. After the basic installation, we can also set the time zone appropriate for our physical location.
				
					timedatectl set-timezone Europe/Warsaw

				
			

5) Firewall Configuration

If we want to enable SIP phones to log in to our PBX, we must add an appropriate rule on the Google Cloud firewall. Select the menu: Firewall > Create firewall rule and create the allow-sip rule. Its example configuration is in the screenshot below.
We can also copy the rtp.conf file from samples/ to Asterisk’s working directory and also limit the rtp ports there to a selected range, here 10000 to 10030. Usually there is no need to open thousands ports, since such a small machine will not allow even hundreds of simultaneous connections.
				
					cp /etc/asterisk/samples/rtp.conf /etc/asterisk
nano /etc/asterisk/rtp.conf


				
			
				
					rtpstart=10000
rtpend=10030

				
			

6) Dynamic DNS configuration

It is true that our switchboard is already recognized on the Internet by its name (FQDN), but unfortunately each time the machine is fully turned off, the IP address changes, so we would lose the ability to connect to the new IP address by name. ClouDNS-type services allow us to properly configure dynamic DNS. On the ClouDNS website, click on the two opposite arrows next to your free entry that we configured in point 3 (Active Dynamic URL)

You will receive a ready-made script to run on your system to update entries in the ClouDNS website. As you can see, in Linux this can be done using the wget command calling the appropriate URL.
However, we need to go a step further and create a script that will run after each full shutdown of our system (poweroff). We then have a guarantee of almost constant access to our services via a specific FQDN address. In the next part we will describe it step by step.

7) Script updating the IP address change

We will use the newly created cloudns_update.sh script to update our IP address
				
					nano /var/tmp/cloudns_update.sh
				
			
				
					#!/bin/bash
curl -s https://ipv4.cloudns.net/api/dynamicURL/?q=paste the encoded value obtained from the ClouDNS website here

EXTERNALIP=$(curl https://ipecho.net/plain)
sudo sed -i "s/^external_media_address =.*$/external_media_address = $EXTERNALIP/" /etc/asterisk/pjsip.conf
sudo sed -i "s/^external_signaling_address =.*$/external_signaling_address = $EXTERNALIP/" /etc/asterisk/pjsip.conf
				
			
The content of this file includes calling a dedicated link for the ClouDNS service and reading the current IP address using the IPecho service. Local knowledge of the changed address is necessary to modify the configuration of our Asterisk to ensure that services are provided correctly. Therefore, the script will also modify the appropriate entries in the pjsip.conf file.
By default, after installation, in the pjsip.conf file, the lines of code that we intend to change with our script are commented out with a semicolon. They must first be uncommented (remove the semicolon) so that the sed -i command finds the correct string of characters to replace.
				
					nano /etc/asterisk/pjsip.conf
				
			

We make changes in two lines

				
					external_media_address =
external_signaling_address =

				
			
We will now grant execution permissions to the script we have created.
				
					chmod +x /var/tmp/cloudns_update.sh
				
			

We will now create a new website file that will be automatically launched every time the system is restarted.

				
					nano /etc/systemd/system/cloudns_update.service
				
			
				
					[Unit]
Description=Update my External IP on Cloudns
After=network.target

[Service]
Type=simple
ExecStart=/var/tmp/cloudns_update.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target
				
			

Now we will reload the system service to include the newly created service.

				
					systemctl daemon-reload
				
			

Then we will add the service to autostart and run it.

				
					systemctl enable cloudns_update.service
systemctl start cloudns_update.service
				
			

Now, after turning off the machine and restarting it, we will see the new IP address there, and in our ClouDNS service the IP address will be updated.

				
					poweroff
				
			

We start the machine from the Google Cloud interface.

8) Logging in your phone account

Let’s check if we will be able to log in the sample pjsip account correctly. Just remember to enter an optional name: Authentication username. All login details can be found in the file /etc/asterisk/pjsip.conf

After a while, we will see that our telephone account will be correctly logged in and available.

You can fully enjoy your free phone system. Have fun!

If you would like to monitor everything that is happening on your PBX, try our proprietary VOIPERO software.

Setup only takes a few minutes and the system is currently completely FREE.

Read what our VOIPERO system can do in terms of live monitoring and reporting of VoIP systems based on Asterisk.

Share this post

Do you have questions or you need an offer?

Contact us!

Most popular

Related Posts

We Have Launched

Monitoring & Reporting of Your VoIP Server