How to Install Asterisk on an Asus WL-520GU Router
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:
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.
rmmod ext3 rmmod wl killall -9 buttons
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 Access. Disable 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 No. Select 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:
Why? You'll see Save your settings and mount your drive.
sleep 15 [ -d /mnt/USB ] && mount /mnt/USB /opt
Now we can install Asterisk. The way we installed Asterisk was with Optware. First, download the Optware install script...
...and run it:
wget http://www.toao.net/pub/VoIP/optware-install-ddwrt.sh -O - | tr -d '\r' > /tmp/optware-install.sh
Installing Asterisk is as simple as:
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.
ipkg update ipkg upgrade ipkg install asterisk16
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.
You should also disable logging, unless you need it for diagnostic purposes. Our logger.conf is now a blank file.
[modules] autoload=no ; Only load explicitely declared modules load => format_pcm.so ; Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G.711 load => codec_ulaw.so ; mu-Law Coder/Decoder load => app_dial.so ; Dialing Application load => app_macro.so ; Extension Macros load => app_playback.so ; Sound File Playback Application load => app_mixmonitor.so ; Record calls load => app_setcallerid.so ; Set CallerID Presentation Application load => app_disa.so ; DISA - used for calling card-type projects load => app_transfer.so ; Transfer calls - good for use with DISA so that you don't proxy audio load => func_timeout.so ; Adjust timeout; handy for use with DISA. But not essential if you can dial quickly. load => func_callerid.so ; Caller ID related dialplan functions load => func_logic.so ; GotoIf() and friends load => func_strings.so ; String handling functions load => pbx_config.so ; This loads your dialplan load => pbx_spool.so ; This is needed to make call files work load => chan_sip.so ; SIP load => res_musiconhold.so ; Music-on-Hold load => func_shell.so ; Execute shell commands and use the output in the dialplan. (Useful for formatting things with gnu-sed.) load => func_channel.so ; 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 => format_wav.so ; Microsoft WAV format ;load => app_echo.so ; Simple Echo Application ;load => res_features.so ; Call parking
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:
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.
cru "a" "asterisk" "*" "*" "*" "*" "*" "asterisk"
Accessing the Asterisk command line
To access the Asterisk command line, type the following:
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!?