You are on page 1of 12

Asterisk config sip.

conf
Configuration file for Asterisk SIP channels, for both inbound and outbound calls. New in Asterisk v1.2.0: The global option "port" in 1.0.X that is used to set which port to bind to has been changed to "bindport" to be more consistent with the other channel drivers and to avoid confusion with the "port" option for users/peers.

Defining SIP channels in sip.conf


Each SIP client and server is identified by a block of text that looks like: [xxx] type=yyy parameter1=value parameter2=value Where xxx is the name associated with the SIP client, or is an arbitrary name used by other configuration files to refer to this SIP device. Typically if a SIP phone has an extension number of 123, then its corresponding entry in this file will begin with [123]. Note that you still have to enable an extension 123 in your dial plan to reach this phone. Type is either "user", "peer" or "friend". (See: Asterisk SIP user vs peer) Asterisk matches incoming calls to the name of a device with type=user based on the From: user name (ignoring the SIP domain). The other way that incoming SIP requests are matched to [xxx] sections in this file, is to examine the IP address that the request is coming from, and look for a peer [xxx] section that has a matching Host= value. If Host=dynamic, then no match is possible until the SIP client has registered.

Asterisk as a SIP client


In sip.conf under [general] add a register definition: Format: register => user[:secret[:authuser]]@host[:port][/extension] If you have problems with your network connection going up and down (e.g. an unreliable cable connection) and you keep losing your sip registry, you may want to add registerattempts and registertimeout settings to the general section above the register definitions. Setting registerattempts=0 will force Asterisk to attempt to reregister until it can (the default is 10 tries). registertimeout sets the length of time in seconds between registration attempts (the default is 20 seconds). P.S. Note for sipgate.co.uk users: /extension must be your sipgate number (this is not true; I am using "99" --jrc) - define one to accept this in your extensions.conf. An alternate port does not seem to work with sipgate.co.uk unless it is defined as the bindport in sip.conf without the [:port] syntax.

Example:
register => 2345:password@mysipprovider.com/1234 ; Register 2345 at sip provider as 1234 here.

user is the user id for this SIP server (ex 2345)

authuser is the optional authorization user for the SIP server secret is the user's password host is the domain or host name for the SIP server. This SIP server needs a definition in a section of its own in SIP.conf (mysipprovider.com). port send the register request to this port at host. Defaults to 5060 /1234 is the Asterisk contact extension. 1234 is put into the contact header in the SIP Register message. The contact extension is used by remote SIP server when it needs to send a call to Asterisk. See the example below. The default context extension is "s".

Agreed, it's not very good to have a lot of cleartext passwords in this text file, but that's how it works now. You only need to register if a) you want to be called, and b) you appear to the other side as having a dynamic IP address. Check the success of your own server's registrations at the CLI with "SIP SHOW REGISTRY", whereas you can obtain a list of clients that registered with your server with the help of "SIP SHOW PEERS". You may examine all details of a peer's registration with "SIP SHOW PEER <NAME>". Enter "HELP SIP" at the CLI for additional commands. The server definition for outgoing calls looks like this: [mysipprovider-out] type=peer secret=password username=2345 host=sipserver.mysipprovider.com fromuser=2345 fromdomain=fwd.pulver.com nat=yes context=from-mysipprovider ; this section will be defined in exte nsions.conf In extensions.conf you'd then use a statement like this: exten => _9.,1,Dial(SIP/${EXTEN:1}@mysipprovider-out,30,r) Please note that the ${EXTEN:1} variable here extracts all but the first characters from the current extension (the current match), in this case: 9 + the following digits. Refer to the Asterisk variables Substrings section for more details Here is the section(in extensions.conf) which routes calls from our sip provider to where we decide: [from-mysipprovider] exten => 1234,1,Answer ; 1234 is the contact extension, default c ontact extension is "s" exten => 1234,2,Dial(SIP/111,25,Ttr) ; incoming calls are redirec ted to SIP telephone with number 111 exten => 1234,3,Hangup

SIP Configuration -general


The [general] section of sip.conf includes the following variables:

allow = <codec> : Allow codecs in order of preference (Use DISALLOW=ALL first, before allowing other codecs) disallow = all : Disallow all codecs (global configuration) allowexternalinvites = yes|no : Enable/Disable INVITE and REFER to non-local domains. Default yes. (New in v1.2.x). allowguest = yes|no : Allow or reject guest calls (default is yes, this can also be set to 'osp' if asterisk was compiled with OSP support). (New in v1.2.x). allguest = yes|no : Allow/deny guest calls. Default yes. (New in v1.2.x). Autocreatepeer = yes|no : If set, anyone will be able to log in as a peer (with no check of credentials; useful for operation with SER). Default no. autodomain = yes|no : Enable/disable Asterisk's ability to add local hostnames and local IP address to the domain list. Default no. (New in v1.2.x). bindaddr = IP_Address : IP Address to bind to (listen on). Default 0.0.0.0 (all network interfaces). bindport = Number : UDP Port to bind to (listen on). Used to be port in Asterisk v1.0.x. Default 5060. callerid = <string> : Caller ID information used when nothing else is available. Defaults to asterisk. (The ability to override the default appears to available in Asterisk 1.0.9. Unsure about other versions.) canreinvite = update|yes|no (global setting): For some reason this defaults to yes, so beware... checkmwi = Number : Global interval (in seconds) between mailbox checks. Default 10 seconds. (New in v1.2.x) compactheaders = yes|no : Indicates Asterisk should send compact (i.e. abbreviated) headers in the SIP messages. Default no. (New in v1.2.x) context = <contextname> :This is the default context and is used when a endpoint has no context property. The context in section of an endpoint is used to route calls from that endpoint to the wanted destination. The context body is located in extensions.conf. defaultexpirey= Number : Default duration (in seconds) of incoming/outgoing registration. Default 120 seconds. dtmfmode = inband|info|rfc2833 (global setting). Default rfc2833. domain = domains : Comma separated list of domains which Asterisk is responsible for. (New in Asterisk 1.2.x) dumphistory = yes|no : Enable support for dumping of SIP conversation's transaction history to LOG_DEBUG. Default no. (New in v1.2.x) externip = IP_Address or a hostname : Address that we're going to put in SIP messages if we're behind a NAT. If a hostname is used as the value, then the IP address associated with the hostname is looked up only once during the reading of the sip.conf. If you want support for a hostname associated with a dynamic IP address, use externhost. externhost = hostname.tld : (New in Asterisk 1.2.x) externrefresh = Number : Specify how often (in seconds) a hostname DNS lookup should be performed for the value entered in 'externhost'. Default 10 seconds. (New in Asterisk 1.2.x). ignoreregexpire = yes|no : Indicates whether to use Contact information about a peer even if the information is stale because it has reached its expiration time. Default no. (New in v1.2.x) language = <string> : Default language used by any Playback()/Background(). localnet = NetAddress/Netmask : local network and mask.

fromdomain= <domain> : Sets default From: domain in SIP messages when acting as a SIP ua (client) insecure = very|yes|no|invite|port : Specifies how to handle connections with peers. Default no (authenticate all connections). (invite and port added in v1.2.x). maxexpirey= Number : Max duration (in seconds) of incoming registration we allow. Default 3600 seconds. musicclass = one of the classes specified in musiconhold.conf musdiconhold = same as musicclass nat= yes|no : Please note that as of Asterisk 1.0.x nat can now have the values: yes|no|never| route. Default no which really means to use rfc3581 techniques. notifymimetype= mediatype/subtype : Allow overriding of mime type in MWI NOTIFY used in voicemail online messages. Valid MIME types can be found here. Default application/simple-message-summary. (New in v1.2.x). notifyringing = yes|no : Notify subscription on RINGING state. Default yes. (New in v1.2.x). outboundproxy = IP_address or DNS SRV name (excluding the _sip._udp prefix) : SRV name, hostname, or IP address of the outbound SIP Proxy. (New in v1.2.x). outboundproxyport = Number : UDP port number for the Outbound SIP Proxy. (New in v1.2.x). pedantic = yes|no : Enable slow, pedantic checking of Call-ID:s, multiline SIP headers and URI-encoded headers. Default no. port = <portno> : Default SIP port of peer. (this is not the port for Asterisk to listen. See bindport). progressinband = never|no|yes : If we should generate in-band ringing always. Default never. promiscredir= yes|no : Allows support for 302 Redirects; (Note: will redirect them all to the local extension returned in Contact rather than to that extension at the destination). Default no. qualify = yes|no|milliseconds : Check if client is reachable. If yes, the checks occur every 2000 milliseconds (2 seconds). Default no. realm = my realm (Change authentication realm from asterisk (default) to your own. Requires Asterisk v1.x) recordhistory = yes|no. Enable logging of SIP conversation's transaction history. Default no. (New in v1.2.x). regcontext = context : Default context to use for SIP REGISTER replies from the SIP Registrar. register => <username>:<password>:[authid]@<sip client/peer id in sip.conf>/<contact> :Register with a SIP provider registerattempts = Number : Number of SIP REGISTER messages to send to a SIP Registrar before giving up. Default 0 (no limit). (New in v1.2.x). registertimeout = Number : Number of seconds to wait for a response from a SIP Registrar before classifying the SIP REGISTER has timed out. Default 20 seconds. (New in v1.2.x). relaxdtmf = yes|no: Default no. rtautoclear = yes|no|number : Auto-Expire friends created on the fly. If yes the autoexpire will be in 120 seconds. Default yes. (New in v1.2.x). rtcachefriends = yes|no : Cache realtime friends by adding them to the internal list just like friends added from the config file. Default no. (New in v1.2.x) rtpholdtimeout = Number : Max number of seconds of inactivity before terminating a call on hold. Default 0 (no limit). (New in v1.2.x). rtpkeepalive = Number : Number of seconds, when a RTP Keepalive packet will be sent if no other RTP traffic on that connection. Default 0 (no RTP Keepalive). (New in v1.2.x).

rtptimeout = Number : Number of seconds, to wait for RTP traffic before classify the connection as discontinued. Default 0 (no RTP timeout). (New in v1.2.x). rtupdate = yes|no : Send registry updates to the database when using Realtime support. Default yes. (New in v1.2.x). sendrpid = yes|no : If a Remote-Party-ID SIP header should be sent. Default no. sipdebug = yes|no. Default setting for whether SIP debug is enabled upon loading of the sip.conf. Default no. (New in v1.2.x). srvlookup = yes|no : Enable DNS SRV lookups on calls. Default no. tos = <value> : Set IP QoS parameters for outgoing media streams (numeric values are also accepted, like tos=184 ) trustrpid = yes|no : If Remote-Party-ID SIP header should be trusted. Default no. useclientcode = yes|no : usereqphone = yes|no : Indicates whether to add a ";user=phone" to the URI. Default no. (New in v1.2.x) useragent = <string> : Allow the SIP header "User-Agent" to be customized. Default asterisk. videosupport=yes|no : Turn on support for SIP video (peer specific setting added in SVN Dec 21 2005, bug 5427. Default no. vmexten = <string> : Dialplan extension to reach mailbox. Default asterisk. (New in v1.2.x)

SIP configurations - peers and clients


These variables can be configured for each SIP peer definition: (If not specified, the configuration variable can be used for both type=peer and type=user.)

accountcode = <string> : Users may be associated with an accountcode. See Asterisk billing allow = <codec> : Allow codecs in order of preference (Use DISALLOW=ALL first, before allowing other codecs) disallow = all : Disallow all codecs for this peer or user definition. allowguest = yes|no : Allow or reject guest calls (default is yes, this can also be set to 'osp' if asterisk was compiled with OSP support). (New in v1.2.x). amaflags: Categorization for CDR records. Choices are default, omit, billing, documentation. See Asterisk billing astdb: Appears to insert a value in the Asterisk database. See example below. auth = <authname> : Value assigned to the Digest username= SIP header. callerid = <string> : Caller ID information used when nothing else is available. Defaults to asterisk. call-limit = number : Number of simultaneous calls through this user/peer. callgroup = num1,num2-num3 : Defines call groups for calls to this device. callingpres = number|descriptive_text : Set Caller-ID presentation on a call. Valid descriptive values are: allowed_not_screened, allowed_passed_screen, allowed_failed_screen, allowed, prohib_not_screened, prohib_passed_screen, prohib_failed_screen, prohib, and unavailable. See SetCallerPres for more information. Default allowed_not_screened. canreinvite = update|yes|no : If the client is able to support SIP re-invites. Default yes. context = <context_name> : If type=user, the Context for the inbound call from this SIP user definition. If type=peer, the Context in the dialplan for outbound calls from this SIP peer definition. If type=friend the context used for both inbound and outbound calls through

the SIP entities definition. If no type=user entry matches an inbound call, then a type=peer or type=friend will match if the hostname or IP address defined in host= matches. defaultip = Dotted.Quad.IP.Addr : Default IP address of client host= is specified as DYNAMIC. Used if client has not been registered at any other IP address. Valid only for type=peer. dtmfmode = inband|info|rfc2833 : How the client handles DTMF signalling. Default rfc2833. fromuser = <from_ID> : Specify user to put in "from" instead of callerid (overrides the callerid) when placing calls _to_ peer (another SIP proxy). Valid only for type=peer. fromdomain = <domain> : Sets default From: domain in SIP messages when placing calls _to_ peer. Valid only when in [general] section or type=peer. fullcontact = <sip:uri_contact> : SIP URI contact for realtime peer. Valid only for realtime peers. host = dynamic|hostname|IPAddr : How to find the client - IP # or host name. If you want the phone to register itself, use the keyword dynamic instead of Host IP. incominglimit and outgoinglimit = Number : Limits for number of simultaneous active calls for a SIP client. Valid only for type=peer. insecure: very|yes|no|invite|port : Specifies how to handle connections with peers. Default no (authenticate all connections). (invite and port added in v1.2.x). ipaddr : Dotted Quad IP address of the peer. Valid only for realtime peers. language : A language code defined in indications.conf - defines language for prompts and specific local phone signals mailbox = mailbox : Voicemail extension (for message waiting indications). Valid only for type=peer. md5secret: MD5-Hash of "<user>:asterisk:<secret>" (can be used instead of secret) musicclass = one of the classes specified in musiconhold.conf musdiconhold = Set class of musiconhold on calls from SIP phone. Calls to the phone require SetMusicOnHold cmd of higher priority (lower numerical value of priority) than Dial cmd in dialplan in order to set this class for the call. Calls have the MusicOnHold class set on a per call basis, not on a per phone basis, and making a call through any extension specifying SetMusicOnHold will override this value for the call. name = <name> : Name of the realtime peer. Valid only for realtime peers. nat = yes|no : This variable changes the behaviour of Asterisk for clients behind a firewall. This does not solve the problem if Asterisk is behind the firewall and the client on the outside. Please note that as of Asterisk 1.0.x nat can now have the values: yes|no|never|route. Default no which really means to use rfc3581 techniques. outboundproxy = IP_address or DNS SRV name (excluding the _sip._udp prefix) : SRV name, hostname, or IP address of the outbound SIP Proxy. Valid only in [general] section and type=peer. (New in v1.2.x). permit, deny,mask: IP address and network restriction pickupgroup: Group that can pickup fellow workers' calls using *8 and the Pickup() application on the *8 extension port: SIP port of the client progressinband = never|no|yes : If we should generate in-band ringing always. Default never. promiscredir= yes|no : Allows support for 302 Redirects; (Note: will redirect them all to the local extension returned in Contact rather than to that extension at the destination). Default no. qualify = yes|no|milliseconds : Check if client is reachable. If yes, the checks occur every 2000 milliseconds (2 seconds). Valid only in [general] section and type=peer. regexten =

regseconds = seconds : Number of seconds between SIP REGISTER. Valid only for realtime peer entries. restrictcid: (yes/no) To have the callerid restricted -> sent as ANI; use this to hide the caller ID. This does not seem to work. This variable has been depreciated as of v1.2.x. rtpkeepalive = seconds : Number of seconds, when a RTP Keepalive packet will be sent if no other RTP traffic on that connection. Default 0 (no RTP Keepalive). Valid only in [general] section and type=peer. rtptimeout = seconds : Terminate call if x seconds of no RTP activity when we're not on hold. Valid only in [general] section and type=peer. rtpholdtimeout = seconds : Terminate call if x seconds of no RTP activity when we're on hold (must be larger than rtptimeout). Valid only in [general] section and type=peer. secret: If Asterisk is acting as a SIP Server, then this SIP client must login with this Password (A shared secret). If Asterisk is acting as a SIP client to a remote SIP server that requires SIP INVITE authentication, then this field is used to authenticate SIP INVITEs that Asterisk sends to the remote SIP server. sendrpid = yes|no : If a Remote-Party-ID SIP header should be sent. Default no. setvar = variable=value : Channel variable to be set for all calls from this peer/user. subscribecontext = <context_name> : Set a specific context for SIP SUBSCRIBE requests trustrpid = yes|no : If Remote-Party-ID SIP header should be trusted. Default no. type = user|peer|friend : Relationship to client - outbound provider or full client? useclientcode = yes|no : usereqphone = yes|no : Indicates whether to add a ";user=phone" to the URI. Default no. Valid only in [general] and type=peer. username = <username[@realm]> : If Asterisk is acting as a SIP client to a remote SIP server that requires SIP INVITE authentication, then this field is used to authenticate SIP INVITEs that Asterisk sends to the remote SIP server. Also, for peers that register with Asterisk, this username is used in INVITEs until we have a registration. vmexten = <string> : Dialplan extension to reach mailbox. Default asterisk. Valid only in [general] or type=peer.

Please note

Asterisk does not yet support SIP over TCP. It only supports SIP over UDP. For Grandstream phones: set dtmfmode=info Asterisk uses the incoming RTP Stream as a timing source for sending its outgoing Stream. If the incoming stream is interrupted due to silence suppression then musiconhold will be choppy. So in conclusion, you cannot use silence suppression. Make sure ALL SIP phones have disabled silence suppression. There is a solution for the silence suppression problem, see bug 5374 for details.

Examples
Each SIP client that connects to Asterisk needs a definition in SIP.CONF. Here is a few samples: [grandstream1] type=friend " or "user" ; either "friend" (peer+user), "peer

context=from-sip username=grandstream1 ; usually matches the <a href='sect ion'>section title </a href='section'> fromuser=grandstream1 ; overrides the callerid, e.g. requi red by FWD callerid=John Doe <1234> host=192.168.0.23 ; we have a static but private IP ad dress nat=no ; there is not NAT between phone and Asterisk canreinvite=yes ; allow RTP voice traffic to bypass Asterisk dtmfmode=info ; either RFC2833 or INFO for the Bud geTone mailbox=1234@default ; mailbox 1234 in voicemail context "default " disallow=all ; need to disallow=all before we can use allow= allow=ulaw ; Note: In user sections the order o f codecs ; listed with allow= does NOT matter ! ;allow=alaw ;allow=g723.1 ; Asterisk only supports g723.1 pass-thru! ;allow=g729 ; Pass-thru only unless g729 license obtained astdb=chan2ext/SIP/grandstream1=1234 ; ensures an astDB entry exists [xlite1] ;Turn off silence suppression in X-Lite ("Transmit Silence"=YES)! ;Note that Xlite sends NAT keep-alive packets, so qualify=yes is not needed type=friend username=xlite1 callerid="Jane Smith" <5678> host=dynamic nat=yes ; X-Lite is behind a NAT router canreinvite=no ; Typically set to NO if behind NAT disallow=all allow=gsm ; GSM consumes far less bandwidth th an G711-u (ulaw) allow=ulaw allow=alaw [user1_snomsip] type=friend secret=blah host=dynamic dtmfmode=inband nfo defaultip=192.168.0.59 mailbox=1234,2345 ator disallow=all allow=ulaw

; Choices are inband, rfc2833, or i ; Mailbox for message waiting indic ; since we chose 'inband' for dtmf

we must use g.711 allow=alaw [user2_pingtel] type=friend username=user2_pingtel secret=blah host=dynamic qualify=1000 to reply callgroup=1,3-4 , 3 and 4 pickupgroup=1,3-4 the callgroups 1, 3 and 4 defaultip=192.168.0.60 disallow=all allow=ulaw allow=alaw allow=g729 [user3_cisco] type=friend username=user3_cisco secret=blah nat=yes host=dynamic canreinvite=no qualify=200 s away defaultip=192.168.0.4 disallow=all allow=ulaw allow=alaw allow=g729 [user4_cisco1] type=friend username=user4_cisco fromuser=markster tead of callerid secret=blah defaultip=192.168.0.4 tip=... amaflags=default g, documentation accountcode=markster ccountcode to ease billing disallow=all allow=ulaw allow=alaw ; Specify user to put in "from" ins ; use either host=dynamic or defaul ; Choices are default, omit, billin ; Users may be associated with an a

; Consider it down if it's 1 second ; we are member of the call groups 1 ; we can do call pick-up with *8 for

; This phone may be natted ; Cisco poops on reinvite sometimes ; Qualify peer is no more than 200m

allow=g729 allow=g723.1 These definitions are documented in the Digium Asterisk handbook. After you defined these SIP client accounts in SIP.conf you are able to login to the asterisk server from clients and place calls. To receive calls, you need to configure extensions in extensions.conf. Example: exten => 1010,1, Dial(SIP/user3_cisco,10,t) If someone calls extension 1010, the sip client logged in as user3_cisco is dialled in order to receive the call.

Notes

the variable ${VXML_URL} can be used to add additional items to the To: header. The value is appended, after a semicolon, to the SIP To: header. Note that previous documentation on this site was incorrect; this variable has nothing to do with pushing pages to a Cisco 7960 phone (something that is currently impossible in the Cisco SIP firmware). The purpose is described in the author's e-mail the variable ${ALERT_INFO} can be used to create a new header called Alert-Info: which can be used to create distinctive ringing on the Cisco SIP-enabled phone devices with firmware version 6.0 onward. For Cisco 7940/60, ALERT_INFO can have the value of any of the following built-in ringtones: Bellcore-BusyVerify Bellcore-Stutter Bellcore-MsgWaiting Bellcore-dr1 Bellcore-dr2 Bellcore-dr3 Bellcore-dr4 Bellcore-dr5

It is not currently possible to specify a custom ring tone, only a cadence on the default ringtone. You will have to listen quite carefully to tell that the ringing is different. Cisco bug ID CSCec42938 tracks the request for it to work on custom ring tones.

Example 1

John Todd, loligo.com: http://www.loligo.com/asterisk/current/sip.conf

Connect to Free World Dialup (no NAT)


[general] disallow=all allow=gsm allow=ulaw allow=alaw context=from-sip

maxexpirey=180 defaultexpirey=160 tos=reliability register => <FWD#>:<FWD_PASSWORD>@fwd.pulver.com/CONTACT [fwd.pulver.com] type=friend secret=<FWD_PASSWORD> username=<FWD#> host=fwd.pulver.com insecure=very ; required for incoming FWD calls Now go to Asterisk config extensions.conf to view how to setup [from-sip] and [fwd-out] contexts in extensions.conf

Example 2
Using Asterisk together with SER
[general] context=OUTGOING autocreatepeer=yes [Provider] type=friend username=XXXXX secret=XXXXX host=xxxxx.FakeProvider.com So when Asterisk receives a call from SER it will "autocreatepeer" and give access to the OUTGOING context.

Controlling sip.conf from outside

Asterisk sip conf from mysql: As with all .conf files the #include statement can be applied to insert another file into sip.conf

Version notes

Additional features, added in v 0.7.2 o 2004-01-23: Added a "sip reload" to the CLI commands to make changes applied to sip.conf known to the running Asterisk server o 2004-01-25: Support for defining SIP peers in a database. The configuration in the database is not very complete, but works. See Asterisk sip mysql peers o 2004-06: Support for defining SIP Users in a database

See also

Asterisk sip channels: More documentation on SIP.conf SIP: Session Initiation Protocol Asterisk config extensions.conf: Asterisk extensions.conf samples Asterisk How to connect to FWD: Examples on how to configure Asterisk for Free World Dialup Asterisk at large: Running a SER proxy in front of Asterisk Letting SIP clients connect directly without media through asterisk Asterisk config files Asterisk SIP chan_sip2: Information about Olle E. Johansson's chan_sip2 project