Gentoo Wiki ArchivesGentoo Wiki

Asterisk

This article is still a Stub. You can help Gentoo-Wiki by expanding it.

Contents

Installation

Take a quick look at your USE flags as they relate to those packages and their dependencies. Check out the output of:

emerge -pv asterisk

You'll probably want to have mmx, and whichever of alsa/oss your soundsystem uses. If you have a 2.6 kernel, and yet still use devfs, you'll also need devfs26. If you're using a zaptel card, set zaptel. If you use pri lines set pri, for ISDN set bri. Everything else should be pretty self-explanatory. I had some trouble getting MOH and other sounds from Asterisk working correctly without the rtc, so just to be sure enable that one too!

Now you're ready to build:

emerge -av asterisk

You will probably want to do as the output from emerge suggests and allow iptables to set the ToS (Type of Service):

iptables -A OUTPUT -t mangle -p udp -m udp --dport 5060 -j DSCP --set-dscp 0x28
iptables -A OUTPUT -t mangle -p udp -m udp --sport 10000:20000 -j DSCP --set-dscp 0x28

If there is an error or you don't have the table mantle, then give this command:

iptables -I INPUT 1 -p udp -m udp --dport 5060 -j ACCEPT
iptables -I INPUT 1 -p udp -m udp --dport 10000:20000 -j ACCEPT

If you built the zaptel drivers, load them. You'll need to modprobe at least two modules, 'zaptel' and one or more dependent on what type of card you have. I'm not going to list them all here, because there's already a perfectly good description at voip-info. Don't bother with anything above the large heading "Install"...we've already taken care of the compile. Anyway, here are the commands if you've just got a cheapo $7-from-ebay fxo card like me:

modprobe zaptel
modprobe wcfxo

If you don't have an fxo card, load ztdummy instead. Astersik seems to require a timing interface that is created by the hardware devices. ztdummy creates this timing interface without any hardware.

It's probably worth noting that at no point did I have to edit anything to make these load on boot. I don't know whether maybe coldplug/hotplug took care of it, or what. But perhaps you want to reboot at some point and see if lsmod shows them loaded afterwards. If not, it'd be wise to add them to /etc/modules.autoload.d/kernel-2.x so that they load up on boot.

Note, if your card requires a firmware installation, you must emerge hotplug before it will work!

I did experience one problem with this part. At first the zaptel module wouldn't load, saying something about an undefined symbol, and recommending I look at dmesg. So I did, and dmesg showed "modprobe zaptel: Unknown symbol crc_ccitt_table." A quick:

grep -i crc /usr/src/linux/.config

Showed "# CONFIG_CRC_CCITT is not set" ...obviously the culprit. If this happens to you, you can either edit the .config directly and change that to "CONFIG_CRC_CCITT=y" or "CONFIG_CRC_CCITT=m" or you can use 'make menuconfig' and change it under "Library Routines" -> "CRC-CCITT functions" ...and then recompile your kernel. If you compiled it as a module, load it, otherwise reboot.

Starting Up

At this point, you should be able to start and stop asterisk like any other service, using these:

/etc/init.d/asterisk start
/etc/init.d/asterisk stop

If you'd like to add options to asterisk when it starts, you can add them in /etc/conf.d/asterisk ...to see a list of all the available options, use:

asterisk -h

Mostly though, those won't be necessary once the server is configured the way you want, and until then you probably don't want to start it from the init.d scripts anyway. Instead, running it with:

sudo -u asterisk asterisk -vvvvvc

will give you high verbosity and an asterisk terminal, where you can view/change your dialplan and channels and such, reload configs, etc. Go ahead and start the server with that command before you edit any configs, and make sure you aren't getting errors. If you are, poke around at the things they complain about, and maybe hit up #asterisk on irc.freenode.net, where people are very friendly and helpful.

The only error I got while starting it was one about chan_oss.so, which complained that something was already using the sound device. This was because I built my kernel with alsa support instead of oss; asterisk by default expects the reverse. This is easily corrected by editing /etc/asterisk/modules.conf ...there are two lines in the config file that look like this:

noload => chan_alsa.so
;noload => chan_oss.so

Remove the semicolon from the beginning of the oss line and add one to the beginning of the alsa line, and you should be good to go. Obviously if you have oss support in your kernel you'll want to skip that.

On my system, I've had problems when speex was enabled. Asterisk (v 1.0.10 & 1.2.1) would crash on initialization of speex. To solve this problem, I added the following to modules.conf

noload => codec_speex.so

Phones!

Ok. Once you've got the asterisk server starting without error, we can start adding channels. I started "on the inside" by adding phones. To save LOT of time (and hair) standalone HW SIP phones are HIGHLY recommended for beginners. Specifically, I added the free (as in beer) softphone "xlite" first, because it was free and there seemed to be adequate community knowledge of making it work with Asterisk. Xlite now also has the advantage that it's available for Windows, Linux and Mac. Since Xlite is not in portage, and its download is precisely hidden, it should be also possible to use "in portage" SIP phones like kphone, minisip, or mythphone (plugin of mythtv). Update Xlite is in portage net-misc/x-lite but at time of writing is masked on ~x86 at least, installing on amd64 is mentioned at X-lite - JG 18 June 2007

I'm not going to get too deep in the theory here. I suggest heading to this page at some point for an in-depth discussion, but that can wait until we've started having fun. For now, let's just say that a channel is anything that asterisk talks to; a phone (SIP/analog+fxs/IAX/etc.), a PSTN line out (fxo/PRI/ISDN/T1), or a VoIP provider (broadvoice/nufone/etc.)...and that we edit these in .conf files named for the type of channels we're describing.

For my xlite phone, which uses SIP, the file in question is the shockingly-named /etc/asterisk/sip.conf which already contains a (commented out) section beginning with [xlite1]. I don't think I needed to edit this section as much as I did....I had trouble getting it working and tried adding several things before realizing my error, which was not changing the aforementioned [xlite] line to [1234] ....1234 being the extension of the phone. So, make sure you put the phone extension inside those brackets to replace 'xlite1' In the end.

Note: It is not at all necessary to replace the [xlite1] with the extension [1234]. It is only important, that the sections name in the square brackets is the same as the username. And of course you have to refer this one as xlite1 instead of 1234 in the dial plan then.

Here's what my channel looked like:

File: /etc/asterisk/sip.conf
[1234]
type=friend
auth=md5
username=1234
secret=chooseapassword
callerid="First Extension" <1234>
host=dynamic
;This below should be an error (Commented out)
;nreinvite=no
canreinvite=no
disallow=all
allow=gsm
allow=ulaw
allow=alaw

That's all you need on the server. If asterisk is already running and you have its terminal open, type:

/etc/init.d/asterisk reload

to load the new config. Meanwhile you can download xlite. You can download it from xten and installation is self-explanatory. Once installed, you need to open up the menu and go to "Advanced System Settings" -> "Audio Settings" -> "Silence Settings" -> "Transmit Silence" and set to "Yes". Then head to "System Settings" -> "SIP Proxy" -> "default" where you need to input the following:

Display Name: First Extension
User Name & Authorization User: 1234
Password: chooseapassword
Domain/Realm: x.x.x.x
SIP Proxy: x.x.x.x

In this case x.x.x.x is your asterisk server's IP. When you get this all input, the phone should login automatically and notify you that it's extension 1234, and on the asterisk server you should see messages indicating that the phone registered. If it fails to register, it should give a message that either shows and obvious error (username != extension, etc.)

Now comes the fun part. Make sure you've got speakers/headphones and a mic, and use the softphone to dial 1000. Hopefully, you'll get a really cool demo that lets you dial a bunch of extensions and mess around with the server. I especially recommend dialing 500 to do an interasterisk exchange to digium's server. Then you can navigate their phone tree, and if you like even speak with a customer service rep. They didn't seem to mind me calling them just to ask how I sounded....I expect they must get that a lot ;-)

Once you've tired of the single-phone gig, add another extension. Just cut/paste the first phone's section of sip.conf and change the username and password, and you can add another xlite phone. The natural thing to do after that is to try to call one phone from the other; try it out, but don't expect much...it didn't work at all for me, and I got some really strange and inconsistent behavior.

If it doesn't work for you either, it is possible that your xten sip softphone is behind a firewall or NATted or something. I had a lot of issues with the SIP protocol at first. But after I set the option "nat=yes" in the xten phone channel definition in the SIP.conf file, all the issues disappeared. I didn't even have to open any ports on the sip softphone side's firewall. What is important though, is that your server has the SIP and RTC protocol ports opened up. Anyway your config file would look something like this:

File:
[1234]
type=friend
auth=md5
username=1234
secret=chooseapassword
callerid="First Extension" <1234>
host=dynamic
nreinvite=no
canreinvite=no
disallow=all
allow=gsm
allow=ulaw
allow=alaw
nat=yes

kphone

I tried this with kphone, and this is what i had to do to make it work:

File:
[1111]
type=friend
username=1111
callerid="First Extension" <1111>
host=dynamic
canreinvite=no
disallow=all
allow=gsm
allow=ulaw
allow=alaw

That's all you need on the server. If asterisk is already running and you have its terminal open, type:

  reload

to load the new config.

In the kphone options add the standard settings

File:
Full Name = 1111 (Don't know about this one?)
User part = 1111
host part = x.x.x.x (address of asterisk server. for me this was 127.0.0.1)
authentication username = 1111

Everything else i left blank. After clicking register, the registration showed up in the asterisk console

IAX protocol and phones

If you are tired of messing around with ports on your firewall to get those SIP and RTP protocols through, give the IAX (pronounced "eeeeks") protocol a try. It's the Asterisk built-in VOIP protocol (Inter Asterisk eXchange protocol). It's very easy to get it working through firewalls because it uses one single port (4569) for everything. The drawback at the moment is that because it is a relatively new protocol, there are not too many softphones around yet (let alone hardware phones). But there is a pretty good softphone, called Idefisk in development (currently beta versioned) at AsteriskGuru.com.

Dumbing Down Your Dialplan

We've got channels. But clearly, asterisk doesn't know how to properly connect them. This is where the magic of the whole PBX deal lies....routing calls. The instructions you give it for how to do this are found in the file /etc/asterisk/extensions.conf and are commonly referred to as the dialplan. The version of extensions.conf that come with the asterisk build was beyond my grasp...it had a whole bunch of stuff going on, and I couldn't really make sense of it. So I more or less started over. I moved extensions.conf to extensions.conf.old and started a new one from scratch. Brace yourself, this is perhaps as basic as it gets:

 [general]
 static=yes
 writeprotect=yes

 [globals]

 [default]
 exten => 1234,1,Dial(SIP/1234,20)
 exten => 1234,2,Voicemail(1234)

 exten => 1235,1,Dial(SIP/1235,20)
 exten => 1235,2,Voicemail(1235)
 

Save that, reload the configs, and dial one extension from the other. Hopefully you can now carry on conversation between the phones, or leave voicemail if no one answers within 20 seconds.

That's all I've got for now. I'm aware that this doesn't let you make outgoing calls yet....when I get there, I'll let you know. I'll revisit this page and add more useful information as I come across it. This is all probably pretty basic and noobish, but that's life. Hope it helps somebody get started.

Mailboxes

I'm sure you sometimes sleep or leave home, mailboxes are a good idea if you want your friends to be able to leave some messages. Mailboxes are configured in /etc/asterisk/voicemail.conf, lets take a look at this config file.

First, the general section, here you can set system wide voicemail configurations. The first one is format which is used to determine in which format files are saved, 3 formats are available :

gsm : Raw gsm encoding (VOIP suggested)
wav : MS wav, 16 bits
WAV : MS wav, gsm encoded

Second is the serveremail option, wich sets email address from where new message notification are originating from. Used with append=yes, messages are also attached with the e-mails !!! Now lets look at a sample voicemail.conf file :

 [general]
 format=gsm|wav               ;Saves the files in both gsm and wav format
 serveremail=AsteriskHome     ;Sets the address from wich emails are originating from
 append=yes                   ;Sends the audio files attached with email notification
 maxmessage=30                ;Sets, in seconds, the maximum duration of a message
 maxgreet=45                  ;Sets, in seconds, the maximum duration of a greetings message

 [default]                     ;Sets the default section, you can have multiple sections
 1234 => 4321,Your name,yourmail@yourprovider.com    ;Adds a box numbered 1234 using password 4321 for "Your name"
 1235 => 5321,Your name two,yourmail2@yourprovider.com   ;Adds a box numbered 1235 using password 5321 for "Your name two"

 [sectiontwo]                  ;Sets a second section
 1324 => 4231,Your name three,yourmail3@yourprovider.com   ;Adds a box numbered 1324 using password 4231 for "Your name three"
 


Great !! We now have three mailboxes, one titled 1234,another one titled 1235 and a final one titled 1324, they are set to start (in the previously made dialplan) after 20 seconds. Your friends (If you have some ;)) Can now leave you voice messages ! But wouldn't it be cool if you could listen to them, modify some options for your mailbox or even record your own personnal greeting message ??? Lets add a little something to our dialplan (*98 is a standard extension for voicemail access) :

 [general]
 static=yes
 writeprotect=yes

 [globals]

 [default]
 exten => 1234,1,Dial(SIP/1234,20)
 exten => 1234,2,Voicemail(1234)

 exten => 1235,1,Dial(SIP/1235,20)
 exten => 1235,2,Voicemail(1235)

 exten=>*98,1,VoiceMailMain(${CALLERIDNUM}@${CONTEXT})   ;This automatically calls the right mailbox using the ${CALLERIDNUM} variable in the current context (var ${CONTEXT}).

 [sectiontwo]
 exten=>*98,1,VoiceMailMain(s1324@sectiontwo)  ;Adding ''s'' in front of the mailbox number makes the password useless
 

Voila ! We now have two active SIP users who can talk to each other and leave messages plus an unused mailbox in the sectiontwo context.

See Also

Retrieved from "http://www.gentoo-wiki.info/Asterisk"

Last modified: Tue, 09 Sep 2008 11:24:00 +1000 Hits: 63,196

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.