O'Reilly logo

VoIP Hacks by Theodore Wallingford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #42. Attach a SIP Phone to Asterisk

Asterisk is a phone system. But it won't do you much good without some phones connected.

You're about to use a SIP telephone to access the de facto auto-attendant greeting and to access a brief demonstration of an Inter-Asterisk Exchange (IAX) trunk over the Internet. Sound like too much? Don't worry; most of this is already configured with Asterisk out of the box. The toughest part for a VoIP beginner will be making sure Asterisk is willing to answer SIP calls—and that's pretty easy.

Tip

You won't need a regular phone line for this hack—just a SIP phone, Asterisk, and an Internet connection.

SIP is one of several standards that allow IP voice endpoints and application servers such as Asterisk to establish, monitor, and tear down media sessions across the network. Asterisk uses SIP to facilitate calls on behalf of SIP-based IP phones such as the BudgeTone 101, the Cisco SIP IP Phone 7960, and the Avaya 4602. I've chosen the BudgeTone 101 hardware because it's cheap, but you can go even cheaper and apply this hack using a softphone like the X-Lite [Hack #4] , which is free.

Tip

The Sipura SPA-841 is another excellent low-cost SIP phone.

Configure a Grandstream BudgeTone 101 IP Phone

The BudgeTone 101 phone has a Menu key, an LCD display, and two arrow keys that you use to navigate its configuration menu options: DHCP, IP Address, Subnet Mask, Router Address, DNS Server Address, TFTP Server Address, Codec Selection Order, SIP Server Address, and Firmware Versions (called Code Rel on the phone's screen). When you get to the option you want, you press the Menu key to select it, and then you enter the numeric data required for each option using the keypad. Use this menu only to set up the IP address, subnet mask, and router (default gateway) address.

To get the phone enabled for the next configuration step, turn off DHCP and assign an IP address, subnet mask, and router address.

More advanced configuration is performed using the BudgeTone's built-in web configuration tool. When you access the IP address you assigned to the phone using your web browser, you'll be prompted to log in to the phone. The default password is admin.

Then, you'll be confronted with a big page of configuration options. Many of these options are available only through this interface, not from the phone's keypad menu. After you apply your configuration changes, you need to power-cycle the BudgeTone.

Some IP phones offer a Telnet interface rather than (or in addition to) a webb-ased one. To use these tools, you must connect to the phone with a Telnet client rather than with a web browser. In any event, once you've set the network configuration on the BudgeTone, ping its address from another host on the same network subnet to make sure it's speaking Transmission Control Protocol/Internet Protocol (TCP/IP).

Set the IP Phone to Use a SIP Server

The IP phone, whose address I'll assume is 10.1.1.103, must be set to use your Asterisk box as a SIP server if you're to interact with the Asterisk demo. In your test lab, the IP phone should refer to the IP address of the Asterisk server (10.1.1.10, say) being used as its SIP server. Configure the SIP User ID setting as 103, too. For the DTMF Mode option, select SIP Info. Then apply the config changes and reboot the IP phone. (The same configuration options are supported by other makes of SIP phone, too.) The configuration page for a BudgeTone phone that has been configured to use a local SIP server (your Asterisk box) is shown in Figure 4-1.

A Grandstream BudgeTone that has been configured to use a SIP server at 10.1.1.10

Figure 4-1. A Grandstream BudgeTone that has been configured to use a SIP server at 10.1.1.10

Allow the IP Phone to Place Calls Via Asterisk

Until you authorize a SIP phone to communicate with Asterisk using Asterisk's SIP configuration file, you will always receive SIP error messages when trying to dial to (or through) the Asterisk server. This is Asterisk's way of ignoring what it sees as an unauthorized endpoint. Unlike traditional PBXs, which tend to give network access to any phone connected on an active port, SIP servers tend to enforce some security—usually in the form of password authentication.

So tell the Asterisk server to stop ignoring requests from your IP phone. Asterisk, the softPBX, refers to IP phones and other SIP devices as channels. SIP channels (or peers, if you like) are defined in Asterisk's configuration file, /etc/asterisk/sip.conf. To enable the phone as configured in Figure 4-1, add the following to the end of this file:

	[defaultsip]
	type=friend
	context=default
	username=103
	fromuser=SIP Phone
	callerid=103
	host=10.1.1.103
	nat=no
	canreinvite=yes
	dtfmode=info
	disallow=all
	allow=ulaw

The preceding configuration settings add the 10.1.1.103 IP phone that matches the configuration of the Grandstream BudgeTone. Take note of the username, callerid, and host values, which resemble each other (103) in this case. They don't need to resemble each other, however, because there's no relation between a phone IP address and its SIP username or caller ID. These can all be completely different.

Tip

One of the biggest differences between SIP and its predecessor, H.323, is that SIP identifies its phone endpoints (or terminals in H.323-speak) by IP address (and port number) exclusively, whereas H.323 still relies on their Ethernet MAC hardware addresses. This makes SIP more flexible!

There are two ways to enable the configuration change you've just made. One is to restart Asterisk:

	# asterisk -rx restart

Bear in mind that restarting your softPBX might be acceptable at home or even in a small office environment, but you'd better make sure no calls are in progress if you restart it in any production environment, lest you draw the ire of angry phone users. Perhaps a better way to handle the addition of a new endpoint to the softPBX is the reload method. To do this, issue the Asterisk reload command using the -rx shell option:

	# asterisk –rx reload

Or log into the Asterisk CLI (as in "Turn Your Linux Box into a PBX" [Hack #41] ) and issue the Asterisk reload command:

	pbx*CLI> reload

No calls are interrupted when the reload occurs. This should keep everyone who is using the system at that moment happy.

Now, you can place calls to the Asterisk server and to the other peers and channels that will be connected to it. The default configuration installed with Asterisk when you compiled it allows for several interesting demonstrations of its capabilities using a SIP phone. (You also can try them using an analog phone, if you have a Zaptel card installed and a phone hooked up—but that's another project [Hack #44] .)

Listening to Asterisk

In its default configuration, Asterisk has an auto-attendant that can route calls. To try it out, take the IP phone off the hook and dial 2. Then dial the BudgeTone's Send button. You will hear a friendly voice saying, "Asterisk is an open source, fully featured PBX and IVR platform…."

Tip

Try this demo while watching the call progress on Asterisk's console by issuing asterisk –vvvvvr at a Unix shell before beginning the call.

While listening to the automated attendant greeting, dial 500. This will cause the Asterisk server to greet you, connect you to a server at Digium, Inc. using the Internet, and allow you to listen to another automated greeting—the one being played back by a production Asterisk PBX at Digium's office. This connection does not use the Public Switched Telephone Network (PSTN) at all, but rather, a Voice over IP "trunk" that is set up on the fly by Asterisk.

Tip

The Voice over Internet demo requires User Datagram Protocol (UDP) port 4569. If you're using a firewall or NAT device, be sure it permits outbound traffic on this port. Most broadband routers will permit this type of traffic by default.

You can also perform an echo test by dialing 600, and you can access Asterisk's built-in voicemail service by dialing 8500. This will give you at least some idea of how your voice sounds when it's been processed and played back for the person on the other end of a call.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required