Adding SIP Peers

Adding the first peer

In this lesson two peers will be added in the /etc/asterisk/sip.conf file so that a phone call can be made between the two. Using nano open the file for editing. Use the command:
sudo nano /etc/asterisk/sip.conf

Scroll to the bottom of the file and add the following information and save the file:
[matthew] type=friend
context=phones
allow=ulaw,alaw
secret=1234
host=dynamic
nat=force_rport,comedia

The first line [matthew] creates a context for an account named matthew. This of course could be changed to reflect any name of an account.

The next line type=friend is used to determine what type of account this is. There are three options to set the type value as: peer, user, and friend.  If the type is set to peer, Asterisk will create a SIP entity that will be used to send calls. An example of this type would be setting up a SIP provider. The user type will have Asterisk create a SIP entity that can place calls through the Asterisk system. The last type friend, will create both a user and peer

The next line context=phones sets the context used for the account in the /etc/asterisk/extensions.conf file. This will be created in the next section Dialplan Extensions.  If the type was set to peer, this defines the context for outbound calls.  If the type was set to user, this would then define the context for inbound calls. And if the type was friend, this would define the context for both outbound and inbound calls.

The following line, allow=ulaw,alaw defines which audio codecs are allowed for this peer. The ulaw option is a standard audio codec for North America and alaw in Europe. The available options include: all, g723, gsm, ulaw, alaw, g726, adpcm, slin, lpc10, g729, speex, and ilbc.

The secret=1234 sets the passcode to 1234. This of course is not a secure passcode at all. This will be needed to authenticate the user account when connecting a hardphone or softphone to asterisk.

The line host=dynamic is used because the phone that will be used to connect to this account will receive a dynamic IP address, which means that it could change over time. This will most likely be the case unless a static IP address is created for each phone device.

The final line nat=force_rport,comedia lets Asterisk ignore the address information in the SIP and SDP traffic headers from this peer, and reply to the sender’s IP address and port. In previous versions of Asterisk this was done by using nat=yes.

Peers in the console

It is now time to move to Asterisk’s Command Line Interface (console) to view the peers that are created in the system and to check to make sure they are loaded in the application.To open the console, use the command:
sudo asterisk -rvvv

To view a list of the peers that Asterisk has loaded enter the following command while in the Asterisk console:
sip show peers

More than likely there will still be now peers loaded into Asterisk. That is because Asterisk has previously loaded in the configuration file information when the computer booted up. When ever changes are made to a configuration file, that part of Asterisk will need to reloaded to use the new configurations. To reload the sip file configuration use the following command:
sip reload

Now if you show the sip peers again in the console it should list the first user that was added to the sip.conf file.

Adding a second peer

Additional peers can be added simply by appending their information to the end of the sip.conf file. Be sure to create a new context for the user/peer. For example, to add another user named eva to the sip.conf file add the information below. Don’t forget to reload sip within the Asterisk console.
[eva] type=friend
context=phones
allow=ulaw,alaw
secret=1234
host=dynamic
nat=force_rport,comedia