Roll Your Own: Part 3 – Asterisk Configuration

(previous)

With Asterisk installed and sipgate and Google Voice configured, it’s time for the meat and potatoes of this whole thing: configuring Asterisk.

safe_asterisk
Before we get into the configuration, though, we need to make a quick security change. We’ll be using safe_asterisk to start asterisk as a daemon, because it will automatically restart Asterisk in case it crashes for some reason. The safe_asterisk script, however, has a fairly serious security flaw out of the box, and we need to patch it.

  1. Open /usr/sbin/safe_asterisk in your favorite text editor and comment out the TTY=9 line.
    # vim /usr/sbin/safe_asterisk
    #!/bin/sh
    # vim:textwidth=80:tabstop=4:shiftwidth=4:smartindent:autoindent
    CLIARGS="$*" # Grab any args passed to safe_asterisk
    TTY=9 # TTY (if you want one) for Asterisk to run on
    …becomes…
    #!/bin/sh
    # vim:textwidth=80:tabstop=4:shiftwidth=4:smartindent:autoindent
    CLIARGS="$*" # Grab any args passed to safe_asterisk
    #TTY=9 # TTY (if you want one) for Asterisk to run on
  2. Start Asterisk with safe_asterisk
    # safe_asterisk

Asterisk Configuration
Now that Asterisk is running, we need to get everything configured for our calls to work. If you’re not familiar with Asterisk Configuration, you may want to check out the wiki at Voip-Info.org (search for the file you’re working on) or the Asterisk Documentation Project for some good references.

  1. Before we begin our configurations, we’ll make backup copies of the samples of the configuration files we’ll change
    # cd /etc/asterisk
    # mv extensions.conf extensions.sample
    # mv sip.conf sip.sample
    # mv voicemail.conf voicemail.sample
    # mv features.conf features.sample
  2. We also need to a little bit of planning at this point. You’ll need to decide how you want to setup your dialplan. In this example, we’re going to use four digit internal extension numbers, with the names of SIP peers set to their extension numbers. You’re free to change this to suit your needs or wants, and I’ll try and point out all the things you will need to change from these examples.

SIP Configuration
The first thing we’ll configure is our SIP settings. We’ll need to configure Asterisk to connect to sipgate, and also configure Asterisk to accept connections from a phone. In this and any other examples 9999999e1 is your sipgate SIP-ID and AAAA1A is your sipgate SIP-Password.

  1. Create the file /etc/asterisk/sip.conf in the text editor of your choice.
  2. Add this to the beginning of the new file:
    [general]
    register => 9999999e1:AAAA1A@sipgate.com/9999999e1

    The [general] section of sip.conf is where configuration options that apply to all SIP peers are set. It is also where register statements are placed. Register statements allow Asterisk to connect as a client to other SIP servers. We connect to sipgate with a register statement so that calls coming into our sipgate number come to Asterisk.
  3. Add this block below the previous one:
    [sipgate]
    type=peer
    host=sipgate.com
    outboundproxy=proxy.live.sipgate.com
    insecure=invite
    qualify=yes
    dtmfmode=rfc2833
    username=9999999e1
    defaultuser=9999999e1
    fromuser=9999999e1
    fromdomain=sipgate.com
    secret=AAAA1A
    context=incoming
    disallow=all
    allow=ulaw

    This [sipgate] section of sip.conf configures the options to use for the sipgate connection. These options are all specified by sipgate.
  4. Add this last block below the [sipgate] section:
    [1000]
    type=friend
    host=dynamic
    nat=yes
    qualify=yes
    context=internal
    defaultuser=1000
    secret=1000
    callerid="Your Name" <1000>
    mailbox=1000

    This section defines the configuration for our SIP phone to connect to Asterisk at extension 1000.
  5. Save the file as /etc/asterisk/sip.conf . Now, connect to the running Asterisk daemon to get to the Asterisk CLI
    # asterisk -rvvv
  6. At the Asterisk command prompt, reload the SIP configuration. Most configuration changes in Asterisk don’t require restarting Asterisk, but simply reloading the configuration files that have been changed.
    asterisk*CLI> sip reload
    Reloading SIP
    == Parsing '/etc/asterisk/sip.conf': == Found
    == Parsing '/etc/asterisk/sip_notify.conf': == Found
    asterisk*CLI>
  7. Now we’ll setup our SIP phone to connect to Asterisk. Use 1000 in place of your sipgate SIP-ID and SIP-Password, and the hostname or IP of your server in place of sipgate.com in the phone’s configuration.
  8. Let’s make sure our SIP configuration is working properly.
    asterisk*CLI> sip show registry
    Host dnsmgr Username Refresh State Reg.Time
    sipgate.com:5060 N 1207176e0 105 Registered Tue, 20 Apr 2010 19:16:08
    1 SIP registrations.
    asterisk*CLI> sip show peers
    Name/username Host Dyn Nat ACL Port Status
    1000/1000 10.13.10.85 D N 5060 OK (50 ms)
    sipgate-kenny/9999999e1 172.16.17.10 5060 OK (45 ms)
    2 sip peers [Monitored: 2 online, 0 offline Unmonitored: 0 online, 0 offline]
    asterisk*CLI>

    If you don’t have 1 registration and 2 peers showing up, there’s something amiss, and you’ll need to look into it.

Next we’ll configure voicemail.conf and features.conf… (continue)

This entry was posted in Computers and other Gadgety-Type Things. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>