Asterisk - CLI

最後更新: 2015-03-13

 

 


Configure File

 

cli.conf

;  automatically executed
core set verbose 3 = yes
core set debug 3 = yes

 

cli_aliases.conf    

[general]
template = friendly
;template = asterisk_1dot4        ; Asterisk 1.4 style syntax

[friendly]
hangup request=channel request hangup
originate=channel originate
help=core show help
pri intense debug span=pri set debug intense span
reload=module reload
pjsip reload=module reload res_pjsip.so res_pjsip_authenticator_digest.so ........

 


Linux 權限

 

asterisk 是在 dialout 及 audio Group 內的 !!

dialout:x:20:asterisk
audio:x:29:asterisk

 


Help

server*CLI> help ???

i.e.

help sip

 


Command

 

check version

asterisk -V

Asterisk 1.8.13.1~dfsg1-3+deb7u3

 

啟動 asterisk:

asterisk -p  -U <user>

  • -p                   # attempt to run with realtime priority for increased performance
  • -U <user>       # Run as a user other than the caller

Default: /usr/sbin/asterisk -p -U asterisk

 

Get Shell

-r              Connect to Asterisk on this machine

-v              Increase verbosity

asterisk -rv

server*CLI>

 


CLI

 

aliases

cli show aliases

Alias Command                                      Real Command
reload                                             module reload
help                                               core show help
hangup request                                     channel request hangup
pri intense debug span                             pri set debug intense span
originate                                          channel originate

 

Core

Voip*CLI> core show version

Asterisk 1.8.7.1

Voip*CLI> core show uptime

System uptime: 1 hour, 53 minutes, 19 seconds
Last reload: 1 hour, 53 minutes, 19 seconds

Voip*CLI> core show channels

Channel              Location             State   Application(Data)
0 active channels
0 active calls
5 calls processed

Voip*CLI> core show calls

0 active calls
5 calls processed

Voip*CLI> core show hints

    -= Registered Asterisk Dial Plan Hints =-
                    203@default             : SIP/203               State:Idle            Watchers  0
                    202@default             : SIP/202               State:Unavailable     Watchers  0
                    201@default             : SIP/201               State:Unavailable     Watchers  0
                    302@default             : SIP/302               State:Unavailable     Watchers  0
                    301@default             : SIP/301               State:Unavailable     Watchers  0
                    224@default             : SIP/224               State:Unavailable     Watchers  0
                    221@default             : SIP/221               State:Unavailable     Watchers  0
                    220@default             : SIP/220               State:Unavailable     Watchers  0
                    223@default             : SIP/223               State:Unavailable     Watchers  0
                    222@default             : SIP/222               State:Unavailable     Watchers  0
----------------
- 10 hints registered

Voip*CLI> core show functions

Installed Custom Functions:
----------------------------
CALLERID
TIMEOUT
.................
44 custom functions installed.

codecs

# show codecs

ls -l /usr/lib/asterisk/modules/ | grep codec_

OR

server*CLI> core show codecs

        It does not indicate anything about your configuration.
                INT    BINARY                  HEX   TYPE       NAME   DESCRIPTION
-----------------------------------------------------------------------------------
                  1 (1 <<  0)                (0x1)  audio       g723   (G.723.1)
                  2 (1 <<  1)                (0x2)  audio        gsm   (GSM)
                  4 (1 <<  2)                (0x4)  audio       ulaw   (G.711 u-law)
                  8 (1 <<  3)                (0x8)  audio       alaw   (G.711 A-law)
                 16 (1 <<  4)               (0x10)  audio   g726aal2   (G.726 AAL2)
                 32 (1 <<  5)               (0x20)  audio      adpcm   (ADPCM)
                 64 (1 <<  6)               (0x40)  audio       slin   (16 bit Signed Linear PCM)
                128 (1 <<  7)               (0x80)  audio      lpc10   (LPC10)
                256 (1 <<  8)              (0x100)  audio       g729   (G.729A)
                512 (1 <<  9)              (0x200)  audio      speex   (SpeeX)
               1024 (1 << 10)              (0x400)  audio       ilbc   (iLBC)
               2048 (1 << 11)              (0x800)  audio       g726   (G.726 RFC3551)
               4096 (1 << 12)             (0x1000)  audio       g722   (G722)
               8192 (1 << 13)             (0x2000)  audio     siren7   (ITU G.722.1 (Siren7, licensed from Polycom))
              16384 (1 << 14)             (0x4000)  audio    siren14   (ITU G.722.1 Annex C, (Siren14, licensed from Polycom))
              32768 (1 << 15)             (0x8000)  audio     slin16   (16 bit Signed Linear PCM (16kHz))
              65536 (1 << 16)            (0x10000)  image       jpeg   (JPEG image)
             131072 (1 << 17)            (0x20000)  image        png   (PNG image)

 

dialplan

Voip*CLI> dialplan show

Voip*CLI> dialplan reload

 

database

Voip*CLI> database show

/SIP/Registry/201                                 : 192.168.88.171:5060:60:201:sip:[email protected]:5060
/SIP/Registry/202                                 : 192.168.88.172:5060:60:202:sip:[email protected]:5060
/SIP/Registry/301                                 : 192.168.88.32:5060:60:301:sip:[email protected]:5060
/SIP/Registry/302                                 : 192.168.88.30:5060:60:302:sip:[email protected]:5060
4 results found.

 

SIP

# 重新載入 sip.conf setting

Voip*CLI> sip reload

# 查看什麼人連到 Server

Voip*CLI> sip show peers

Name/username              Host                                    Dyn Forcerport ACL Port     Status    
201/201                    192.168.88.171                           D   N      5060     Unmonitored
202/202                    192.168.88.172                           D   N      5060     Unmonitored
301/301                    192.168.88.32                            D   N      5060     Unmonitored
302/302                    192.168.88.30                            D   N      5060     Unmonitored
4 sip peers [Monitored: 0 online, 0 offline Unmonitored: 4 online, 0 offline]

Voip*CLI> sip show peer 202

  * Name       : 202
  Secret       : <Set>
  MD5Secret    : <Not set>
  Remote Secret: <Not set>
  Context      : context-user-202
  Subscr.Cont. : <Not set>
  Language     :
  AMA flags    : Unknown
  Transfer mode: open
  .......................

Voip*CLI> sip show users

Username                   Secret           Accountcode      Def.Context      ACL  ForcerPort
202                        ??????                            context-user-20  No   Yes
201                        ??????                            context-user-20  No   Yes

# 會顥示 clear text password !!

Voip*CLI> sip show user 202

  * Name       : 202
  Secret       : <Set>                                      # 只會顯然 <Set> 或 <Not set>
  MD5Secret    : <Not set>
  Context      : context-user-202
  Language     :
  AMA flags    : Unknown
  Transfer mode: open
  MaxCallBR    : 384 kbps
  CallingPres  : Presentation Allowed, Not Screened
  Call limit   : 0
  Callgroup    :
  Pickupgroup  :
  Callerid     : "Tim" <>
  ACL          : No
  Sess-Timers  : Accept
  Sess-Refresh : uas
  Sess-Expires : 1800 secs
  Sess-Min-SE  : 90 secs
  RTP Engine   : asterisk
  Codec Order  : (ulaw:20,alaw:20)
  Auto-Framing:  No

 

sip show registry

 

Voip*CLI> sip notify <type> <peer>

# types are defined in sip_notify.conf

 

Voip*CLI> sip show channels

Peer             User/ANR         Call ID          Format           Hold     Last Message    Expiry     Peer     
192.168.88.172   (None)           2f0d209b06d7b83  0x0 (nothing)    No       Rx: REGISTER               <guest>  
192.168.88.30    (None)           054980911c97b24  0x0 (nothing)    No       Rx: REGISTER               <guest>  
192.168.88.32    (None)           434f2f4403a83be  0x0 (nothing)    No       Rx: REGISTER               <guest>  
192.168.88.171   (None)           6c2cf3487b18337  0x0 (nothing)    No       Rx: REGISTER               <guest>

 

Voip*CLI> sip show inuse

* Peer name               In use          Limit

 

Voip*CLI> sip show settings

Global Settings:
----------------
  UDP Bindaddress:        0.0.0.0:5060
  TCP SIP Bindaddress:    0.0.0.0:5060
  TLS SIP Bindaddress:    Disabled

.......................................
 
Network QoS Settings:
---------------------------
  IP ToS SIP:             CS0
  IP ToS RTP audio:       CS0
  IP ToS RTP video:       CS0
  IP ToS RTP text:        CS0
  802.1p CoS SIP:         4
  802.1p CoS RTP audio:   5
  802.1p CoS RTP video:   6
  802.1p CoS RTP text:    5
  Jitterbuffer enabled:   No

Network Settings:
---------------------------
  SIP address remapping:  Enabled using externaddr
  Externhost:             <none>
  Externaddr:             x.x.x.x:0
  Externrefresh:          10
  Localnet:               192.168.88.0/255.255.255.0

Global Signalling Settings:
---------------------------
  Codecs:                 0x0 (nothing)
  Codec Order:            none
  Relax DTMF:             No
  RFC2833 Compensation:   No
  Symmetric RTP:          Yes
  Compact SIP headers:    No

.......................................

Default Settings:
-----------------
  Allowed transports:     UDP
  Outbound transport:     UDP
  Context:                default
  Force rport:            Yes
  DTMF:                   rfc2833

.......................................

# 重選部份 setting

sip reload

 

# Debug

sip set debug on

 

 


Cheatsheet

 

Voip*CLI> sip show settings

Voip*CLI> sip show inuse

Voip*CLI> sip show peers

Voip*CLI> sip show users

 


參考

http://www.asteriskguru.com/tutorials/cli_cmd_14.html

Creative Commons license icon Creative Commons license icon