Asterisk sip mysql peers

IAX2 / SIP peers in MySQL Database

The SIP and IAX2 channels support definition of friends in a MySQL database.

To enable this, you need to edit the Makefile in the channels directory of your source tree and enable MYSQL_FRIENDS. This enables database definition of both IAX2 and SIP friends. Make sure you have the MySQL development kit (libraries) installed before compilation.

You also need to define the following variables in the general section of sip.conf and iax.conf:
  • dbname: Name of database in your Mysql server
  • dbhost: Hostname of server
  • dbuser: Username in MySQL
  • dbpass: Password for user in MySQL

The following data is stored in the database:
  • name: Name of peer (used in SIP registration)
  • secret: Secret (password) stored in plaintext!
  • context: Default context for incoming calls from user
  • ipaddr: Default IP address of user
  • port: Default port

Database format:

  1. Table structure for table `bit_sipfriends`
CREATE TABLE `bit_sipfriends` (
`name` varchar(40) NOT NULL default '',
`username` varchar(40) default '',
`secret` varchar(40) NOT NULL default '',
`context` varchar(40) NOT NULL default '',
`ipaddr` varchar(20) NOT NULL default '',
`port` int(6) NOT NULL default '0',
`regseconds` int(11) NOT NULL default '0',
PRIMARY KEY (`name`)

  1. Table structure for table `bit_iaxfriends`
CREATE TABLE `bit_iaxfriends` (
`accountcode` varchar(20) NOT NULL default '',
`name` varchar(40) NOT NULL default '',
`secret` varchar(40) default '',
`context` varchar(40) default '',
`ipaddr` varchar(20) default '',
`port` int(6) default '0',
`regseconds` int(11) default '0',
PRIMARY KEY (`name`)

'accountcode' column needed for IAX2 calls to complete successfully (IAX2 calls will error incorrrectly saying "no authority found" if this field is not available in the iaxfriends table)

How to securely store passwords in the database:

MySQL offers several ways of storing passwords in the database:


If you wish to decrypt/encrypt passwords for storing in sip.conf, then you would look at using DES_DECRYPT/ENCRYPT or AES_DECRYPT/ENCRYPT. Or, you can store a MD5 hash of the password in the database, but you will not be able to decrypt the password because it is one-way encryption.

See also

Created by: oej, Last modification: Thu 18 of Aug, 2005 (14:21 UTC) by Nuttah
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+