How to Install Asterisk on an Asus WL-520GU Router

January 19th, 2010 Leave a comment Go to comments

Update: This article is almost a year old and some of the information is now outdated.  While it is certainly possible to run Asterisk on a WL-520GU router, there is now a better router that has been released since we bought ours.  It has a whopping eight times the memory and flash, and a CPU twice the speed of that in the WL-520GU - this is the best consumer-grade router with open-source firmware we've ever seen.  If you intend to run Asterisk on a router, we recommend the new Asus RT-N16.

We have also discovered that USB flash drives (at least the ones we have tried) are not up to the task of long-term use.  So, you may wish to instead use a CIFS share, or connect a USB hard drive instead of a USB flash drive.  Additionally, Asterisk may be installed on many other devices such as the Seagate Dockstar or many NAS devices such as the Western Digital MyBook Live.  If you have a favourite, please comment and let us know what it is and why.

The original article is below, in case it is still helpful for anyone.

Yes, you read right.  For this project, we're going to tell you how we built a fully functioning Asterisk PBX out of a $25 router.  We designed this project because we wanted an Asterisk server for use as a home PBX that could be built relatively easily, used as little power as possible, and cost as little as possible.  The best part is, a lot of the heavy lifting such as compiling Asterisk has already been done for us.  All we need to do is install it.

The first version of this article was published on the VoIP Tech Chat forum in August 2009.  The article that you are reading right now is the latest version.  The forum no longer allows us to edit the original post so we have moved it here.

A common question people ask is, "Why do you need a PBX for your home?"  The answer is we wanted telephone features that we haven't been able to find for a price we're willing to pay.  Now, we can have nearly any feature we want.  Some of these include termination failover, custom incoming Caller ID, and call recording.  The best part is that when we're done, the device will still function as a router.  You won't even need to wedge another AC adapter into your power strip.

Let's get started.  The first thing you need to do is install Tomato firmware with USB support on your router.  Be sure to read the paragraph at the end about the UDP Timeout settings as they are important.  True, it is possible to make Asterisk work using different firmware.  If you have other firmware that you prefer, you may be able to extrapolate this guide to it.  Our favourite firmware is Tomato.

It's a big Tomato.

The next thing you need to do is trim down some unneeded components of Tomato.  The WL-520GU only has 16MB of RAM.  This isn't a great deal, and we need as much RAM as possible available in order for Asterisk to run properly.  Another option is to use the Asus WL-500G Premium router which has 32MB of RAM.  It's quite a bit more expensive though, and for our purposes 16MB works like a charm.

Open the Tomato's configuration.  Navigate to the Administration module and then choose Scripts.  Save the following as the Init script:
rmmod ext3
rmmod wl
killall -9 buttons
This will disable the wireless module and the ext3 module, and the buttons program upon rebooting the router.  In all likelihood, you will not use ext3.  If you use wireless, omit the second line.  If you have configured the button on the back of the router for some important use, omit the last line.

Next, choose Logging from Tomato's menu.  Remove any checkmarks in Log Internally and Log To Remote System, if they exist.  Save your changes.  Then, navigate to Bandwidth Monitoring and remove the checkmark in Enable, if it exists.  Save again.

Next, choose Admin AccessDisable Telnet and enable SSH.  If you currently use Telnet to access the router's command line, you will now need to use an SSH client such as PuTTY.  One added bonus here is that we find PuTTY more user friendly than the Windows Telnet client.

Navigate to the USB and NAS menu and choose File Sharing.  Set Enable File Sharing to NoSelect FTP Server and disable this as well.

Prepare your USB drive.

We're almost ready to install Asterisk.  But first, we need something to install it on.  If you've already formatted your USB drive as EXT2, you may skip the next few steps.  If not, attach any spare USB drive that you have around and read on.

Return to the Tomato setup page, navigate to USB and NAS, and then to USB Support.  Enable Core USB Support, USB 2.0 Support, USB Storage Support, and Ext2 / Ext3 File System Support.  Attach your USB drive.  If the drive automatically mounted itself, unmount it before continuing.

It is time to partition and format the drive.  Note that anything on the drive will be erased during this process.  SSH into the router and type fdisk /dev/discs/disc0/disc.  To be sure you've selected the correct drive, use the command p.  The first line will tell you the size of the drive.  The system column will tell you the format.  If the drive is currently formatted as FAT32, under the System column should be Win95 FAT32.

Type d to delete the current partition, if one exists.  Then, type n to create a new partition.  Follow the prompts to create a primary partition.  If it asks for a partition number, enter 1.  Use the defaults for cylinders.  Next, enter w to write the partition table and exit fdisk.  If you've made a mistake, instead exit by pressing CTRL+C and start over.

Now you have created a partition.  You need to format it.  You should use the ext2 filesystem, unless you have a really really good reason to use ext3.  Type mkfs.ext2 /dev/discs/disc0/part1 -L USB
Note that "USB" may be anything you like.  -L specifies a volume label and I decided "USB" would be easy to remember.

Finally, run a check on the new partition by typing fsck.ext2 -f -y /dev/discs/disc0/part1

Next, you should configure the drive to automatically mount.  Return to the Tomato setup page and turn Automount on.  In the Run after mounting box, enter the following:
sleep 15
[ -d /mnt/USB ] && mount /mnt/USB /opt
Why?  You'll see 🙂 Save your settings and mount your drive.

Install Asterisk

Now we can install Asterisk.  The way we installed Asterisk was with Optware.  First, download the Optware install script...
wget -O - | tr -d '\r' > /tmp/
...and run it:
sh /tmp/
Installing Asterisk is as simple as:
ipkg update  
ipkg upgrade  
ipkg install asterisk16
ipkg may recommend some other packages to install such as sound and music-on-hold files. Install them if you want - we find them useful.  We only installed the uLaw versions because we only use the G.711 codec.

Asterisk Slimming

Asterisk's configuration is located in /opt/etc/asterisk.  We recommend using the following as your modules.conf.  This will conserve even more memory.  To edit Asterisk config files, we recommend WinSCP with your favourite text editor.
autoload=no                    ; Only load explicitely declared modules
load =>          ; Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G.711
load =>          ; mu-Law Coder/Decoder
load =>            ; Dialing Application
load =>           ; Extension Macros
load =>        ; Sound File Playback Application
load =>      ; Record calls
load =>     ; Set CallerID Presentation Application
load =>            ; DISA - used for calling card-type projects
load =>        ; Transfer calls - good for use with DISA so that you don't proxy audio
load =>        ; Adjust timeout; handy for use with DISA.  But not essential if you can dial quickly.
load =>       ; Caller ID related dialplan functions
load =>          ; GotoIf() and friends
load =>        ; String handling functions
load =>          ; This loads your dialplan
load =>           ; This is needed to make call files work
load =>            ; SIP
load =>     ; Music-on-Hold
load =>          ; Execute shell commands and use the output in the dialplan.  (Useful for formatting things with gnu-sed.)
load =>        ; Find information about the channel.  (Used with our implementation of DISA.)
; We do not use the following modules but mention them because they are common.
;load =>          ; Microsoft WAV format
;load =>            ; Simple Echo Application 
;load =>        ; Call parking
You should also disable logging, unless you need it for diagnostic purposes.  Our logger.conf is now a blank file.

Start Asterisk

Most likely you will want Asterisk to load automatically.  Return to the Tomato setup page, navigate to USB and NAS, and then to USB support.  Add the following to the Run after mounting box:
cru "a" "asterisk" "*" "*" "*" "*" "*" "asterisk"
This will create a cron job that will check to make sure Asterisk is loaded every minute.  If Asterisk is terminated for any reason - for example lack of memory - the cron job will restart it in one minute.  This should not happen if you've followed all of our directions but it it is nice to have just in case.  One side effect to this is that "Remote UNIX connection/Remote UNIX connection disconnected" will appear in the CLI every minute.  At this point you may start asterisk by running the asterisk command, or by rebooting you router and waiting for the cron job to start it.

Accessing the Asterisk command line

To access the Asterisk command line, type the following:
asterisk -vvvr
The r switch connects to the already-running Asterisk, and vvv tells Asterisk to set verbosity to 3.  This is useful when troubleshooting your dial plan.

Make a backup

At this point, it might be worthwhile to make a backup of your /opt directory.  In case your USB drive fails or you make a mistake and mess up your configuration, you can restore everything to defaults.  I do this every time I make major changes to my configuration.  Mount a CIFS share to /cifs1 and type:
tar -cvvf /cifs1/opt-backup.tar /opt


If everything worked properly and you didn't see any errors, you're done.  If you don't yet know how to configure Asterisk, take a look at our next article, Configure Asterisk for a Home PBX.  But first, take a minute and congratulate yourself.  You just built a PBX out of a router.  Isn't that just the coolest thing ever!?
  1. January 29th, 2010 at 12:23 | #1

    Great article!! I saw the original in the VoIP Tech Chat forums.

    A question, why Asterisk 1.6 and not 1.4?  Wouldn't you save memory?

    Also, I saw your postings on Digital Home (that's how I got to this page 🙂 ). How does it work with this Asterisk box? 


  2. January 29th, 2010 at 20:19 | #2

    Hey 🙂

    For the life of me, I all of a sudden couldn't get 1.4 to run.  I have no idea why.  I uninstalled and reinstalled and I checked my config 'til I was blue in the face and couldn't find anything wrong.  I eventually gave up and installed 1.6.  Yes, 1.4 memory usage would be about 20% less.  I might give it another try at some point, but fortunately 1.6 seems to run really really well. works really well with Asterisk!  😀


If you would like a reply to your comment, you must leave your email address! We receive dozens of questions every month from people who don't leave us with any way to contact them, so we have no choice but to ignore the question. We try to reply to as many questions as we can, if we know the email address of the person who asked the question. Thanks in advance for writing in :)

Allowed HTML: <b>, <i>, <em>, <strong>. All other < and > will be replaced with &lt; and &gt;.