「Asterisk」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎SIP: chan_sip に変更)
(→‎chan_sip: PJSIP を追加)
37行目: 37行目:
 
''';''' noload => chan_sip.so
 
''';''' noload => chan_sip.so
 
}}
 
}}
  +
  +
=== PJSIP ===
  +
  +
Once installed, Asterisk has the {{ic|res_pjsip}} configuration in {{ic|/etc/asterisk/pjsip.conf}}. The sample file included with Asterisk gives several basic examples, but is not exhaustive for all pjsip options. Readers are encouraged to read the [https://wiki.asterisk.org/wiki/x/EwFB Asterisk Wiki Security best practices article], and [https://wiki.asterisk.org/wiki/display/AST/Configuring+res_pjsip Configuring res_pjsip] before continuing.
  +
  +
This article contains a basic single SIP phone, multiple SIP trunk example, using [https://store.sipstation.com/ss_index/ SIP Station SIP trunks, from Sangoma]. Two SIP trunks with SIP Station are configured for redundancy, as recommended by SIP Station. The following example was tested using a Sangoma/Digium D60 hardware phone, but any SIP 2.0 compliant hard- or softphone should suffice.
  +
  +
This example assumes the Asterisk PBX server and SIP phone are on a private IPv4 LAN, with a NAT router between the server/phone and the WAN/Internet. If you would like to use IPv6, please read the [https://wiki.asterisk.org/wiki/display/AST/Configuring+res_pjsip+for+IPv6 Configuring res_pjsip for IPv6] article.
  +
  +
==== modules.conf ====
  +
  +
First, ensure {{ic|res_pjsip.so}} is not prefixed with {{ic|noload {{=}}}}. In this example, the {{ic|require {{=}}}} prefix makes Asterisk fail to load if {{ic|chan_pjsip.so}} fails to load. This is not absolutely necessary, but unless you are using other VoIP protocols it may not make sense for Asterisk to load if {{ic|res_pjsip}} does not load.
  +
  +
{{hc|/etc/asterisk/modules.conf|
  +
;...
  +
require {{=}} chan_pjsip.so
  +
;...
  +
}}
  +
  +
==== pjsip.conf ====
  +
  +
Before diving into configuring {{ic|pjsip.conf}}, review the [https://wiki.asterisk.org/wiki/display/AST/PJSIP+Configuration+Wizard PJSIP Configuration Wizard]. It is useful for the simple use case of only one SIP provider/ITSP, and handles many of the pjsip objects for this automatically.
  +
  +
The file {{ic|pjsip.conf}} is an ini-style configuration file, with {{ic|[section-headers-in-square-brackets]}}, and either a hash ({{ic|#}}) or a semicolon ({{ic|;}}) as the comment character. Each line under a section header is a {{ic|key{{=}}value}} pair, with section-specific keys set to the specified values. Note that section headers can have {{ic|(!)}} appended after the closing square bracket, which indicates the section is a template, for later use within {{ic|pjsip.conf}}. To instantiate a section using a previously defined template, suffix the section header with the {{ic|(template-name)}}.
  +
  +
===== transport section =====
  +
  +
In order to define a SIP trunk for use with Asterisk, PJSIP has the concept of a network {{ic|transport}}. From the Asterisk Wiki, the transport section configures how {{ic|res_pjsip}} will operate at the transport layer. For example, it supports configuration options for protocols such as TCP, UDP, or WebSockets and encryption methods like TLS/SSL.
  +
  +
Transport sections can be named arbitrarily, but it is recommended to name the section that makes it easy to remember what it signifies. The following example names it {{ic|[transport-udp-nat]}} for identifying that this transport is using UDP for SIP, and is expected to traverse a NAT device.
  +
  +
{{hc|/etc/asterisk/pjsip.conf|2=
  +
[transport-udp-nat]
  +
type=transport ; signifies this is a transport definition
  +
protocol=udp ; specifies this uses the UDP transport protocol
  +
; this transport binds to all configured network interfaces,
  +
; replace with the IP address of the desired interface. 0.0.0.0 means all interfaces
  +
bind=0.0.0.0
  +
; ===== NOTE, the following directives are OPTIONAL
  +
local_net=10.20.30.0/24 ; specify the networks that this Asterisk server should consider as local/LAN networks. Change this to the local LAN subnet (in CIDR notation)
  +
local_net=127.0.0.0/8 ; specify the networks that this Asterisk server should consider as local/LAN networks (this one sets it to the IPv4 loopback network)
  +
external_media_address=96.69.199.60 ; specify the external/WAN IP address for RDP media (audio)
  +
external_signaling_address=96.69.199.60 ; specify the external/WAN IP address for SIP (signaling)
  +
}}
  +
  +
Note that only one transport is allowed for each IP address/port or IP address/protocol mapping. If you would like to configure multiple transport protocols (e.g. both TCP and UDP), you will need to bind each protocol to a different IP address. Likewise if you want to define multiple transports using the same protocol, the ports used need to be different for each transport definition.
  +
  +
===== registration section =====
  +
  +
Next, define the registrations the SIP trunks will use. Note that the SIP Station registrations are first defined via a template (with {{ic|(!)}} appended to the section name). Each template defines the settings that are common for each section using the template; the sections themselves only contain the options that need to be set for that section.
  +
  +
{{hc|/etc/asterisk/pjsip.conf|2=
  +
[sipstation-reg](!)
  +
type=registration
  +
transport=transport-udp-nat
  +
contact_user=15055551234
  +
retry_interval=60
  +
  +
; ==== ... several other templates and sections will appear here
  +
; ==== including the authentication sections, etc., which are also used by the registration
  +
; ==== ....
  +
  +
[siptsation-reg1](sipstation-reg)
  +
outbound_auth=sipstation-auth1
  +
<nowiki>server_uri=sip:trunk1.freepbx.com ; trunk1 provided by SIP Station
  +
client_uri=sip:my_username@trunk1.freepbx.com</nowiki>
  +
  +
[siptsation-reg2](sipstation-reg)
  +
outbound_auth=sipstation-auth2
  +
<nowiki>server_uri=sip:trunk2.freepbx.com ; trunk2 provided by SIP Station
  +
client_uri=sip:my_username@trunk2.freepbx.com</nowiki>
  +
}}
  +
  +
===== authentication section =====
  +
  +
Here, define the authentication template, and the specific authentication sections for use with the SIP Station trunks.
  +
  +
{{hc|/etc/asterisk/pjsip.conf|2=
  +
[sipstation-auth](!)
  +
type=auth
  +
password=Super*Secret@Password!
  +
username=my_username
  +
  +
; ==== ... more templates may appear here
  +
  +
[sipstation-auth1](sipstation-auth)
  +
realm=trunk1.freepbx.com
  +
  +
[sipstation-auth2](sipstation-auth)
  +
realm=trunk2.freepbx.com
  +
}}
  +
  +
===== endpoint section =====
  +
  +
An endpoint is essentially a profile for the configuration of a SIP device such as a phone or remote server. This defines the transport, the Asterisk Dialplan context where calls originating from the endpoint gets handled, and the audio codecs allowed for the endpoint. For the SIP station trunks, define the following:
  +
  +
{{hc|/etc/asterisk/pjsip.conf|2=
  +
[sipstation-endpoint](!)
  +
type=endpoint
  +
transport=transport-udp-nat
  +
context=from-external ; Dialplan context, defined in extensions.conf or related file
  +
disallow=all ; disallows all codecs, including default ones, unless explicitly allowed below
  +
allow=ulaw ; standard G.711, uncompressed PCM codec. Uses the most bandwidth
  +
allow=gsm ; another standard, compressed codec. Uses less bandwidth than ulaw
  +
; other codecs are available, and have different attributes. Some require paid licenses to use.
  +
aors=sipstation-aors ; AOR - Address of Record, to be defined later
  +
;direct_media=no ; setting this may not allow audio to pass through NAT
  +
direct_media=yes
  +
rtp_symmetric=yes
  +
  +
; ==== ... more template definitions
  +
  +
[sipstation-endpoint1](sipstation-endpoint)
  +
outbound_auth=sipstation-auth1
  +
from_domain=trunk1.freepbx.com
  +
  +
[sipstation-endpoint2](sipstation-endpoint)
  +
outbound_auth=sipstation-auth2
  +
from_domain=trunk2.freepbx.com
  +
}}
  +
  +
===== identify section =====
  +
  +
Controls how the res_pjsip_endpoint_identifier_ip module determines what endpoint an incoming packet is from. For the SIP Station trunks, the following is defined:
  +
  +
{{hc|/etc/asterisk/pjsip.conf|2=
  +
[sipstation-identify](!)
  +
type=identify
  +
; this is the LAN IP address of the NAT router, which calls from the SIP Station
  +
; trunks may appear to come from (because of NAT).
  +
match=10.20.30.254/32
  +
  +
[sipstation-id1](sipstation-identify)
  +
endpoint=sipstation-endpoint1
  +
match=192.159.66.3 ; IP address of trunk1.freepbx.com
  +
  +
[sipstation-id2](sipstation-identify)
  +
endpoint=sipstation-endpoint2
  +
match=162.253.134.142 ; IP address of trunk2.freepbx.com
  +
}}
  +
  +
===== aor (Address Of Record) section =====
  +
  +
A primary feature of AOR objects (Address of Record) is to tell Asterisk where an endpoint can be contacted. Without an associated AOR section, an endpoint cannot be contacted. For the SIP Station trunks, define this:
  +
  +
{{hc|/etc/asterisk/pjsip.conf|2=
  +
[sipstation-aors]
  +
type=aor
  +
<nowiki>contact=sip:trunk1.freepbx.com
  +
contact=sip:trunk2.freepbx.com</nowiki>
  +
}}
  +
  +
===== phone sections =====
  +
  +
Finally, define the necessary sections for the SIP phone that will register to Asterisk. It has several similar sections as with the SIP Station trunks. Expand these with templates if multiple local SIP phones are intended to register to your Asterisk PBX. Remote phones (from the WAN/Internet) can also be configured, but that iss outside the scope of this example.
  +
  +
{{hc|/etc/asterisk/pjsip.conf|2=
  +
[home-phone]
  +
type=endpoint
  +
transport=transport-udp-nat
  +
context=from-internal ; Dialplan context that gets executed when a user dials from this phone
  +
disallow=all
  +
allow=ulaw
  +
allow=gsm
  +
auth=home-phone-auth
  +
aors=home-phone
  +
  +
[home-phone-auth]
  +
type=auth
  +
auth_type=userpass
  +
password=MyPhonePa$$word0
  +
username=home-phone
  +
  +
[home-phone]
  +
type=aor
  +
max_contacts=1
  +
}}
  +
  +
==== Managing PJSIP ====
  +
  +
There are several commands regarding {{ic|res_pjsip}} available in the Asterisk CLI, all prefixed with the {{ic|pjsip}} command. To get to the Asterisk CLI, enter the following command, as the {{ic|asterisk}} user:
  +
  +
$ asterisk -rvvv
  +
  +
This assumes Asterisk is already running (e.g., via the systemd service unit). Once in the Asterisk CLI, you will see the prompt {{ic|hostname*CLI> }}. To see a list of available PJSIP commands, type {{ic|help pjsip}}.
  +
  +
To see a list of PJSIP registrations, type the following:
  +
  +
{{hc|hostname*CLI> pjsip show registrations|<nowiki>
  +
  +
<Registration/ServerURI..............................> <Auth....................> <Status.......>
  +
---------------------------------------------------------------------------------------------
  +
  +
siptsation-reg1/sip:trunk1.freepbx.com sipstation-auth1 Registered (exp. 2062s)
  +
siptsation-reg2/sip:trunk2.freepbx.com sipstation-auth2 Registered (exp. 2069s)
  +
  +
Objects found: 2
  +
</nowiki>}}
  +
  +
To see a list of PJSIP endpoints, type the following:
  +
  +
{{hc|hostname*CLI> pjsip show endpoints|<nowiki>
  +
  +
Endpoint: <Endpoint/CID.....................................> <State.....> <Channels.>
  +
I/OAuth: <AuthId/UserName...........................................................>
  +
Aor: <Aor............................................> <MaxContact>
  +
Contact: <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
  +
Transport: <TransportId........> <Type> <cos> <tos> <BindAddress..................>
  +
Identify: <Identify/Endpoint.........................................................>
  +
Match: <criteria.........................>
  +
Channel: <ChannelId......................................> <State.....> <Time.....>
  +
Exten: <DialedExten...........> CLCID: <ConnectedLineCID.......>
  +
----------------------------------------------------------------------------------------------
  +
  +
Endpoint: home-phone Not in use 0 of inf
  +
InAuth: home-phone-auth/home-phone
  +
Aor: home-phone 1
  +
Contact: home-phone/sip:home-phone@10.20.30.229:506 f91928f561 NonQual nan
  +
Transport: transport-udp-nat udp 0 0 0.0.0.0:5060
  +
  +
Endpoint: sipstation-endpoint1 Not in use 0 of inf
  +
OutAuth: sipstation-auth1/mw3FSBsPPjQ7
  +
Aor: sipstation-aors 0
  +
Contact: sipstation-aors/sip:trunk1.freepbx.com 256c242e36 NonQual nan
  +
Contact: sipstation-aors/sip:trunk2.freepbx.com c07c6c7180 NonQual nan
  +
Transport: transport-udp-nat udp 0 0 0.0.0.0:5060
  +
Identify: sipstation-id1/sipstation-endpoint1
  +
Match: 10.20.30.254/32
  +
Match: 192.159.66.3/32
  +
  +
Endpoint: sipstation-endpoint2 Not in use 0 of inf
  +
OutAuth: sipstation-auth2/mw3FSBsPPjQ7
  +
Aor: sipstation-aors 0
  +
Contact: sipstation-aors/sip:trunk1.freepbx.com 256c242e36 NonQual nan
  +
Contact: sipstation-aors/sip:trunk2.freepbx.com c07c6c7180 NonQual nan
  +
Transport: transport-udp-nat udp 0 0 0.0.0.0:5060
  +
Identify: sipstation-id2/sipstation-endpoint2
  +
Match: 10.20.30.254/32
  +
Match: 162.253.134.142/32
  +
  +
Objects found: 3
  +
</nowiki>}}
   
 
=== chan_sip ===
 
=== chan_sip ===

2023年5月1日 (月) 14:16時点における版

Asterisk は完全な PBX (構内交換機) ソフトウェアです。Linux, BSD, Windows, macOS などで動作し、PBX が通常備えている機能は全て含まれています。Asterisk は4つのプロトコルで Voice over IP を実現し、比較的安価なハードウェアでほぼ全ての規格の電話装置と一緒に使うことが可能です。

Asterisk はボイスメールサービス、電話帳、電話会議、自動音声応答、コールキューイングを実現します。また、三者通話、発信者番号通知サービス、ADSI、IAX、SIP、H.323 (クライアントとゲートウェイの両方)、MGCP (コールマネージャのみ)、SCCP/Skinny をサポートしています。

この記事では家庭ネットワークにおけるシンプルな設定を説明し、SIP ソフトフォンを使って LAN 上の他の SIP ソフトフォンと会話できるようにします。

インストール

asteriskAUR パッケージをインストールしてください。Cisco の IP 電話を使用する場合はパッチが適用されている asterisk-ciscoAUR パッケージを使うことが推奨されます (https://issues.asterisk.org/jira/browse/ASTERISK-13145 を参照)。

あるいは、asterisk-lts-20AUR パッケージをインストールすると、長期サポートリリースを入手できます(現在の最新 LTS メジャーバージョンは Asterisk 20です)。Asterisk LTS リリースは機能が少ない傾向にありますが、ずっと長い間メンテナンスされます。すべての asterisk バージョンのリリースサイクルに関する完全な詳細については、Asterisk Versions ページを参照してください。

インストールしたら asterisk.service systemd サービスを有効化および起動してください。

SIP ソフトフォンと最低2つのマシンが必要です。SIP フォンとしては Blink (blinkAUR)、 Linphone (liblinphone-gitAUR) または X-Lite (xlite-binAUR) が推奨されます。

ilbc コーデックのサポートを有効にするには PKGBUILD の build セクションの冒頭に以下を追加してください:

cd ${srcdir}/${pkgname}-${pkgver}/contrib/scripts
echo | ./get_ilbc_source.sh

設定

この記事またはセクションの正確性には問題があります。
理由: 廃止されたモジュール (sip) ではなく、廃止されていないモジュール (pjsip) のインストラクションを提供する方がよいでしょう。 (議論: トーク:Asterisk#)

以下の説明は、すでに時代遅れとなっている sip モジュールを使いたい場合を想定していることに注意してください。sip モジュールはもうメンテナンスされていませんが、新しい pjsip モジュールより設定が簡単です。2 つのモジュールの間の設定の変更点のまとめと、新しいモジュールへの移行方法は Asterisk wiki に記載されています。

sip を使うには、古いモジュールを明示的にロードし、新しい pjsip モジュールがアンロードされていることを確認する必要があります。/etc/asterisk/modules.conf で、以下を調整してください。

noload => chan_pjsip.so
noload => res_pjsip.so
; noload => chan_sip.so

PJSIP

Once installed, Asterisk has the res_pjsip configuration in /etc/asterisk/pjsip.conf. The sample file included with Asterisk gives several basic examples, but is not exhaustive for all pjsip options. Readers are encouraged to read the Asterisk Wiki Security best practices article, and Configuring res_pjsip before continuing.

This article contains a basic single SIP phone, multiple SIP trunk example, using SIP Station SIP trunks, from Sangoma. Two SIP trunks with SIP Station are configured for redundancy, as recommended by SIP Station. The following example was tested using a Sangoma/Digium D60 hardware phone, but any SIP 2.0 compliant hard- or softphone should suffice.

This example assumes the Asterisk PBX server and SIP phone are on a private IPv4 LAN, with a NAT router between the server/phone and the WAN/Internet. If you would like to use IPv6, please read the Configuring res_pjsip for IPv6 article.

modules.conf

First, ensure res_pjsip.so is not prefixed with noload テンプレート:=. In this example, the require テンプレート:= prefix makes Asterisk fail to load if chan_pjsip.so fails to load. This is not absolutely necessary, but unless you are using other VoIP protocols it may not make sense for Asterisk to load if res_pjsip does not load.

/etc/asterisk/modules.conf
;...
require テンプレート:= chan_pjsip.so
;...

pjsip.conf

Before diving into configuring pjsip.conf, review the PJSIP Configuration Wizard. It is useful for the simple use case of only one SIP provider/ITSP, and handles many of the pjsip objects for this automatically.

The file pjsip.conf is an ini-style configuration file, with [section-headers-in-square-brackets], and either a hash (#) or a semicolon (;) as the comment character. Each line under a section header is a keyテンプレート:=value pair, with section-specific keys set to the specified values. Note that section headers can have (!) appended after the closing square bracket, which indicates the section is a template, for later use within pjsip.conf. To instantiate a section using a previously defined template, suffix the section header with the (template-name).

transport section

In order to define a SIP trunk for use with Asterisk, PJSIP has the concept of a network transport. From the Asterisk Wiki, the transport section configures how res_pjsip will operate at the transport layer. For example, it supports configuration options for protocols such as TCP, UDP, or WebSockets and encryption methods like TLS/SSL.

Transport sections can be named arbitrarily, but it is recommended to name the section that makes it easy to remember what it signifies. The following example names it [transport-udp-nat] for identifying that this transport is using UDP for SIP, and is expected to traverse a NAT device.

/etc/asterisk/pjsip.conf
[transport-udp-nat]
type=transport  ; signifies this is a transport definition
protocol=udp  ; specifies this uses the UDP transport protocol
; this transport binds to all configured network interfaces, 
; replace with the IP address of the desired interface. 0.0.0.0 means all interfaces
bind=0.0.0.0
; =====  NOTE, the following directives are OPTIONAL
local_net=10.20.30.0/24  ; specify the networks that this Asterisk server should consider as local/LAN networks. Change this to the local LAN subnet (in CIDR notation)
local_net=127.0.0.0/8  ; specify the networks that this Asterisk server should consider as local/LAN networks (this one sets it to the IPv4 loopback network)
external_media_address=96.69.199.60  ; specify the external/WAN IP address for RDP media (audio)
external_signaling_address=96.69.199.60  ; specify the external/WAN IP address for SIP (signaling)

Note that only one transport is allowed for each IP address/port or IP address/protocol mapping. If you would like to configure multiple transport protocols (e.g. both TCP and UDP), you will need to bind each protocol to a different IP address. Likewise if you want to define multiple transports using the same protocol, the ports used need to be different for each transport definition.

registration section

Next, define the registrations the SIP trunks will use. Note that the SIP Station registrations are first defined via a template (with (!) appended to the section name). Each template defines the settings that are common for each section using the template; the sections themselves only contain the options that need to be set for that section.

/etc/asterisk/pjsip.conf
[sipstation-reg](!)
type=registration
transport=transport-udp-nat
contact_user=15055551234
retry_interval=60

; ==== ... several other templates and sections will appear here
; ====     including the authentication sections, etc., which are also used by the registration
; ==== ....

[siptsation-reg1](sipstation-reg)
outbound_auth=sipstation-auth1 
server_uri=sip:trunk1.freepbx.com  ; trunk1 provided by SIP Station
client_uri=sip:my_username@trunk1.freepbx.com

[siptsation-reg2](sipstation-reg)
outbound_auth=sipstation-auth2 
server_uri=sip:trunk2.freepbx.com  ;  trunk2 provided by SIP Station
client_uri=sip:my_username@trunk2.freepbx.com
authentication section

Here, define the authentication template, and the specific authentication sections for use with the SIP Station trunks.

/etc/asterisk/pjsip.conf
[sipstation-auth](!)
type=auth
password=Super*Secret@Password!
username=my_username

; ==== ... more templates may appear here

[sipstation-auth1](sipstation-auth)
realm=trunk1.freepbx.com

[sipstation-auth2](sipstation-auth)
realm=trunk2.freepbx.com
endpoint section

An endpoint is essentially a profile for the configuration of a SIP device such as a phone or remote server. This defines the transport, the Asterisk Dialplan context where calls originating from the endpoint gets handled, and the audio codecs allowed for the endpoint. For the SIP station trunks, define the following:

/etc/asterisk/pjsip.conf
[sipstation-endpoint](!)
type=endpoint
transport=transport-udp-nat
context=from-external  ; Dialplan context, defined in extensions.conf or related file
disallow=all   ; disallows all codecs, including default ones, unless explicitly allowed below
allow=ulaw     ; standard G.711, uncompressed PCM codec. Uses the most bandwidth
allow=gsm      ; another standard, compressed codec. Uses less bandwidth than ulaw
; other codecs are available, and have different attributes. Some require paid licenses to use.
aors=sipstation-aors  ; AOR - Address of Record, to be defined later
;direct_media=no  ; setting this may not allow audio to pass through NAT
direct_media=yes
rtp_symmetric=yes

; ==== ... more template definitions

[sipstation-endpoint1](sipstation-endpoint)
outbound_auth=sipstation-auth1
from_domain=trunk1.freepbx.com

[sipstation-endpoint2](sipstation-endpoint)
outbound_auth=sipstation-auth2
from_domain=trunk2.freepbx.com
identify section

Controls how the res_pjsip_endpoint_identifier_ip module determines what endpoint an incoming packet is from. For the SIP Station trunks, the following is defined:

/etc/asterisk/pjsip.conf
[sipstation-identify](!)
type=identify
; this is the LAN IP address of the NAT router, which calls from the SIP Station
; trunks may appear to come from (because of NAT).
match=10.20.30.254/32

[sipstation-id1](sipstation-identify)
endpoint=sipstation-endpoint1
match=192.159.66.3   ;  IP address of trunk1.freepbx.com

[sipstation-id2](sipstation-identify)
endpoint=sipstation-endpoint2
match=162.253.134.142    ;  IP address of trunk2.freepbx.com
aor (Address Of Record) section

A primary feature of AOR objects (Address of Record) is to tell Asterisk where an endpoint can be contacted. Without an associated AOR section, an endpoint cannot be contacted. For the SIP Station trunks, define this:

/etc/asterisk/pjsip.conf
[sipstation-aors]
type=aor
contact=sip:trunk1.freepbx.com
contact=sip:trunk2.freepbx.com
phone sections

Finally, define the necessary sections for the SIP phone that will register to Asterisk. It has several similar sections as with the SIP Station trunks. Expand these with templates if multiple local SIP phones are intended to register to your Asterisk PBX. Remote phones (from the WAN/Internet) can also be configured, but that iss outside the scope of this example.

/etc/asterisk/pjsip.conf
[home-phone]
type=endpoint
transport=transport-udp-nat
context=from-internal  ;  Dialplan context that gets executed when a user dials from this phone
disallow=all
allow=ulaw
allow=gsm
auth=home-phone-auth
aors=home-phone

[home-phone-auth]
type=auth
auth_type=userpass
password=MyPhonePa$$word0
username=home-phone

[home-phone]
type=aor
max_contacts=1

Managing PJSIP

There are several commands regarding res_pjsip available in the Asterisk CLI, all prefixed with the pjsip command. To get to the Asterisk CLI, enter the following command, as the asterisk user:

$ asterisk -rvvv

This assumes Asterisk is already running (e.g., via the systemd service unit). Once in the Asterisk CLI, you will see the prompt hostname*CLI> . To see a list of available PJSIP commands, type help pjsip.

To see a list of PJSIP registrations, type the following:

hostname*CLI> pjsip show registrations

 <Registration/ServerURI..............................>  <Auth....................>  <Status.......>
---------------------------------------------------------------------------------------------

 siptsation-reg1/sip:trunk1.freepbx.com                  sipstation-auth1            Registered        (exp. 2062s)
 siptsation-reg2/sip:trunk2.freepbx.com                  sipstation-auth2            Registered        (exp. 2069s)

Objects found: 2

To see a list of PJSIP endpoints, type the following:

hostname*CLI> pjsip show endpoints
                                                                                                 
 Endpoint:  <Endpoint/CID.....................................>  <State.....>  <Channels.>
    I/OAuth:  <AuthId/UserName...........................................................>
        Aor:  <Aor............................................>  <MaxContact>
      Contact:  <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
  Transport:  <TransportId........>  <Type>  <cos>  <tos>  <BindAddress..................>
   Identify:  <Identify/Endpoint.........................................................>
        Match:  <criteria.........................>
    Channel:  <ChannelId......................................>  <State.....>  <Time.....>
        Exten: <DialedExten...........>  CLCID: <ConnectedLineCID.......>
 ----------------------------------------------------------------------------------------------

 Endpoint:  home-phone                                           Not in use    0 of inf
     InAuth:  home-phone-auth/home-phone
        Aor:  home-phone                                         1
      Contact:  home-phone/sip:home-phone@10.20.30.229:506 f91928f561 NonQual         nan
  Transport:  transport-udp-nat         udp      0      0  0.0.0.0:5060

 Endpoint:  sipstation-endpoint1                                 Not in use    0 of inf
    OutAuth:  sipstation-auth1/mw3FSBsPPjQ7
        Aor:  sipstation-aors                                    0
      Contact:  sipstation-aors/sip:trunk1.freepbx.com     256c242e36 NonQual         nan
      Contact:  sipstation-aors/sip:trunk2.freepbx.com     c07c6c7180 NonQual         nan
  Transport:  transport-udp-nat         udp      0      0  0.0.0.0:5060
   Identify:  sipstation-id1/sipstation-endpoint1
        Match: 10.20.30.254/32
        Match: 192.159.66.3/32

 Endpoint:  sipstation-endpoint2                                 Not in use    0 of inf
    OutAuth:  sipstation-auth2/mw3FSBsPPjQ7
        Aor:  sipstation-aors                                    0
      Contact:  sipstation-aors/sip:trunk1.freepbx.com     256c242e36 NonQual         nan
      Contact:  sipstation-aors/sip:trunk2.freepbx.com     c07c6c7180 NonQual         nan
  Transport:  transport-udp-nat         udp      0      0  0.0.0.0:5060
   Identify:  sipstation-id2/sipstation-endpoint2
        Match: 10.20.30.254/32
        Match: 162.253.134.142/32

Objects found: 3

chan_sip

asterisk サーバーを動かしたら、後は2つのファイルを編集すれば設定できます: sip.confextensions.conf。asterisk の設定ディレクトリ (/etc/asterisk) に移動して、sip.conf を編集して以下を記述してください:

[me1]
type=friend
username=me1
secret=PASSWORD
host=dynamic
context=house

[me2]
type=friend
username=me2
secret=PASSWORD
host=dynamic
context=house

これで house コンテキストに二人の SIP ユーザー me1me2 が作成されます。パスワードは PASSWORD です。

次にコンテキストを定義します。extensions.conf を以下のように編集:

[house]
exten => 100,1,Dial(SIP/me1)

exten => 101,1,Dial(SIP/me2)

これでコンテキスト house が作成され SIP ユーザー me1 にエクステンション 100 が、SIP ユーザー me2 にエクステンション 101 が割り当てられます。後は実際に動作するか確認するだけです。

保留音

保留音はとても楽しい機能です。簡単に設定することができます。/etc/asterisk/musiconhold.conf を編集して以下を追加してください:

[default]
mode=files
directory=mohmp3

後は合法的に入手したお気に入りの MP3 を /var/lib/asterisk/mohmp3 にコピーしてください。

ボイスメール

Asterisk にはボイスメール機能が存在します。設定する方法は多数ありますが、この記事ではシンプルな設定方法だけを紹介します。

voicemail.conf を作成・編集:

[general]
format=gsm|wav49|wav
serveremail=asterisk
attach=no
mailcmd=/usr/sbin/sendmail -t
maxmessage=180
maxgreet=60

[default]
100 => 1234,Me,me@mydomain.com

[general] の設定の内容は こちら を見て下さい。Postfix が正しくセットアップされていれば PBX からメールの通知がユーザーに送信され、attach=yes と定義されている場合、メールに音声ファイルが添付されます。

次にメールボックスの設定です。フォーマットは:

mailbox => password,user,email

上記の場合、'Me' というユーザー名でメールアドレスが me@mydomain.com、パスワードが 1234 のメールボックス 100 が設定されます。

それから、ボイスメールボックスにメッセージを残す方法と、記録されたメッセージにアクセスする手段を用意する必要があります。

extensions.conf に戻り、既存のエントリを次のように変更します:

exten => 100,1,Dial(SIP/me1,20)
exten => 100,2,Voicemail(100@default)

最初の 'exten' は 'Dial()' で20秒間電話を呼び出します。応答がない場合、default コンテキストの 100 番のボイスメールボックスに転送します。

さらに以下のように設定することで実際にボイスメールにアクセスすることができます:

exten => 600,1,VoiceMailMain,s100@default

600 番を呼び出すと、'VoiceMailMain' アプリケーションは default コンテキストの 100 番に行きます。s で自動ログインが許可されます。

ノート: 'VoiceMail' アプリケーションには多くのオプションがありますので、追加のドキュメントに目を通すことをお勧めします。これは、基本的な家庭用の設定です。 また、一般的に 'VoiceMail' にアクセスする際には、ユーザーの内線より高い内線を使用することをお勧めします。208 にダイヤルしても、205 のボイスメールにヒットしないようにするためです。

PSTN に接続

ここまで設定できたら、次は外線と繋ぎましょう。OnSIP などのプロバイダが必要です。asterisk に接続する手順がプロバイダによって用意されているかもしれないため、このセクションは共通のことだけ記述します。

一般的なセットアップ

sip.conf
[general]
register => username:password@sip.specific.com

[whatever]                   
fromdomain=specific.com     
host=sip.specific.com
insecure=very    ; check with provider
username=usernameduh
secret=passwordduh
type=peer
extensions.conf
[outboundwithCID]  ; this can be whatever
exten => _1NXXNXXXXXX,1,SetCIDNum(15555551234)
exten => _1NXXNXXXXXX,2,Dial(SIP/${EXTEN}@whatever)
exten => _1NXXNXXXXXX,3,Congestion()
exten => _1NXXNXXXXXX,103,Busy()

[default]  ; This should be set in your sip.conf for incoming calls

;These should to be changed to your actual number
; ie     15555555555
exten => 1NXXNXXXXXX,1,Answer()
exten => 1NXXNXXXXXX,2,Playback(ttt-weasels)
exten => 1NXXNXXXXXX,3,HangUp()
  • 発信(outbound)コンテキストでは、ダイアルした番号を全てサービスプロバイダに送信します。2 の 'whatever' は sip.conf の設定と一致させる必要があります。
  • もちろん、着信(inbound)番号計画は、あなたが望むように変更することができます。例えば、Dial(SIP/me1)とすることで、誰かがあなたの番号に電話をかけると、あなたのコンピュータの SIP 電話に転送されるようにすることができます。それから、ボイスメールなどを追加します。
iax.conf

まず、FWD にログインして、FWD 側の IAX を有効にします。これは extra features の下にあり、作者は有効化するのに少し時間がかかると主張しているのを覚えておいてください。

そして iax.conf の 'general' セクションを以下のように編集:

register => FWDNUMBER:PASSWORD@iax2.fwdnet.net 
disallow = all
allow = ulaw

そして末尾に以下を追加:

[iaxfwd]
type=user
context=fromiaxfwd
auth=rsa
inkeys=freeworlddialup

これにより、FWD からの呼び出しが許可されます。

extensions.conf

'[globals]' の一番上に以下を記述:

FWDNUMBER=MYFWDNUMBER ; your calling number
FWDCIDNAME="MyName"; your caller id
FWDPASSWORD=MYFWDPASSWORD ; your password
FWDRINGS=sip/office ; the phone to ring
FWDVMBOX=1000 ; the VM box for this user

次に、これを発信用のコンテキストに追加します:

exten => _393.,1,SetCallerId,${FWDCIDNAME}
exten => _393.,2,Dial(IAX2/${FWDNUMBER}:${FWDPASSWORD}@iax2.fwdnet.net/${EXTEN:3},60,r)
exten => _393.,3,Congestion

「393」は好きなように変更できます。これは、「転送」番号をダイヤルする前にダイヤルするものです。例えば、「744561」をダイヤルする場合は、「393744561」をダイヤルします。

そして最後に、着信です。

[fromiaxfwd]
exten => ${FWDNUMBER},1,Dial(${FWDRINGS},20,r)
exten => ${FWDNUMBER},2,Voicemail,u${FWDVMBOX}
exten => ${FWDNUMBER},102,Voicemail,b${FWDVMBOX}
ノート: もし問題があれば、extensions.confから変数を削除してみてください。この手順は FWD のサイトからのもので、この記事の著者によってテストされたわけではありません。

内線番号の 55555(有志のテスト回線)、514(会議)にかけてみてください。

音声

音声は /var/lib/asterisk/xx フォルダに保存します。xx は言語コードです。例えば英語なら "en" になります。新しい音声を追加したいときはこのフォルダにコピーしてください。以下のフォルダ構造を守って下さい:

/var/lib/asterisk/sounds/xx
/var/lib/asterisk/sounds/xx/digits
/var/lib/asterisk/sounds/xx/letters
/var/lib/asterisk/sounds/xx/phonetic

sip.conf の language パラメータを編集してください:

[general]
...
language=en
...

音声が入手できる場所:

MeetMe

MeetMe は電話会議をできるようにするアプリケーションです。設定は簡単です。

meetme.conf を編集:

conf => 1000

extensions.conf を編集:

exten => 999,1,MeetMe(1000|M)

999 にダイアルすることで会議 1000 に入ることができます。|M を設定することで誰もいないときは保留音が鳴ります。誰かが会議に参加すると保留音は自動的に消えます。

ノート: MeetMe を使うには zaptel パッケージが必要です。asterisk を起動する前にインストールして modprobe ztdummy を実行してください。それによって TDM が利用できるようになります。

Asterisk コンソールとソフトフォン

Asterisk を立ち上げてください:

# asterisk -vvvvvvc

詳細な出力がされる Asterisk CLI が立ち上がります。

Asterisk が既に起動している場合、以下のコマンドを実行:

# asterisk -r

SIP クライアントを起動して sip.conf の情報にあわせて設定してください。Asterisk CLI に戻って以下のように表示されることを確認:

Registered SIP 'me1' at 192.168.0.142 port 5061 expires 60

これで me1 から 101 にダイアルして me2 と会話できるはずです。

トラブルシューティング

404 Not Found エラーが表示される場合は extensions.conf とダイアルした電話番号を確認してください。

翻訳ステータス: このページは en:Asterisk の翻訳バージョンです。最後の翻訳日は 2023-3-2 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。