Tuesday, June 29, 2010

Asterisk, the VoIP Server on DD-WRT

I'm a big fan of Asterisk on router -- imho, it's the perfect platform for anyone want to try Asterisk at home -- 24x7, fanless and even the cheapest router can handle at least 2-3 concurrent conversation. Before this WZR-HP-G300NH, I had Asterisk running on a WRT54G-TM for over a year with lots of fun.

Installing Asterisk on the router is easier now as current OpenWrt trunk build(the one we use) includes prebuilt Asterisk binaries. As always, since OpenWrt is designed to work with / not /opt, some adjustment is required to get Asterisk working properly.

  1. Install Asterisk 1.6
    Believe it or not, DD-WRT MEGA also has Asterisk included -- it's an old ver1.4 and some important files are missing -- I have no idea why DD-WRT decided to do so, too much flash ROM? Anyway, to install Asterisk 1.6 on our opkg enabled router, run
    opkg install asterisk16

    You may also want to install some additional modules like:
    opkg install asterisk16-res-agi
    opkg install asterisk16-res-musiconhold

    To view a full list of Asterisk packages(lots of them!), run
    opkg list | grep asterisk16

  2. The configuration file: asterisk.conf
    With our installation, the asterisk.conf is in /opt/etc/asterisk/asterisk.conf. Change it to the contents below:

    [directories] ; remove the (!) to enable this
    astetcdir => /opt/etc/asterisk
    astmoddir => /opt/usr/lib/asterisk/modules
    astvarlibdir => /opt/usr/lib/asterisk
    astdbdir => /opt/usr/lib/asterisk
    astkeydir => /opt/usr/lib/asterisk
    astdatadir => /opt/usr/lib/asterisk
    astagidir => /opt/usr/lib/asterisk/agi-bin
    astspooldir => /var/spool/asterisk
    astrundir => /var/run/asterisk
    astlogdir => /var/log/asterisk
  3. [compat]
    pbx_realtime=1.6
    res_agi=1.6
    app_set=1.6


    As you can see, by modifying this file, we tell Asterisk to look for files at /opt/etc/asterisk and /opt/usr/lib/asterisk instead of default locations, which fits our installation.

    Now try to launch asterisk by running:
    asterisk -vvvvvc
    Exit by pressing ctrl+c

  4. Asterisk configuration
    By default, asterisk loads lots of modules, you can change the settings to fit your needs and reduce memory usage.

    Below is a sample of /opt/etc/asterisk/modules.conf with reduced modules:

    [modules]
    autoload=no                ; only load explicitly declared modules
    load => app_dial.so
    load => app_echo.so
    load => app_macro.so
    load => app_playback.so
    load => chan_sip.so
    load => codec_ulaw.so
    load => pbx_config.so
    load => format_pcm.so
    load => format_wav.so
    load => func_callerid.so
    load => func_strings.so
    load => res_musiconhold.so
    load => res_agi.so

    For SIP users, other important files including /opt/etc/asterisk/extensions.conf and /opt/etc/asterisk/sip.conf. These are not covered here, please refer to website about Asterisk like asteriskguru and voip-info.org. Also, here is a must-read  ebook: Asterisk: The Future of Telephony Second Edition(download the PDF book)

  5. Run it as service
    Create file /opt/etc/init.d/asterisk with below(delete previous contents if its not empty)

    source /mnt/root/.profile
    mkdir -p /var/run/asterisk
    mkdir -p /var/spool/asterisk
    mkdir -p /var/log/asterisk/cdr-csv
    /opt/usr/sbin/asterisk -C /opt/etc/asterisk/asterisk.conf

    And run
    chmod a+x /opt/etc/init.d/asterisk
    ln -s /opt/etc/init.d/asterisk /opt/etc/init.d/S95asterisk

That's all. Enjoy Asterisk and happy VoIP!

15 comments:

Kevin said...

Great blog!

Any chance you can write a tutorial on using ushare? I tried following the DD-WRT tutorial and so far I'm stuck at trying to run it.
My error:

Interface ath0 is down.
Recheck uShare's configuration and try again !
ioctl: Cannot assign requested address

Ath0 is the wireless interface.

Anonymous said...

Please write how to configure opendchub with scripts

Anonymous said...

Thanks for this great blog!
I am considering running Asterisk and/or Wireless Hostspot manager(Chillispot, FreeRadius) on a suitable router. This blog sure shed a light on my choice of router. Do you plan to write a tutorial on configuring the WZR-HP-G300NH as a Wireless Hotspot soon.
Evans, Netherlands

Anonymous said...

Do you have any idea how I could get my Nokia CS-15 3g modem to start on the wzr using dd-wrt?!
On ubuntu I had the same problem until I found a post saying I just have to type " eject /dev/sr1 " in the terminal! And it works great there!
Could it be that simple on the wzr too? What should the commandline look like ?
I´m not an expert on linux but I´m not a retard either :P

Magnus, Finland

Anonymous said...

sounds great - does having the VOIP system affect the quality of the VPN system at all? im concerned that it will become a bit too much to handle for a small office (4 pcs 2 sip phones)

Anonymous said...

Can anyone help please... i'm new and i get this error..

root@DD-WRT:/opt# opkg install asterisk16
Collected errors:
* make_directory: Cannot create directory `//usr/lib/opkg': Read-only file system.
* make_directory: Cannot create directory `/usr/lib/opkg': Read-only file system.
* make_directory: Cannot create directory `//usr/lib/opkg': Read-only file system.
* opkg_install_cmd: Cannot install package asterisk16.
root@DD-WRT:/opt#


Thanks in advance.

Afshin said...

When I'm trying to run this command: "opkg install asterisk16", dd-wrt says that "-sh: opkg: not found". I have dd-wrt v24 sp2 installed on my router. Can you help me plz?

Anonymous said...

It would be great if this would work...
In my case when I start asterisk I get huge number of messages like:

loader.c:726 inspect_module: Module 'func_timeout.so' was not compiled with the same compile-time options as this version of Asterisk.

loader.c:727 inspect_module: Module 'res_adsi.so' will not be initialized as it may cause instability.


As result of this... or may be something else I can not load dial plan.
So "dialplan reload" is not valid command with OpenWRT asterisk. If I use "dialplan show" -- my dial plan is not there.

So I can not get working what works fine in Asterisk 1.6 on my desktop.

Anybody was able to get this working???

go4download said...

Great list, just give me a couple of new ideas on what to do next!
hp p1505 driver

Anonymous said...

Can anyone put here some working sip.conf and extension.conf for several interior phones and for multiple SIP-VSP (voice service provider) accounts ?

Angela Navejas said...

I followed step by step and was able to pass through a D-Link DIR-857. My internet works, but my second box gets on TV, but can not pause, record or records access ect. After 3 hours with the support of TELUS, there was an impasse. Anyone else having this problem?

Norton Antivirus Support | Mcafee Antivirus Support

Gear Oillubricants said...

Gear oil if you want oil products for your CNC products you can purchase from us.

Angela Navejas said...

Nice info ! There are many people who are using tech support services and their experience is great.

Norton Antivirus Security Scan | McAfee Antivirus Security Scan

Anonymous said...

nice tutorial !

Voip Sip Client

Ashiq mahmud said...

Hey, Your post is very informative and helpful for us. In fact i am looking this type of article from some days. Thanks a lot to share this informative article.
You can also see this MicFlip: World's First Reversible Micro USB Cable .

Thanks

Post a Comment