Install Asterisk
From Joe's Wiki
Contents |
Purpose of this page
The purpose of this page is to show you how to setup Asterisk in Ubuntu. This assumes a basic knowledge of how Ubuntu and Linux work -- if you don't, use trixbox or AsteriskNow. I try to be as detailed as I can about how to setup Asterisk in Ubuntu; generic stuff about Asterisk, FreePBX, and setting up phones I leave to the multitude of tutorials out there. If there's something important that's missing, if anything here is just plain wrong, or if you know a better way, feel free to edit it or to contact me.
References
Using these as a basis: VOIP Phreak Guide Asterisk on Ubuntu
Some things to keep note of
I'm not going to worry about keeping version numbers up to date. If I ask you to download something that includes a version number, or cd into a directory with a version number, please use the latest version (except Asterisk -- use 1.4 of Asterisk, as FreePBX doesn't support 1.6 yet). If you see a wrong version number, please update it.
This configuration will need the following ports to be accessible to the outside world:
- 5060 (sip)
- 10000-10100 (rtp)
and optionally:
- 22 (to allow remote ssh access)
- 80 (to allow remote web access)
You can forward these ports using your router, or set the asterisk server as the DMZ server for your router (if you set it DMZ, you really really want to set up Shorewall firewall
Your asterisk server (and enum, if you choose to set it up) will need to be able to figure out your public IP. If you have a static ip, great, no problems. If you have a dynamic IP, that's OK, but you need a dynamic domain. You can get one from DynDNS or noip.com. Hopefully, your router supports one or both of those dynamic domain providers, or a different one. If it does, I recommend setting this up in your router. If it doesn't, you can always install ddclient. See the Ubuntu wiki for instructions on Dynamic DNS.
Install needed packages
sudo apt-get install cvs build-essential automake autoconf bison flex libtool libncurses5-dev libssl-dev php5 php5-cli \ php5-curl php5-gd php5-mysql mysql-server php-pear php-db curl sox apache2 subversion libssl-dev libmysqlclient15-dev \ libxml2-dev
Install Shorewall
Note: These instructions are for installing the Shorewall firewall, to help protect your Asterisk system (which you should do!). If you have your own firewall, or are only going to NAT the asterisk specific ports to your router, go right ahead and skip this step.
Note 2: These instructions also assume that you are using a server with a) 1 ethernet card, b) on the network 192.168.1.* . Changing your subnet should be pretty straight forward; if you want to use multiple NICs, contact me. It changes things both here and a boatload of other places.
Shorewall is a really awesome front end to ip tables. These are basic instructions for a configuration only using this server as an asterisk server. For more info on Shorewall, including what any of this means, and how to extend this configuration to work with other stuff, you can see Shorewall's website
Install Shorewall firewall.
sudo apt-get install shorewall
/etc/shorewall/zones
#ZONE TYPE OPTIONS IN OUT # OPTIONS OPTIONS fw firewall net ipv4 loc:net ipv4 # this allows you to have two different zones (internet and local) on the same interface
/etc/shorewall/interfaces
#ZONE INTERFACE BROADCAST OPTIONS net eth0 255.255.255.0 dchp,routeback
/etc/shorewall/hosts
#ZONE HOSTS loc eth0:192.168.1.0/24 # set this to be your local subnet. If it's 10.10.10.*, make this 10.10.10.0/24
/etc/shorewall/policy
#SOURCE DEST POLICY LOG LEVEL LIMIT:BURST loc $FW ACCEPT $FW all ACCEPT net all DROP info all all REJECT info
/etc/shorewall/rules
#ACTION SOURCE DEST PROTO DEST SOURCE ORIGINAL # PORT PORT(S) DEST ACCEPT all all tcp 5060 ACCEPT all all udp 5060 ACCEPT all all tcp 10000:10100 ACCEPT all all udp 10000:10100 #ACCEPT all $FW tcp 22 #if you want ssh from the outside world, uncomment this line #ACCEPT all $FW tcp 80 #ditto for web access
Then to start (have physical access to the server before doing this. You will probably lock yourself out.) edit /etc/default/shorewall . Find this
# prevent startup with default configuration # set the following varible to 1 in order to allow Shorewall to start startup=0
Change startup=0 to startup=1
sudo /etc/init.d/shorewall start
Install Asterisk
Lets get some things set up
sudo adduser --system --home /var/lib/asterisk --group asterisk sudo mkdir /var/run/asterisk sudo chown -R asterisk:asterisk /var/run/asterisk
Download Linux Headers
sudo apt-get install linux-headers-`uname -r` sudo ln -s /usr/src/linux-headers-`uname -r` /usr/src/linux-2.6
Download Asterisk and addons
wget http://downloads.digium.com/pub/asterisk/asterisk-1.4-current.tar.gz wget http://downloads.digium.com/pub/asterisk/asterisk-addons-1.4-current.tar.gz tar -xzf asterisk-1.4-current.tar.gz tar -xzf asterisk-addons-1.4-current.tar.gz
DAHDI (necessary if you're going to be using conference rooms)
sudo apt-get install dahdi-dkms sudo nano -w /etc/modules
Add dahdi-dummy to the list, save.
Download Sounds
CODECS=( alaw g722 g729 gsm ulaw wav); for i in ${CODECS[@]}; \
do wget http://downloads.digium.com/pub/telephony/sounds/asterisk-core-sounds-en-$i-current.tar.gz; \
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-extra-sounds-en-$i-current.tar.gz; done
Install Asterisk
cd asterisk-1.4.23.1 # or whatever the latest version is ./configure nano -w Makefile (change all instances of "ASTVARRUNDIR=<something>" to "ASTVARRUNDIR=/var/run/asterisk". If you know a better way, please point it out) make sudo make install
If this a first time install, do:
sudo make samples
Now for asterisk-addons:
cd ../asterisk-addons-1.4.7/ # or whatever the latest version is ./configure make sudo make install
Once again, we can do sudo make samples
cd ~ for i in `ls asterisk-core-sounds-en-*`; do sudo tar -xzf $i -C /var/lib/asterisk/sounds/; done for i in `ls asterisk-extra-sounds-en-*`; do sudo tar -xzf $i -C /var/lib/asterisk/sounds/; done
Additional setup
We need to tell Asterisk to only use rtp ports 10000 - 10100. If you're some crazy telephony wiz kid you needs more that 100 simultaneous voice channels, increase this port range higher (up to 20000 if you want), and in both your router forwarding / firewall rules.
sudo nano -w /etc/asterisk/rtp.conf
change to:
rtpstart=10000 rtpend=10100
Now we need to tell Asterisk your IP address, so it addresses SIP packets correctly both inside and outside your network.
sudo nano -w /etc/asterisk/sip_nat.conf
externip=45.62.227.168 # your best guess at your external IP. Your current one works localnet=192.168.1.0/255.255.255.0 # unless you know what a netmask is, you should only need to change the first part to your local subnet externhost=joe.foobardns.com # the dynamic dns domain you set up earlier. You did that, right? externrefresh=10 # how often to refresh your external domain to get your ip.
mysqladmin -uroot -p create asterisk create asteriskcdrdb echo "GRANT ALL PRIVILEGES ON asterisk.* TO asterisk@localhost IDENTIFIED BY '<asteriskpassword>';" | mysql -u root -p echo "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asterisk@localhost IDENTIFIED BY '<asteriskpassword>';" | mysql -u root -p Configure Asterisk Files: sudo nano -w /etc/apache2/apache2.conf User asterisk Group asterisk sudo nano -w /etc/asterisk/asterisk.conf astrundir => /var/run/asterisk sudo nano -w /etc/php5/apache2/php.ini sudo nano -w /etc/php5/cli/php.ini post_max_size = 20M upload_max_filesize = 20M magic_quotes_gpc = Off memory_limit = 100M sudo /etc/init.d/apache2 restart
Install the asterisk init file.
sudo nano -w /etc/init.d/asterisk
Copy the init file from here, save.
sudo chmod +x /etc/init.d/asterisk sudo chown -R asterisk:asterisk /var/spool/asterisk/ /var/log/asterisk/ sudo update-rc.d asterisk defaults sudo /etc/init.d/asterisk start
Setup Freepbx
wget http://mirror.freepbx.org/freepbx-2.5.1.tar.gz tar -xzf freepbx-2.5.1.tar.gz cd freepbx-2.5.1/ mysql -uroot -p asterisk < SQL/newinstall.sql mysql -uroot -p asteriskcdrdb < SQL/cdr_mysql_table.sql sudo ./install_amp
Now the FreePBX Install wizard
Enter your USERNAME to connect to the 'asterisk' database: [asteriskuser] asterisk Enter your PASSWORD to connect to the 'asterisk' database: [amp109] <asteriskpassword> Enter the hostname of the 'asterisk' database: [localhost] localhost Enter a USERNAME to connect to the Asterisk Manager interface: [admin] <hit enter> Enter a PASSWORD to connect to the Asterisk Manager interface: [amp111] <hit enter> Enter the path to use for your AMP web root: [/var/www/html] /var/www Enter the IP ADDRESS or hostname used to access the AMP web-admin: [xx.xx.xx.xx] <hit enter> Enter a PASSWORD to perform call transfers with the Flash Operator Panel: [passw0rd] <hit enter> Use simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]? [extensions] <hit enter> Enter directory in which to store AMP executable scripts: [/var/lib/asterisk/bin] <hit enter> Created /var/lib/asterisk/bin Enter directory in which to store super-user scripts: [/usr/local/sbin] <hit enter>
Now go to the IP of your server in firefox, and click the FreePBX admin link
- Go to Tools -> Module Admin
- Click Check for Updates Online
- Click Upgrade All
- Click Process, then Confirm
Apply Configuration Changes
Now that we've made changes, we need to apply them. At the top is an orange button that says Apply Configuration Changes. Whenever we make changes to FreePBX, we need to click that to make them live with Asterisk. Whenever I say Apply Configuration Changes, do this:
- Click that button
- Click Continue with Reload in the box that comes up.
That's it. This is necessary whenever you're done making changes you want to make live, so you'll need to get used to it.
Tighten the Notches
- Still in Freepbx, go to the Tools tab
- Under Basic, go to the Administrators section
- Click admin in the users list at the right.
- Fill in a new password for admin (you'll need this username and password to edit FreePBX's settings from now on)
- Click Submit Changes at the bottom
- Apply Configuration Changes
You'll notice that it says that because the AUTHTYPE is not set to database, nothing we do here makes any difference. Well, let's fix that!
sudo nano -w /etc/amportal.conf find this: AUTHTYPE=none change it to: AUTHTYPE=database
If you refresh, it shouldn't give you that warning anymore.
Now that we've set up FreePBX to actually require a password, let's change the manager password for Asterisk. This isn't entirely necessary, but will make you feel better.
sudo nano -w /etc/asterisk/manager.conf change this: [admin] secret = amp111 to this: [admin] secret = <yoursupersecretasteriskpassword> sudo nano -w /etc/amportal.conf change this: # AMPMGRPASS: the password for AMPMGRUSER AMPMGRPASS=amp111 to this: # AMPMGRPASS: the password for AMPMGRUSER AMPMGRPASS=<yoursupersecretasteriskpassword> sudo /etc/init.d/asterisk restart

