asterisk settings HKBN 2b

Sample Asterisk config for Hong Kong BroadBand

  • Account created starting October 2005 (if your account is before October 2005 or is NOT a "2b" account, then you want to look here)
  • Softphone password: abcdef9876
  • Phone number: 35129898











;;; Beginning of stuff for NAT support



;;; End of stuff for NAT support

register =>

;;; If your account was created after Nov 2005, the register line should be:

;;; register =>




;;; If your account was created after Nov 2005, the above line should be:

;;; username=35129898hk




;;; If your account was created after Nov 2005, the above line should be:

;;; fromuser=35129898hk





; delete one of the two lines according to your bandwidth

allow=alaw ; if you have high incoming & outgoing bandwidth; i.e. > 128 kps

allow=g729 ; if you have low incoming & outgoing bandwidth; i.e. < 128 kps




;;; Default context for all incoming SIP calls without a specific context definition
exten => _X.,1,Congestion

;;; Incoming calls enter into this context
;;; I'll configure it to start the EchoTest
exten => 35129898,1,Answer
exten => 35129898,2,NoOp(==> ${TIMESTAMP}: Starting EchoTest for ${CALLERIDNUM})
exten => 35129898,3,Wait(2)
exten => 35129898,4,Playback(demo-echotest)
exten => 35129898,5,Echo
exten => 35129898,6,Playback(demo-echodone)
exten => 35129898,7,NoOp(==> ${TIMESTAMP}: Ending EchoTest for ${CALLERIDNUM})
exten => 35129898,8,Hangup

;;; Call out to the HK Observatory using HKBN
exten => 1878200,1,Dial(SIP/


You need the above entry in your /etc/hosts since HKBN has not created a DNS domain by the name of As a result, you need to have this entry in order for Asterisk to figure out which host to send your calls to and from which host calls should be accepted.

2b using at least 2 SIP Proxies

It has come to my attention that some "2b" subscribers have been moved to another SIP Proxy server. As a result, some subscribers cannot use as their SIP Proxy. The most obvious sign that you have been moved off of is if you can no longer REGISTER your presence with their SIP Proxy.

To see verify your account was moved to the other SIP Proxy, enable SIP debugging for the peer:

CLI> sip debug ip

If you see something like:

Sip read:
SIP/2.0 301 Moved Permanently
t: <>;tag=922074415
f: <>;tag=ec3f4cef5aa1376bo1
i: 46ccadff-b8c4c99b@
v: SIP/2.0/UDP;rport;branch=z9hG4bK-75923633
m: <;maddr=>
k: com.nortelnetworks.firewall,p-3rdpartycontrol,nosec
l: 0

9 headers, 0 lines

(Use "sip no debug" to turn off the debugging information.)

If you see the "301 Moved Permanently" SIP response, then that means HKBN has moved your account to another SIP Proxy besides The new SIP Proxy you should use is listed in the "m:" line. The IP address after the "maddr=" is the new SIP Proxy. The IP address corresponds to the hostname: You will need to edit the /etc/hosts file and change the line:


I followed the procedure above but couldn't get Asterisk to register with HKBN 2B, after capturing traffic of the Windows client, I discovered that the client appends the characters "hk" to the end of my username:

By changing:

register =>


register => ;; Note the string "hk"

It now registers and I can take incoming calls on that number. I have not looked at outgoing calls, but if it fails — try changing the username.

For new user of HKBN 2b around and after Feb 2006, the username is no longer just the phone number anymore. It requires addition two characters hk appended at the end in order to work. -rcc 3/10/2006

2b's Proxy registration quirks

From my tests, it appears that the (Nortel?) Proxy/Registrar used by HKBN's 2b service presents the following problems:

1. The SIP URI of the REGISTER message must contain the domain name, or else the message is rejected with status "403 - registrations to foreigndomains are forbidden" . This is problematic with Asterisk because it requires in sip.conf a "register" command containing "", and that same domain name is also used by asterisk to get the IP address of the Proxy/Registrar. Unfortunately, HKBN did not define an 'A' record for it, so the DNS resolution fails... Recent versions of Asterisk allow the "/etc/hosts" workaround described by chandave, but older versions (like the 1.0.7) apparently do not use the system resolver, and therefore ignore entries in /etc/hosts... Luckily that Proxy/Regstrar appears to support third-party registrations, so I took the "register" line out of sip.conf and now I rely upon the utility sipsak (see below).

2. The Proxy/Registrar does not allow multiple registrations with different contacts for the same user (resulting in new registrations rejected with status "403 LR1 - Login limit exceeded"), and:

3. The Proxy/Registrar doesn't seem to expire the registrations according to the "Expires:" header in the request.

The combination of 2. and 3. may create problems to clients with dynamic and often changing IP address. If a registration fails, the client should unregister all the previous contacts for that user. The following "HKBNregister" shell script, run every two minutes by a cron job on the same machine where Asterisk runs, does precisely this: first it gets the current external IP address from the output of "ipconfig ppp0" (my box also acts as router); then, using sipsak, it tries to register using as contact that IP address, and if the request fails it unregisters any existing contact (-C '*') and then it repeats the registration request (which usually succeeds):

OUR_IP="$(ifconfig ppp0 | sed -n -e 's/.*inet addr:\([.0-9]*\).*/\1/p')"

if ! { sipsak -U -x 300 -C $OUR_URI -s $HKBN_URI -a ${PWD} -p $HKBN_HOST ; }; then
sleep 1 # seems to be necessary...
sipsak -U -x 0 -C '*' -s $HKBN_URI -a ${PWD} -p $HKBN_HOST
sipsak -U -x 300 -C $OUR_URI -s $HKBN_URI -a ${PWD} -p $HKBN_HOST

For sipsak, see: ; under OpenWRT, the installation is as simple as "ipkg install sipsak".

Enzo, 4 Nov 2006

See also

Created by: chandave, Last modification: Thu 04 of Nov, 2010 (06:55 UTC) by admin
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+