Monday, January 3, 2011

Dialing via phone line through VoIP

Happy new year! :-)

It's time for my final installment of this tutorial, finally what we've been heading towards -
calling from a cellphone via a cheap PSTN (Public switched telephone network) in simple words, land line.

I assume you have:

  1. The SPA3102 unpacked and ready to setup.
  2. A router which has at least a one free RJ45 jack.

Setting SPA3102 IP


The first thing that needs to be done is to setup a LAN IP for the SPA3102 so trixbox
will be able to access it directly through LAN.

  1. Connect the SPA3102 to a power outlet.
  2. Connect the RJ45 supplied with the SPA3102 via the Ethernet jack and to a computer:

  3. In the computer, open up a browser and go to the SPA's Web based
    configuration UI via http://192.168.0.1
  4. Once there, click Wan Setup and then Advanced at the top of the page:



  5. Once in Wan Setup make the following changes:

    • Connection type - Static IP, the IP entered here will remain permanent.
    • Static IP - An IP of your choosing which matches your router's IPs,e.g, my router gives IPs formatted 10.x.x.x (due to the netmask255.0.0.0 and it's gateway),
      I chose 10.0.0.8.
    • Gateway - Your router's IP, to figure that one outyou can type
      ipconfig in cmd and get the Default Gateway from
      the NIC you're getting your network from.
    • Netmask - Match to your router's netmask, mine is 255.0.0.0
    • Enable WAN Web Server - Set this to Yes since we'll need access to the web ui.

    Click the Submit All Changes when done:


  6. Disconnect the RJ45 cable from both the computer and the SPA.
    Reconnect the cable in the following manner:
    From the SPA's Internet jack to a free ethernet
    port in router:




When this is done, test out the connection, try and access from your browser
to the IP you've setup e.g http://10.0.0.8.
In case you fail, redo the steps above.

NOTE: If you by mistake misconfigure you SPA3102 and unable to connect to it at all you can reset it using a phone - connect
a phone to the phone jack in the spa, and hit **** 73738# 1
this will reset the device.

SPA 3102 Configuration


Now we're going to configure the SPA3102 so asterisk will be able to connect to it.


  1. Open a browser and go to http://[your-spa3102-ip]/admin/voice/advanced (e.g http://10.0.0.8/admin/voice/advanced) or alternatively
    go to the Voice tab, then choose Admin Login and Advanced on the top right corner of the page:

  2. Now, we need to disable the port which corresponds to the phone jack in the SPA
    because we don't want to get any connected phone ringing when a call comes in.
    Go to the Line 1 tab and set Line Enable to No:

  3. Head into the PSTN Line tab and set the following settings:

    • Proxy and Registration
      • Proxy - This is the trixbox IP you've setup in section 2 of this tutorial, mine is 10.0.0.4.
      • Ans Call Without Reg - Set this to yes.

    • Dial Plans
      • Dial Plan 1: (x.<:@gw0>)

    • VoIP-To-PSTN Gateway Setup
      • Line 1 Fallback DP: 1
      • VoIP Caller Default DP: none

    • FXO Timer Values (sec)
      • PSTN Answer Delay: 1

    • PSTN Disconnect Detection
      • If you live in israel set Disconnect Tone: 400@-6,400@-19;3(.5/.5/1+2)

    • International Control
      • FXO Port Impendance: 220+820||120nF (Works well in Israel, leave as is if problematic)
      • PSTN To SPA Gain (I've changed to to increase volume coming from the land line): 12

  4. Now, click Submit All Changes.


Adding SPA3102 to trixbox

In this stage we'll let trixbox know of our SPA3102 by adding it as a 'trunk'.
A trunk is basically a device which gives certain VoIP service.

  1. Open up the trixbox web ui using http://[trixboxip] e.g http://10.0.0.4, go to
    PBX>PBX Settings via the top menu:
  2. From the left menu choose Trunks and the on the right choose Add SIP Trunk:



  3. Fill in the following fields:
    • Outbound Caller ID: SPA3102 (or anything you want, either way it's not really used)
    • Maximum Channels: 1
    • Dial Rules: X. (including the dot at the end)
    • Trunk Name: SPA3102
    • PEER Details:
      canreinvite=no
      context=from-internal
      host=[spa ip address - e.g 10.0.0.8]
      nat=no
      port=5061
      type=friend
      qualify=yes
      dtmfmode=rfc2833


  4. Click Submit Changes when done.
  5. In order to use the newly added trunk we'll create an Outbound route which will say the following: each number which begins with 0 will be passed on to the SPA3102.
    Go to Outbound Routes from the left menu and fill the following fields:

    • Route Name: bezeq (anything you like)
    • Dial Patterns: 0. (zero dot)
    • Trunk Sequence: SIP/[trunk name] - e.g SIP/SPA3102

  6. Commit the new configuration and restart asterisk by clicking the orange
    Apply Configurations Settings bar at the top of the page and confirm restart:




Calling Cheap

Now we're set to go, open up sipdroid and dial any number which begins with a zero,
call your friends and tell them what you just accomplished.

Opening NAT Ports

If you wish to use this system outside of your local home network (which is the whole point)
and you are behind NAT (which you most likely are) then you'll have to open the following ports
and direct them to trixbox's IP address:

  • 5060 UDP - This is the standard port for the SIP protocol.
  • Range: 10000 - 20000 UDP - RTP ports, it's the protocol responsible transferring voice, if
    these ports are closed you or the party you call won't hear a thing.

Final Words

Thanks for bearing with me on this long tutorial, if you've reached thus far it means you've
accomplished something pretty cool.
If you like this tutorial pass it on.
If you encounter any problems don't hesitate to leave comments and ask.

Cheers, Max.

Sunday, December 19, 2010

Configuring trixbox and voip test

Hi, and thanks for reading part III of this tutorial.

In this part, I'm going to introduce you to setting up SIP extensions in
trixbox, and establishing voip calls.

We'll test VoIP calls between X-lite, a Windows based Software VoIP Phone,
and Sipdroid, a voip client for Android.

The purpose of this test is to verify our networking with trixbox is
operational just a tad before we lay out the big guns.

Configuring IP


If you're not satisfied in the IP automatically assigned to your VM, you can
modify it, if it's fine go ahead and skip to the next section.


  1. Launch VirtualBox if it's not up yet.

  2. In the login screen use root as user name
    and the password you entered during the installation (I hope you remember it!).

  3. Type system-config-network-tui to enter
    networking configuration screen:



  4. Choose Edit Devices and hit Enter, then choose your device and hit Enter again:



  5. You can modify its parameters. If you'd like to change to static IP, hit the spacebar when cursor is on Use DHCP to uncheck it, and customize parameters as needed:

    trixbox eth0 configuration

  6. Save everything by choosing OK and at the end, Save&Quit.

  7. We're not done yet, now we have to restart our network card, type
    (assuming eth0 is your NIC):

    ifdown eth0
    ifup eth0

    Then to verify your IP was indeed set type:
    ifconfig





Setting up extensions in trixbox

Before we start, I assume you've configured your IP, if not return to the previous section.
I'll be using [trixboxip] notation instead of a true IP in the examples follow.

In thie section we'll be setting up two SIP extensions.
Extension are basically endpoints that interface with asterisk.
You can configure extensions manually by editing various configuration scripts
and typing in some terminal commands, but trixbox comes with a very versatile
web interface to do almost everything through GUI.
For our purposes it is more than sufficient.


  1. Browse to http://[trixboxip] OR https://[trixboxip] for SSL secured page in your
    favorite browser to enter the web interface.
    Click switch at the top right corner of the page
    to enter Administration mode.



  2. The default credentials are:

    user: maint
    password: password



    NOTE: You can change the password using the command passwd-maint in the terminal.
    I suggest you do so for security purposes.

  3. To create new extensions head into PBX>PBX Settings:


  4. Now, head into Extensions:

  5. In the Add an Extension page make sure
    Generic SIP Device is selected (should be the default) and click Submit.

  6. Create an extension and later create another one in the same manner.
    The fields which are relevant are the following:

    User Extension - it's analogous to User Name.
    Display Name - optional, but nicer for SIP Caller Id.
    secret - account's password.



    Click Submit when you're done.

  7. After you've created 2 extensions click Apply Configuration Changes at the top of the page.

    The idea behind this approach is that you can do as much changes as you'd like
    to asterisk, and submit them, and all this without reloading the asterisk server.
    When you are ready to commit those changes the server is reloaded by clicking
    that button.



  8. Confirm reloading of the PBX:




OK, now that we've set-up extensions we're ready to test them out.

Configuring X-Lite and Sipdroid



First of all, we'll install X-Lite and connect to the server as the
first extension we've setup - I named it's user 500.
Second, we'll install Sipdroid on Android from the Market, and connect as the
second extension - I named it's 600.

  1. Download X-Lite from here

  2. Launch it, and right click on the display screen, choose SIP Account Settings:


  3. Now, choose Add... on the right:


  4. Fill in user first user's credentials:

    Display Name - Anything you'd like, its internal to X-Lite.
    User Name - First user's name.
    Password - Second user's password.
    Domain - trixbox's server url.




  5. Confirm you entries, wait a few moments and if everything's OK it should look like this:




Let's get to installing and configuring Sipdroid.
I'm assuming you have WiFi since this test is performed in a local network, in later tutorials,
I will explain how to expose to server outside of the LAN and through out NAT.

NOTE: If your phone supports SIP (I know some Symbian phones have
support built in, iPhone users should look for SIP client in the AppStore, Windows Mobile users should
do the same).


  1. First, enter the Market app and type in sipdroid in the search box, and download it (as of writing the article, the latest
    Sipdroid version was 2.0.1 beta).

  2. Open Sipdroid:
    Sipdroid main screen

  3. Press the phone's Menu button and choose Settings, fill in:

    Authorization Username - Second user's name.
    Password - Second user's password.
    Server or Proxy - trixbox's server url.
    Use WLAN - Check this checkbox so WiFi dialing will be enabled.

    Sipdroid account settings

  4. Now, press the phone's Back button to return to main screen and
    slide down the Notifications Bar to see if registration succeeded, if it does you should
    see [userName]@asterisk Registered:

    Sipdroid registered notification Android

    NOTE:
    If registration failed due to:

    • Timeout - make sure you've entered
      the proper server address, that the used port is 5060 and
      the protocol is UDP (in Sipdroid's settings).

    • Unauthorized access - make sure the user name and password entered in
      settings are correct.







Dialing from Sipdroid to X-Lite



If you've reached here you've just set-up a basic VoIP configuration, let's test it by
dialing from Sipdroid:


  1. Head into your phone's dialer and type in the user name you used in X-Lite and dial:


    NOTE: I once encountered an issue that seems to be an X-Lite bug which cause the call to fail,
    restart X-Lite in retry in such case.

  2. Answer the incoming call and make sure voice passes on each end:



    NOTE: If there's a problem recording within
    X-Lite you can configure recording device by right clicking it's display,
    and going into Options>Device and
    choosing the proper Microphone Device.



Excellent, now we've tested our quickly assembled VoIP system in our nifty
in-house WiFi.

In the next tutorial section we'll connect and configure the Linksys SPA3102 to
a router and an analog phone line.
Then, we'll create an extension for it in Asterisk and
configure its gateway to work for our VoIP to Analog Phone line
conversion purposes.

Stay tuned,
Max.

Sunday, December 12, 2010

Installing trixbox in VirtualBox

Hello again, thanks for bearing with me.

I'm going to explain step-by-step how to install trixbox in VirtualBox, this guide
assumes you have VirtualBox installed, if not, you can download it from here.

Virtual machine setup



  1. Grab the latest trixbox ISO from here, version 2.8.0.4 was latest at the time I wrote this tutorial.

  2. Start VirtualBox

  3. Click New


  4. You'll see this dialog, click next:


  5. In Name type trixbox, In OS Type select Operating System: Linux, Version: Red Hat
    and click Next.


  6. 512MB of memory is more than enough, if you've low memory in your PC, even 256MB should suffice, click Next.


  7. Now, let's create a virtual hard drive for trixbox, click Next


  8. The following wizard will start, click Next.


  9. Make sure Dynamically expanding storage is checked, this way the disk will
    expand on demand, this saves space.


  10. Pick a location into which you'd like to store the virtual disk file.
    The size of 8.00GB should suffice, remember that it will not really take up
    the whole 8.00GB since we've selected Dynamically Expanding Storage earlier.
    After initial installation, trixbox virtual drive consumes around 1.8GB.
    Click Next.


  11. Click Finish in the summary dialog:


  12. Click finish again in the Create New VM (Virtual Machine) summary dialog:





Configure VM


Now that we have created a virtual machine, we need to configure it in order to achieve the following goals:

  1. Make the VM boot from the trixbox ISO so we can install it.

  2. Make our the VM see our LAN so we'll be able to connect to it from
    the Outside world.



Let's accomplish these:

  1. Open settings dialog by selecting trixbox and clicking Settings:


  2. From the left pane, select Storage and on the right under IDE Controller choose Empty and click the folder icon.

  3. In the Virtual Media Manager click Add and browse for trixbox ISO file you've downloaded earlier.


  4. After choosing the trixbox ISO, click Select.


  5. The steps above made that the ISO will appear as a bootable CD-ROM to the machine.
    Now we need to make our machine visible in the network.
    To do so, on the left pane click Network and then on the right choose
    Attached to: Bridged Adapter and under Name choose your active network interface card, in my case I had to choose my Ralink WiFi card.

    You can use ipconfig /all in cmd to determine which card is connected to the network according to it's IP in the network.
    Close the settings dialog afterwards by clicking OK.




Installing trixbox


Now we're finally ready to install trixbox.
Before we start you may receive informative messages from VirtualBox regarding
the mouse being not active and the Host key being Right Control.

The host key (Right Ctrl) allows you to exit the VM and return to Windows.
If you have no mouse active in the VM use the Tab key to switch between
inputs and list boxes (more on that soon).


  1. Click Start:
  2. In the boot screen hit Enter.


  3. Choose your keyboard layout, not really important in truth since we'll be
    doing our configurations using a web browser, the keyboard layout is internally in
    Linux.

    To switch between Ok, Back and the list box use the Tab key.

    Focus on OK and hit Enter when ready.


  4. Choose your time zone, again, to move between buttons use the Tab key,
    focus on OK and hit Enter when ready to continue:


  5. Enter you root account password (Don't forget it!), focus on OK and hit Enter when done.


  6. Grab a beer while trixbox installs:


  7. The VM will reboot, now we need to remove the virtual CD-ROM or else we'll be stuck in an infinite setup loop, to do so go to the Devices Menu - remember to hit Right Ctrl if you're inside the VM to return keyboard and mouse focus to windows).
    In the devices menu choose CD/DVD Devices and click Unmount CD/DVD Device.


  8. Now, reboot - go to the Machine menu and choose Reset:


  9. After reboot you'll see this startup screen, hit Enter:


  10. OK, now wait a couple of seconds until Trixbox boots, you should see the following
    login screen:



    ***NOTE the IP might be different, in case
    you don't see an IP but only http:// you may have not setup the network card correctly.
    In that case, shut down the machine by choosing Machine>ACPI Shutdown, go to
    Settings, there go to Network and switch the network interface card to another one.
    Start the machine again and see if you get an IP address.



End of part II


I hope this tutorial has been useful to you. In the next one we'll be configuring
trixbox and testing it with a free softphone, called X-lite, to see if networking
works.