Asterisk config example

Someone asked for a copy, so here’s an edited copy of my Asterisk extensions.conf file. I changed most of the email addresses to user@example.com, and replaced parts of specific phone numbers with ‘9999’, but other then that, it’s essentially the same. There’s some legacy cruft in here, and parts of it are overly complex. It implements a few features that you don’t strictly need in most setups. particularly the 10-digit dialing bit that makes ‘1’ for long distance optional.

Here it is, warts and all:

[general]
  static=yes
  writeprotect=no

[globals]
  TRUNK=Zap/1                           ; FXO interface
  ANALOG=Zap/2                          ; FXS interface

  SCOTTSIP=Sip/2202
  CYNSIP=Sip/2203
  KITSIP=Sip/2204
  NUFONE=IAX2/account@NuFone
  PHONES=${ANALOG}&${SCOTTSIP}&${CYNSIP}&${KITSIP}

; Fax receiving macro.  Handles rxfax and directing the fax to the 
; correct email address.
[macro-faxreceive]
  exten => s,1,SetVar(FAXFILE=/var/spool/asterisk-fax/${UNIQUEID}.tif)
  exten => s,2,DBGet(EMAILADDR=extensionemail/${MACRO_EXTEN})
  exten => s,3,rxfax(${FAXFILE})
  exten => s,103,SetVar(EMAILADDR=user@example.com)
  exten => s,104,Goto(3)

; Outside line macro.  This handles incoming phone calls from outside
; of the house, including caller-ID rewriting, blacklisting, and
; distinctive ring.
[macro-outsideline]
  exten => s,1,SetCDRUserField(Outside (${CHANNEL}))
  exten => s,2,LookupCIDName
  exten => s,3,SetMusicOnHold(random)
  exten => s,4,Macro(setalertinfo)
  exten => s,5,LookupBlacklist
  exten => s,6,Dial(${PHONES},13,Ttmr)
  exten => s,7,Answer
  exten => s,8,Goto(outside-ivr,s,1)
  exten => s,106,Goto(206)
  exten => s,107,Goto(7)
  exten => s,206,Wait(3600)
  exten => s,207,Hangup

; Extension dialing logic.  Call an internal extension and bounce to VM
; if no answer.
[macro-callextension]
  exten => s,1,Dial(${ARG1},30,t)
  exten => s,2,Voicemail(${ARG2})
  exten => s,3,Hangup
  exten => s,102,Voicemail(${ARG2})
  exten => s,103,Hangup

; The next block of macros handle outgoing calls.  This is more complex
; then you'd expect for a couple reasons.  First, I'm using two different
; outgoing mechanisms--NuFone and my POTS line, but I'd like either one
; to be able to work as a fallback if the other fails.
;
; Next, I want to be able to handle 7- and 10-digit dialing without
; having to remember which area codes and prefixes require a '1' first.
; I'm in the Seattle area, and part of 425 is free, along with 95% of
; 206.  With POTS, I must dial a '1' iff it is a toll call.  With
; NuFone I must always dial a 1.
;
; See http://scottstuff.net/scott/archives/000163.html

; This handles 10-digit local numbers
[macro-dialanalogwithfallback]
  exten => s,1,Dial(${TRUNK}/${MACRO_EXTEN})
  exten => s,2,Congestion
  exten => s,102,SetCallerID(4254889999)
  exten => s,103,SetCIDName(LAIRD SCOTT)
  exten => s,104,Dial(${NUFONE}/1${MACRO_EXTEN})
  exten => s,105,Congestion
  exten => s,205,Busy

; This handles 7-digit local numbers
[macro-dialanalogwithfallback425]
  exten => s,1,Dial(${TRUNK}/425${MACRO_EXTEN})
  exten => s,2,Congestion
  exten => s,102,SetCallerID(4254889999)
  exten => s,103,SetCIDName(LAIRD SCOTT)
  exten => s,104,Dial(${NUFONE}/1425${MACRO_EXTEN})
  exten => s,105,Congestion
  exten => s,205,Busy

; This handles 10-digit non-local numbers
[macro-dialanalogwithfallback1]
  exten => s,1,Dial(${TRUNK}/1${MACRO_EXTEN})
  exten => s,2,Congestion
  exten => s,102,SetCallerID(4254889999)
  exten => s,103,SetCIDName(LAIRD SCOTT)
  exten => s,104,Dial(${NUFONE}/1${MACRO_EXTEN})
  exten => s,105,Congestion
  exten => s,205,Busy

; This just dials via POTS without any special handling
[macro-dialanalog]
  exten => s,1,Dial(${TRUNK}/${MACRO_EXTEN})
  exten => s,2,Congestion
  exten => s,102,Busy

; ditto, but for NuFone.
[macro-dialnufone]
  exten => s,1,SetCallerID(4254889999)
  exten => s,2,SetCIDName(LAIRD SCOTT)
  exten => s,3,Dial(${NUFONE}/${MACRO_EXTEN})
  exten => s,4,Congestion

[macro-dialnufonewithfallback]
  exten => s,1,SetCallerID(4254889999)
  exten => s,2,SetCIDName(LAIRD SCOTT)
  exten => s,3,Dial(${NUFONE}/${MACRO_EXTEN})
  exten => s,4,Congestion
  exten => s,104,Dial(${TRUNK}/${MACRO_EXTEN})
  exten => s,105,Macro(fastbusy)
  exten => s,205,Busy

; for 10-digit dialing in non-local areas
[macro-dialnufonewithfallback1]
  exten => s,1,SetCallerID(4254889999)
  exten => s,2,SetCIDName(LAIRD SCOTT)
  exten => s,3,Dial(${NUFONE}/1${MACRO_EXTEN})
  exten => s,4,Congestion
  exten => s,104,Dial(${TRUNK}/1${MACRO_EXTEN})
  exten => s,105,Macro(fastbusy)
  exten => s,205,Busy

; This sets the ALERT_INFO variable based on the CALLERIDNUM
; setting via a lookup in the 'distinctivering' database.  See
; http://scottstuff.net/scott/archives/000163.html
[macro-setalertinfo]
  exten => s,1,DBGet(ALERT_INFO=distinctivering/${CALLERIDNUM})

; This is the 'inside' context, where calls made from inside of the
; house start out.  The 'inside' context (or 'inside-sip'/'inside-analog')
; is referred to in sip.conf and zapata.conf.  That's what ties this all
; together.
[inside]
  include => parkedcalls
  include => operator
  include => e911
  include => forced-analog
  include => information
  include => local
  include => pstn-local10
  include => tollfree
  include => pstn-nonlocal10
  include => international

; There's no real reason for these to exist right now; I could
; just replace the references to them in sip.conf/zapata.conf
; with references to the 'inside' context.  This is kind of 
; historical.
[inside-sip]
  include => inside

[inside-analog]
  include => inside

[operator]
  exten => 0,1,Macro(dialanalog)

[e911]
  exten => 911,1,Macro(dialanalog)
  exten => 9911,1,Macro(dialanalog)

[forced-analog]
  exten => _9.,1,Macro(dialanalog)

[information]
  exten => 411,1,Macro(dialanalog)

; The 'local-extensions.conf' file is autogenerated.  See
; http://scottstuff.net/scott/archives/000163.html and
; http://svn.scottstuff.net/project/asterisk-lca-map/
[pstn-local10]
#include "local-extensions.conf"

[pstn-nonlocal10]
  exten => _NXXNXXXXXX,1,Macro(dialnufonewithfallback1)
  exten => _1NXXNXXXXXX,1,Macro(dialnufonewithfallback)

[tollfree]
  exten => _1888NXXXXXX,1,Macro(dialanalogwithfallback)
  exten => _1877NXXXXXX,1,Macro(dialanalogwithfallback)
  exten => _1866NXXXXXX,1,Macro(dialanalogwithfallback)
  exten => _1855NXXXXXX,1,Macro(dialanalogwithfallback)
  exten => _1800NXXXXXX,1,Macro(dialanalogwithfallback)

  exten => _888NXXXXXX,1,Macro(dialanalogwithfallback1)
  exten => _877NXXXXXX,1,Macro(dialanalogwithfallback1)
  exten => _866NXXXXXX,1,Macro(dialanalogwithfallback1)
  exten => _855NXXXXXX,1,Macro(dialanalogwithfallback1)
  exten => _800NXXXXXX,1,Macro(dialanalogwithfallback1)

[international]
  exten => _011.,1,Macro(dialnufone)

[local]
  exten => 2200,1,Macro(callextension,${PHONES},2201)
  exten => 2201,1,Macro(callextension,${ANALOG},2201)
  exten => 2202,1,Macro(callextension,${SCOTTSIP},2202)
  exten => 2203,1,Macro(callextension,${CYNSIP},2203)
  exten => 2204,1,Macro(callextension,${KITSIP},2201)
  exten => 2205,1,Macro(callextension,${KITSIP},2201)

  exten => 2230,1,Answer
  exten => 2230,2,Wait(5)
  exten => 2230,3,Goto(fax,2201,1)

  exten => 2211,1,Answer
  exten => 2211,2,Goto(outside-ivr,s,1)
  exten => 2211,3,Beep
  exten => 2211,4,Hangup

  exten => 2222,1,Wait,2
  exten => 2222,2,VoicemailMain(s2201)
  exten => 2222,3,Hangup

  exten => 2223,1,Wait,2
  exten => 2223,2,VoicemailMain
  exten => 2223,3,Hangup

[outside-ivr]
  ; This is the outside IVR
  ; Playback a "We're not home message"
  ; To leave a message for Scott, press 1
  ; To leave a message for C, press 2
  ; Otherwise stay on the line.
  ;
  ; Also, 3 => main voicemail
  ;   4 => check voicemail (main)
  ;   5 => check voicemail
  ;
  ; Check for fax, too

  exten => s,1,AppendCDRUserField( -> IVR)
  exten => s,2,DigitTimeout(5)
  exten => s,3,ResponseTimeout(2)
  exten => s,4,Wait(1)
  exten => s,5,Background(laird/ivr-greeting)

  exten => 1,1,AppendCDRUserField( -> 1)
  exten => 1,2,Wait(1)
  exten => 1,3,VoiceMail(us2202)
  exten => 1,4,Hangup

  exten => 2,1,AppendCDRUserField( -> 2)
  exten => 2,2,Wait(1)
  exten => 2,3,VoiceMail(us2203)
  exten => 2,4,Hangup

  exten => 3,1,AppendCDRUserField( -> 3)
  exten => 3,2,Wait(1)
  exten => 3,3,VoiceMail(us2201)
  exten => 3,4,Hangup

  exten => 4,1,AppendCDRUserField( -> 4)
  exten => 4,2,Wait(1)
  exten => 4,3,VoiceMailMain(2201)
  exten => 4,4,Hangup

  exten => 5,1,AppendCDRUserField( -> 5)
  exten => 5,2,Wait(1)
  exten => 5,3,VoiceMailMain
  exten => 5,4,Hangup

  exten => 7,1,AppendCDRUserField( -> 7)
  exten => 7,2,Goto(outside-ivr-7,s,1)

  exten => fax,1,AppendCDRUserField( -> fax)
  exten => fax,2,Answer
  exten => fax,3,Goto(fax,2201,1)

  exten => t,1,AppendCDRUserField( -> timeout)
  exten => t,2,VoiceMail(s2201)
  exten => t,3,Hangup

  exten => i,1,AppendCDRUserField( -> invalid)
  exten => i,2,Playback(tt-allbusy)
  exten => i,3,Goto(s,3)

[outside-ivr-7]
  exten => s,1,AppendCDRUserField( -> ivr7)
  exten => s,2,Wait(1)
  exten => s,3,Background(tt-weasels) ; need to record a better message...

  exten => t,1,Goto(s,1)

  exten => i,1,Goto(s,1)

  exten => 1,1,Dial(Local/12069999991@inside)
  exten => 2,1,Dial(Local/12069999992@inside)
  exten => 0,1,Goto(outside-ivr,s,1)

[fax]
  exten => fax,1,Macro(faxreceive)
  exten => 2201,1,Macro(faxreceive)
  exten => 2202,1,Macro(faxreceive)
  exten => 2203,1,Macro(faxreceive)

  exten => h,1,system(/usr/local/sbin/mailfax ${FAXFILE} ${EMAILADDR} "${CALLERIDNUM} ${CALLERIDNAME}")

; This is where outside calls enter the system, thanks to 
; zapata.conf, sip.conf, and iax2.conf.  By and large, calls are
; directed to the 'outsideline' macro, *except* for the second 
; 866 number; that's just for checking voicemail.
[outside]
  exten => s,1,Macro(outsideline)
  exten => s,2,Hangup
  exten => 4254889999,1,Macro(outsideline)
  exten => 4254889999,2,Hangup
  exten => 8662299999,1,Macro(outsideline)
  exten => 8662299999,2,Hangup

  exten => 8662559999,1,VoicemailMain(2201)
  exten => 8662559999,2,Hangup
  exten => 8662559999/2069999991,1,VoicemailMain(s2201)
  exten => 8662559999/2069999991,2,Hangup
  exten => 8662559999/2069999992,1,VoicemailMain(s2201)
  exten => 8662559999/2069999992,2,Hangup

  exten => fax,1,Goto(fax,2201,1)
  exten => t,1,Hangup
  exten => h,1,Hangup

[outside-analog]
  exten => s,1,Goto(outside,4254889999,1)

[outside-sip]
  include => outside

[outside-nufone]
  include => outside

Posted by Scott Laird Fri, 18 Jun 2004 13:23:15 GMT


Comments

  1. SWS 2 days later:

    Thank you kindly!

  2. Curt about 1 month later:

    Scott,

    I’m having trouble getting my BudgeTone-100 phone talking to my Asterisk PBX. Very simple needs: calls come into PBX via PSTN on FXO, PBX prompts direct caller to extension, extension rings, if no answer or busy go to vmail; and I also need to dial outside (9, ) via my ip phone ;). That’s it.

    Thanks for the extensions.conf sample. Do you have corresponding samples of sip.conf, phones.conf, zapata.conf, anything else?

    Thanks very much !

  3. steve 2 months later:

    It would be beneficial if you could share your sip.conf, iax.conf file and your extensions.conf file. You have done a lot of nice tricks with asterisk and it’s always great to learn from someone like you.

  4. steve 2 months later:

    Scott,

    I was wonder if you had a need or seen an example of how to do a “find me or “follow me” with asterisk. For example, a call comes into asterisk. It rings internal phone as well as a cell phone. You answer the phone and asterisk tells you that you have a call from 999 999 9999 , please 1 to accept, press 2 to send to voice mail, press 3 to hangup,press 4 to forward the call to another number, etc. I think that would be a great feature to try or add to asterisk.

  5. iran 4 months later:

    Could you sent me an example of the table that you used with the DBGET command.

  6. Scott Laird 6 months later:

    I don’t have a Sipura, so I’m not really sure how to configure them. They’re just a SIP device, so Asterisk’s end shouldn’t look very different, but I don’t know what you need to do for the Sipura; I’d recommend sending mail to asterisk-users@lists.digium.com and asking for help with it. Also, look at the voip-info.org wiki–the first 3 answers from asterisk-users are just going to say “did you search the wiki,” so you might as well start there :-).

  7. DummyBoy 9 months later:

    Hi Scott, you are an asterisk expert I see.. I’m trying to develop an automatic redial function for my PBX but I don’t know how to do it…any idea?

    Thanks in advance.

    DummyBoy

  8. Blessen Cherian about 1 year later:

    Hi

    I need help on how to receive calls on my softphone. I have a softphone account with vonage and have installed a Asterisk@home server. I can make calls inside the network but not able to make calls to outside number and not able to receive calls. Can you please help me with this.

    Internet –> Wireless router (WRTP54G) –> My asterisk@home server -> linux clients machines

    Blessen

  9. issac about 1 year later:

    i have difficulties to get stared. i have a TDM11B with port 1-FXS and port-2-FXO. i am trying to make a call from port 1 using the pots line on port 2. i tried your config and many others and can’t get it to work. i see the line up and when i enter any digit i get buy signal. can you help?

  10. Doug about 1 year later:

    Any luck implementing automatic redial on your PBX app? (I assume as a pass-through number dialing in extensions.conf). I’d like the same thing. Please let me know!

    Email me at doug(atsign)scottstuff.con.com

    thanx man

  11. hichamadarnou@hotmail.com about 1 year later:

    I have TDM 422 P , I do the same configuration and I write ‘s’ instead ‘fax’ , and I plug the analog line fxo and other analog line to fax device , so I sent the fax to fxo , the fxs accept the fax
    but I dont receive any mail or file.tif

  12. styde over 2 years later:

    thank u for your help!! I have to configure an IVR under asterisk for a phone operator. your file will help me to begin..as i’m a new comer on the asterisk world..