I’ve had several people ask me for a more recent version of my Asterisk configuration files, and it’s been about a year since I last posted them, so here they are.### extensions.conf

Here’s extensions.conf. I’ve lightly redacted a few phone numbers and deleted a few really obvious bits of cruft, but this is essentially what my Asterisk server is running. There’s at least a year’s worth of cruft lurking in here, but it’s a real, live example:

[general]
  static=yes
  writeprotect=no

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

  KITSIP=Sip/203
  BEDSIP=Sip/204
  BASESIP=Sip/210

  NUFONE=IAX2/username@NuFone
  EBC=IAX2/username@EBC
  PHONES=${ANALOG}&${KITSIP}&${BEDSIP}

; 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=scott@sigkill.org)
  exten => s,104,Goto(3)

; This fixes up incoming CallerID.  NuFone doesn't transmit CID name
; info on incoming toll-free calls.  So, we cache the name when we see
; it and use the cached copy when we can.
; 
; This is kind of close to LookupCIDName, except we also *store* the
; CID Name when we know it.
[macro-cidfix]
  exten => s,1,GotoIf($["${CALLERIDNUM:0:2}" = "+1"]?600)
  exten => s,n(dbget),DBGet(cidfixname=cidname/${CALLERIDNUM})
  exten => s,n,SetCIDName(${cidfixname})
  exten => s,dbget+101,GotoIf($[${CALLERIDNAME} = "Toll-Free Call"]?500:104)
  exten => s,n,GotoIf($["X${CALLERIDNAME}" = "X"]?500:104)
  exten => s,n,DBput(cidname/${CALLERIDNUM}=${CALLERIDNAME})
  exten => s,500,SetCallerID("No Caller ID <Unknown>")
  exten => s,600,SetCIDNum($[${CALLERIDNUM:2:100}])
  exten => s,n,Goto(dbget)

; Conditionally set the CallerID.  If we already have a valid CallerID
; (basically, it's more then 4 digits long), then we leave it in place.
; Otherwise, replace it with our home phone number
[macro-condsetcid]
  exten => s,1,NoOp
  exten => s,2,GotoIf($[${CALLERIDNUM:0:4} = ${CALLERIDNUM}]?3:4)
  exten => s,3,SetCallerID(4254889014)
  exten => s,4,NoOp

; Do call forwarding out of a database.  Look up the caller ID number, 
; and if it exists in the forward DB, then forward the call to the 
; specified number.
[macro-dbcallforward]
  exten => s,1,DBGet(FORWARDTO=forward/${CALLERIDNUM})
  exten => s,2,Macro(condsetcid)
  exten => s,3,Wait(1)
  exten => s,4,Dial(Local/${FORWARDTO}@inside/n)
  exten => s,102,Noop

; 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,AbsoluteTimeout(7200)
  exten => s,2,SetCDRUserField(Outside (${CHANNEL}))
  exten => s,3,Macro(cidfix)
  exten => s,4,Macro(dbcallforward)
  exten => s,5,Macro(setalertinfo)
  exten => s,6,LookupBlacklist
  exten => s,7,Dial(${PHONES},30,Ttr)
  exten => s,8,Answer
  exten => s,9,Goto(outside-ivr,s,1)
  exten => s,107,Goto(208)
  exten => s,108,Goto(8)
  exten => s,207,Wait(3600)
  exten => s,208,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
[macro-diallocal]
  exten => s,1,AbsoluteTimeout(7200)
  exten => s,n,SetAMAFlags(default)
  exten => s,n(analog),Dial(${TRUNK}/${ARG1})
  exten => s,n,Congestion
  exten => s,analog+101,Macro(condsetcid)
  exten => s,n,SetCIDName(LAIRD SCOTT)
  exten => s,n,SetAMAFlags(billing)
  exten => s,n(nufone),Dial(${NUFONE}/1${ARG1})
  exten => s,n,Congestion
  exten => s,nufone+101,Busy

; This handles 10-digit local numbers
[macro-dialanalogwithfallback]
  exten => s,1,Macro(diallocal,${MACRO_EXTEN})

; This handles 7-digit local numbers
[macro-dialanalogwithfallback425]
  exten => s,1,Macro(diallocal,425${MACRO_EXTEN})

; This handles 10-digit non-local numbers
[macro-dialanalogwithfallback1]
  exten => s,1,Dial(${TRUNK}/1${MACRO_EXTEN})
  exten => s,2,Congestion
  exten => s,102,Macro(condsetcid)
  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,Macro(condsetcid)
  exten => s,n,SetCIDName(LAIRD SCOTT)
  exten => s,n,SetAMAFlags(billing)
  exten => s,n,Dial(${NUFONE}/${MACRO_EXTEN})
  exten => s,n,Congestion

[macro-dialnufonewithfallback]
  exten => s,1,Macro(condsetcid)
  exten => s,n,SetCIDName(LAIRD SCOTT)
  exten => s,n,SetAMAFlags(billing)
  exten => s,n(nufone),Dial(${NUFONE}/${MACRO_EXTEN})
  exten => s,n,Congestion
  exten => s,nufone+101,SetAMAFlags(default)
  exten => s,n(analog),Dial(${TRUNK}/${MACRO_EXTEN})
  exten => s,n,Macro(fastbusy)
  exten => s,analog+101,Busy

; for 10-digit dialing in non-local areas
[macro-dialnufonewithfallback1]
  exten => s,1,Macro(condsetcid)
  exten => s,n,SetCIDName(LAIRD SCOTT)
  exten => s,n,SetAMAFlags(billing)
  exten => s,n(nufone),Dial(${NUFONE}/1${MACRO_EXTEN})
  exten => s,n,Congestion
  exten => s,nufone+101,SetAMAFlags(default)
  exten => s,n(analog),Dial(${TRUNK}/1${MACRO_EXTEN})
  exten => s,n,Macro(fastbusy)
  exten => s,analog+101,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]
  ; Only allow 2, 3, 7, and 10-digit strings.  Without this, calls to area
  ; codes that start with a '9' (like my sister's cell phone in NYC) don't
  ; work.
  exten => _9XX,1,Macro(dialanalog)
  exten => _9XXX,1,Macro(dialanalog)
  exten => _9XXXXXXX,1,Macro(dialanalog)
  exten => _9XXXXXXXXXX,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 => 200,1,Macro(callextension,${PHONES},200)
  exten => 201,1,Macro(callextension,${ANALOG},200)
  exten => 202,1,Macro(callextension,${BEDSIP},200)
  exten => 203,1,Macro(callextension,${KITSIP},200)
  exten => 204,1,Macro(callextension,${BEDSIP},200)

  exten => 210,1,Macro(callextension,${BASESIP},210)

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

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

  exten => 222,1,Wait,2
  exten => 222,2,VoicemailMain(s200)
  exten => 222,3,Hangup

  exten => 211,1,Wait(2)
  exten => 211,n,VoicemailMain(s210)

  exten => 223,1,Wait,2
  exten => 223,2,VoicemailMain
  exten => 223,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(us201)
  exten => 1,4,Hangup

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

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

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

  exten => 5,1,AppendCDRUserField( -> 5)
  exten => 5,2,Wait(1)
  exten => 5,3,VoiceMailMain
  exten => 5,4,Hangup
     
  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(s200)
  exten => t,3,Hangup

  exten => i,1,AppendCDRUserField( -> invalid)
  exten => i,2,Playback(tt-allbusy)
  exten => i,3,Goto(s,3)
     
[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,GotoIf($[X${CALLERIDNAME} = X]?200:2)
  exten => s,2,Macro(outsideline)
  exten => s,3,Hangup
  exten => s,200,Wait(30)
  exten => s,201,Hangup
  exten => 4254889999,Macro(outsideline)
  exten => 4254889999,2,Hangup
  exten => 8662299999,1,Macro(outsideline)
  exten => 8662299999,2,Hangup
  exten => 2068389999,1,Macro(outsideline)
  exten => 2068389999,n,Hangup
  exten => 8003949999,1,Macro(cidfix)
  exten => 8003949999,n,Goto(outside-ivr,s,1)
  exten => 8003949999,n,Hangup
  exten => 8888299999,1,SetAccount(pannell)
  exten => 8888299999,n,Macro(cidfix)
  exten => 8888299999,n,Dial(${BASESIP},30,t)
  exten => 8888299999,n,Voicemail(u210)
  exten => 4253549999,1,Macro(outsideline)
  exten => 4253549999,2,Hangup
  
  exten => 8662559999,1,VoicemailMain(200)
  exten => 8662559999,2,Hangup
  exten => 8662559999/2064849999,1,VoicemailMain(s200)
  exten => 8662559999/2064849999,2,Hangup
  exten => 8662559999/2069799999,1,VoicemailMain(s200)
  exten => 8662559999/2069799999,2,Hangup

  exten => scott,1,VoiceMail(us201)
  exten => scott,2,Hangup
  exten => cynthia,1,VoiceMail(us202)
  exten => cynthia,2,Hangup

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

[outside-analog]
  exten => s,1,GotoIf($[X${CALLERIDNAME} = X]?200:2)
  exten => s,2,Goto(outside,4254889999,1)
  exten => s,3,Hangup
  exten => s,200,Wait(30)
  exten => s,201,Hangup

[outside-sip]
  include => outside

[outside-nufone]
  include => outside

[outside-ebc]
  include => outside

[default]
  exten => s,n,Goto(outside,2068389999,1)
  exten => _x.,n,Goto(outside,2068389999,1)

sip.conf

Here’s sip.conf, again slightly redacted:

;
; SIP Configuration for Asterisk
;
[general]
port = 5060                   ; Port to bind to
bindaddr = 0.0.0.0    ; Address to bind to
context = outside-sip         ; Default for incoming calls
srvlookup = yes               ; Enable SRV lookups on outbound calls
;pedantic = yes               ; Enable slow, pedantic checking for Pingtel
tos=lowdelay
disallow=all                  ; Disallow all codecs
allow=gsm
allow=ilbc
allow=ulaw            ; Allow codecs in order of preference
insecure=very

[201]
type=friend
secret=zzzz
auth=md5
nat=yes
host=dynamic
reinvite=no
canreinvite=no
qualify=1000
dtmfmode=rfc2833
mailbox=200,201
callerid="Scott Laird" <201>
disallow=all
allow=gsm
allow=ulaw
allow=ilbc
context=inside-sip

[202]
type=friend
secret=zzzz
auth=md5
nat=yes
host=dynamic
reinvite=no
canreinvite=no
qualify=1000
dtmfmode=rfc2833
mailbox=200,202
callerid="Cynthia Laird" <202>
disallow=all
allow=gsm
allow=ulaw
allow=ilbc
context=inside-sip

[203]
type=friend
secret=zzzz
auth=md5
nat=yes
host=dynamic
reinvite=no
canreinvite=no
qualify=1000
dtmfmode=rfc2833
mailbox=200
callerid="Kitchen" <203>
disallow=all
allow=gsm
allow=ulaw
allow=ilbc
context=inside-sip

iax.conf

Finally, iax.conf:

; Inter-Asterisk eXchange driver definition
;
;
[general]
bandwidth=low
allow=gsm
disallow=ilbc
disallow=speex
disallow=ulaw
disallow=alaw
disallow=lpc10                ; Icky sound quality...  Mr. Roboto.
jitterbuffer=yes

register => laird:zzzz@switch-2.nufone.net
register => laird:zzzz@voip.teliax.com
authdebug=yes
tos=lowdelay

[guest]
type=user
context=outside
callerid="Guest IAX User"

[NuFone]
type=user
host=switch-2.nufone.net
secret=zzzz
context=outside-nufone
qualify=400
amaflags=billing

[NuFone]
type=peer
host=switch-1.nufone.net
secret=zzzz
qualify=400
amaflags=billing

[teliax]
context=outside
type=friend
host=voip.teliax.com
auth=md5
secret=zzzz
disallow=all
;allow=ilbc
allow=gsm
qualify=400