Asterisk Project : Connecting to the Asterisk CLI

There are two ways to connect to an Asterisk console, either a foreground console when starting the Asterisk process or by connecting to a remote console after Asterisk is already running.

Connecting to a foreground console

This is as simple as passing the  -c flag when starting Asterisk.

       -c     Provide  a control console on the calling terminal. The console is similar to the remote console provided
              by -r. Specifying this option implies -f and will cause asterisk to no longer fork  or  detach  from  the
              controlling terminal. Equivalent to console = yes in asterisk.conf.

When working on a foreground console, you won't be able to exit, instead you'll have to stop Asterisk to return to the Linux shell. Most people will use a remote console when performing administration tasks.

After Asterisk has finished loading, you'll see the default CLI prompt. The text "server" will be replaced with your system's hostname.

server*CLI>

Connecting to a remote console

Connecting to a remote console using the  -r or -R flags. 

       -r     Instead of running a new Asterisk process, attempt to connect to a running Asterisk process and provide a
              console interface for controlling it.
       -R     Much like -r. Instead of running a new Asterisk process, attempt to connect to a running Asterisk process
              and provide a console interface for controlling it. Additionally, if connection to the  Asterisk  process
              is lost, attempt to reconnect for as long as 30 seconds.

To exit a remote console, simply type 'quit' or 'exit'. Please note that you can differentiate between a remote console and a foreground Asterisk console, as 'quit' or 'exit' will not function on the main console, which prevents an accidental shutdown of the daemon. If you would like to shutdown the Asterisk daemon from a remote console, there are various commands available.

 

Executing Command Outside Of CLI

Icon

You can execute an Asterisk command from outside the CLI:

$ asterisk -rx "core reload"
$ asterisk -rx "core show help" | grep -i "sip"