{"id":189,"date":"2017-10-08T14:32:11","date_gmt":"2017-10-08T19:32:11","guid":{"rendered":"https:\/\/codemonkeyden.com\/blog\/?p=189"},"modified":"2023-11-10T23:02:20","modified_gmt":"2023-11-11T05:02:20","slug":"home-voip-asterisk","status":"publish","type":"post","link":"https:\/\/codemonkeyden.com\/?p=189","title":{"rendered":"Host Your Own Home VOIP System using Asterisk"},"content":{"rendered":"<h5>Background<\/h5>\n<p>Some cable ISPs like comcast offer home VOIP systems for a hefty monthly fee. In addition to the extra cost, they often require you to rent a gateway from them. By renting a gateway from them, you not only incur an additional monthly fee for this, but more importantly you are giving them a backdoor into your cable modem and allowing them to use it as a wifi hotspot for strangers, often without your knowledge. To\u00a0regain full control over your home network and VOIP system, you need to buy your own modem and host the VOIP system yourself using free (as in freedom) software.<\/p>\n<p>A VOIP system could just be used for communicating between rooms in your house much like the phones in hotel rooms can call each other. But most likely you will want to be able to receive calls from outside of your house from the PSTN (Public Switched Telephone Network). To do this you will need to purchase a DID (Direct Inward Dialing) number from a SIP provider, which typically involves a small recurring charge.<\/p>\n<h5>Prerequisites<\/h5>\n<p>On Debian 9 GNU\/Linux, the\u00a0asterisk package needs to be installed.<\/p>\n<pre>$ sudo apt-get install -y asterisk<\/pre>\n<p>The following information about your SIP provider must be known:<\/p>\n<ul>\n<li>SIP_USER &#8211; SIP username<\/li>\n<li>SIP_SECRET &#8211; SIP password<\/li>\n<li>SIP_HOST &#8211; SIP server hostname (DID Point of Presence)<\/li>\n<li>SIP_IP &#8211; SIP server IP<\/li>\n<li>SIP_PORT &#8211; SIP port<\/li>\n<li>DID_PHONE_NUMBER &#8211; phone number from VoIP provider (10 digits with no delimiters)<\/li>\n<\/ul>\n<p>The following information about your IP Phone must be known:<\/p>\n<ul>\n<li>EXT_NUMBER &#8211; a 4 digit extension number<\/li>\n<li>EXT_PASSWORD &#8211; the extension password<\/li>\n<li>VM_NUMBER &#8211; a 4 digit voicemail number<\/li>\n<\/ul>\n<p>The following information must be known about your network:<\/p>\n<ul>\n<li>EXTERNHOST &#8211; hostname that resolves to\u00a0your public WAN IP<\/li>\n<\/ul>\n<p>Decide on the following information:<\/p>\n<ul>\n<li>VOICEMAIL_PIN &#8211; numeric password for voicemail<\/li>\n<li>EMAIL_ADDRESS &#8211; email address of voicemail account<\/li>\n<\/ul>\n<h5>Configure sip.conf<\/h5>\n<p>There are a\u00a0ton\u00a0of possible settings that can go in this file. The file is divided into several sections whose names are enclosed in square brackets.<\/p>\n<ul>\n<li><strong>context\u00a0<\/strong>specifies the name of the context to which each extension is associated and is defined later in extensions.conf<\/li>\n<li><strong>register<\/strong>\u00a0specifies the SIP registration parameters including\u00a0the username, secret, host-name, and port<\/li>\n<li><strong>allowguest=no<\/strong> disables unauthenticated calls<\/li>\n<li><strong>allowoverlap=no<\/strong> disables overlap dialing support<\/li>\n<li><strong>srvlookup=no<\/strong> disables looking up SRV DNS records on outbound calls, which is unnecessary because we explicitly specified both the SIP IP address and port number in the register line<\/li>\n<li><strong>disallow<\/strong> and <strong>allow<\/strong> restricts the audio codecs that a device will accept or offer<\/li>\n<li><strong>alwaysauthreject=yes<\/strong> enables a security feature where the reject for a wrong password and wrong username appear the same way, which prevents a cracker from gaining knowledge about the system they are attempting to attack<\/li>\n<li><strong>canreinvite=no<\/strong> disables SIP re-invites, forcing asterisk to stay in the middle of the media<\/li>\n<li><strong>nat=force_rport,comedia <\/strong>modifies the behavior related to a server behind NAT (Network Address Translation);\u00a0force_rport disables symmetric RTP support\u00a0and comedia enables symmetric RTP support if the remote side requests it<\/li>\n<li><strong>qualify=yes\u00a0<\/strong>enables\u00a0sending a SIP\u00a0OPTIONS\u00a0command every 2 seconds to check that the device is still online<\/li>\n<li><strong>session-timers=refuse\u00a0<\/strong>disables session timers<\/li>\n<li><strong>externhost=EXTERNHOST<\/strong>\u00a0 specifies the FQDN to be resolved to acquire the public IP address of the asterisk server<\/li>\n<li><strong>externrefresh=15\u00a0<\/strong>specifies that externhost should be resolved every 15 seconds<\/li>\n<li><strong>localnet=192.168.0.0\/255.255.0.0\u00a0<\/strong>excludes addresses in the subnet from any NATing efforts by asterisk, allowing the source addresses of SIP requests\/response to include\u00a0the internal address<\/li>\n<li><strong>host=HOST\u00a0<\/strong>specifies the hostname of the\u00a0sip peer<\/li>\n<li><strong>host=dynamic<\/strong> means that the sip peer must register<\/li>\n<li><strong>secret=SECRET<\/strong> allows a SIP peer to securely prove its identity<\/li>\n<li><strong>type=friend<\/strong>\u00a0specifies that an entity is both a sip peer (receives calls) and user (places calls)<\/li>\n<li><strong>defaultuser=SIP_USER\u00a0<\/strong>specifies the username for authentication in SIP INVITE requests from remote clients<\/li>\n<li><strong>fromuser=SIP_USER\u00a0<\/strong>overrides the username when calling to this peer from asterisk<\/li>\n<li><strong>trustrpid=yes<\/strong> trust Remote-Party-ID SIP header<\/li>\n<li><strong>sendrpid=yes<\/strong>\u00a0send Remote-Party-ID SIP header<\/li>\n<li><strong>insecure=invite<\/strong>\u00a0disables\u00a0authentication requirement for incoming SIP INVITE requests<\/li>\n<li><strong>deny<\/strong> and <strong>permit<\/strong> restrict the addresses of hosts that can attempt registration<\/li>\n<\/ul>\n<pre>[general]\ncontext=internal\nregister =&gt; SIP_USER:SIP_SECRET@SIP_HOST:SIP_PORT\nallowguest=no\nallowoverlap=no\nsrvlookup=no\ndisallow=all\nallow=ulaw\nalwaysauthreject=yes\ncanreinvite=no\nnat=force_rport,comedia\nqualify=yes\nsession-timers=refuse\nexternhost=EXTERNHOST\nexternrefresh=15\nlocalnet=192.168.0.0\/255.255.0.0\n\n[voipms]\ncontext=internal\nhost=HOST\nsecret=SIP_SECRET\ntype=friend\ndefaultuser=SIP_USER\nfromuser=SIP_USER\ntrustrpid=yes\nsendrpid=yes\ninsecure=invite\ndeny=0.0.0.0\/0.0.0.0\npermit=SIP_IP\/255.255.255.255\n\n[EXT_NUMBER]\ntype=friend\nhost=dynamic\nsecret=EXT_PASSWORD\ncontext=internal\ndeny=0.0.0.0\/0.0.0.0\npermit=192.168.0.0\/255.255.0.0<\/pre>\n<h5>Create a Dialplan<\/h5>\n<p>The dialplan is stored in extensions.conf.<\/p>\n<pre>[internal]\nexten =&gt; s,1,Answer()\nexten =&gt; s,2,Dial(SIP\/EXT_NUMBER,10)\nexten =&gt; s,3,Playback(vm-nobodyavail)\nexten =&gt; s,4,VoiceMail(EXT_NUMBER@main)\nexten =&gt; s,5,Hangup()\nexten =&gt; EXT_NUMBER,1,Answer()\nexten =&gt; EXT_NUMBER,2,Dial(SIP\/EXT_NUMBER,10)\nexten =&gt; EXT_NUMBER,3,Playback(vm-nobodyavail)\nexten =&gt; EXT_NUMBER,4,VoiceMail(EXT_NUMBER@main)\nexten =&gt; EXT_NUMBER,5,Hangup()\n\nexten =&gt; _*97,1,VoiceMailMain(${CALLERID(num)}@main)\nexten =&gt; _*97,2,Hangup()\n\ninclude =&gt; voipms-inbound\ninclude =&gt; voipms-outbound\n\n[voipms-outbound]\nexten =&gt; _1NXXNXXXXXX,1,Dial(SIP\/${EXTEN}@voipms)\nexten =&gt; _1NXXNXXXXXX,n,Hangup()\nexten =&gt; _NXXNXXXXXX,1,Dial(SIP\/1${EXTEN}@voipms)\nexten =&gt; _NXXNXXXXXX,n,Hangup()\nexten =&gt; _011.,1,Dial(SIP\/${EXTEN}@voipms)\nexten =&gt; _011.,n,Hangup()\nexten =&gt; _00.,1,Dial(SIP\/${EXTEN}@voipms)\nexten =&gt; _00.,n,Hangup()\n\n[voipms-inbound]\nexten =&gt; DID_PHONE_NUMBER,1,Answer()<\/pre>\n<h5>Configure voicemail.conf<\/h5>\n<pre>[main]\nEXT_NUMBER =&gt; VOICEMAIL_PIN, danny, EMAIL_ADDRESS<\/pre>\n<h5>Reload Asterisk<\/h5>\n<pre>$\u00a0sudo asterisk -rx reload<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Background Some cable ISPs like comcast offer home VOIP systems for a hefty monthly fee. In addition to the extra cost, they often require you to rent a gateway from them. By renting a gateway from them, you not only incur an additional monthly fee for this, but more importantly you are giving them a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":489,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[5],"class_list":["post-189","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sysadmin","category-voip","tag-debian"],"_links":{"self":[{"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=189"}],"version-history":[{"count":1,"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":496,"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions\/496"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=\/wp\/v2\/media\/489"}],"wp:attachment":[{"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codemonkeyden.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}