Solved

Asterisk Ports question

Posted on 2009-05-17
24
858 Views
Last Modified: 2013-11-12
I have one Asterisk server, and then 2 sip peers over the WAN, at different remote locations.  They are a linksys spa942 phone and a linksys pap2 ATA.  My Asterisk box is using port 5060 to communicate with the spa942 over the wan, which is normal.  But then it is using 5061, to communicate with the pap2 ata.  Why is it using 5061, if my linksys PAP2 is set on 5060?  I had to change the port on the linksys PAP2, to 5061 in order to receive inbound calls.  Originally PAP2 was set to use 5060 and would register fine with asterisk, could place calls but could NOT receive calls.  So I did a SIP SET DEBUG on asterisk and saw when it was sending data to the Linksys PAP2, it was sending on port 5061.  Is this something Asterisk does when it has multiple peers?  
0
Comment
Question by:jkockler
  • 11
  • 6
  • 6
  • +1
24 Comments
 
LVL 9

Expert Comment

by:michofreiha
ID: 24407348
Dear Sir,

did you define the port value in sip.conf?

Regards
0
 
LVL 4

Author Comment

by:jkockler
ID: 24407380
No I did not but I bet that would help.  Could you provide me the syntax and which context to put it under?  thanks
0
 
LVL 4

Author Comment

by:jkockler
ID: 24407450
Correction.  I do have the "bindport" specified as 5060 in the sip.conf, under the general context.
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 24407469
Dear Sir,

Kindly fix the port value as follow in sip.conf

                                ; Set this to your host name or domain name
bindport=5060                   ; UDP Port to bind to (SIP standard port is 5060)
                                ; bindport is the local UDP port that Asterisk will listen on
bindaddr=8Asterisk_IP

After that reload asterisk and configure all your endpoint to use port 5060 for SIP and everything will work fine

Regards
0
 
LVL 4

Author Comment

by:jkockler
ID: 24407489
Thanks michofreiha, but I already have the bindport set to 5060.  Is there a way to specify the port for each peer individually?  Maybe in the peer context?
0
 
LVL 9

Assisted Solution

by:michofreiha
michofreiha earned 100 total points
ID: 24407572
Dear Sir,
No this could not be done...Asterisk listen on 1 port only and should be defined under general context

Regards

0
 
LVL 4

Author Comment

by:jkockler
ID: 24408040
Then why is it communicating with my Linksys PAP2 on port 5061?
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 24409827
Dear Sir,

Peer tell asterisk which port it needs to use and not the opposite...So if your endpoint send a request to asterisk on port 5061 then asterisk will accept it but it'll reply back to it on the port defined on bindport value under general context

regards
0
 
LVL 19

Accepted Solution

by:
feptias earned 400 total points
ID: 24409982
> "Is this something Asterisk does when it has multiple peers?"
No, Asterisk will send to registered UA's on the port that they specify in their Contact header during registration. i.e. the UA tells Asterisk what port it can be reached on. This means your  PAP2 must have been telling Asterisk it wanted to be contacted on 5061. Perhaps this is because 5061 is the default port for SIP over TLS, in which case you may need to adjust some settings on the PAP2 to disable TLS. Another explanation is that the PAP2 uses 5060 for one account and 5061 for the next (assuming it has multiple accounts).

The bindport parameter specified in sip.conf only tells Asterisk which port it should listen for SIP. It does not tell Asterisk which port to send to when it wants to reach a UA. It is very unlikely that the UA would care which port SIP messages are coming from - it only cares which port they arrive at. So, for example, Asterisk could use a randomly selected port to send SIP requests to port 5060 on your PAP2 and it should work fine as long as the PAP2 sends responses back to whichever port was specified in "bindport". It would know this from the Via that is included in the SIP request (or use 5060 by default if no port is specified in the Via).
0
 
LVL 4

Author Comment

by:jkockler
ID: 24410284
Thanks for the info but I still have some discrepancies.

The bindport is set to 5060 in asterisk but yet asterisk is receiving requests from the PAP2 on 5061.  How is it possible that it is receiving requests on 5061, if it is listening on 5060?
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 24410334
And the PAP2 is registered using this SIP port?
0
 
LVL 4

Author Comment

by:jkockler
ID: 24410353
Yes, everything coming from that device is specified with its ip address in this format, even the registrations :  xxx.xx.xx.xxx: 5061
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Expert Comment

by:michofreiha
ID: 24410525
And you are able to make calls from this PAP2 registered using port 5061?
0
 
LVL 4

Author Comment

by:jkockler
ID: 24410609
Yes I am able to make and receive calls on 5061 to the PAP.  I am also able to make and receive calls on 5060 with a linksys spa942.  You may be asking, what is the problem then?  Well just having it work is not good enough for me.  I want to know the reason for it's behavior, so I am able to expand the solution with accurate planning.
0
 
LVL 4

Expert Comment

by:denisdsr20
ID: 24410880
Do not forget you are using UDP, it requires 2 UDP port for each endpoint.

1 UDP port is used to contact the server, let say IP_asterisk:5060 (asterisk will get the request on 5060=bindport) (in configuration files for UA it's called sipProxy/sipServer or registrar IP/port)

+ 1 UDP port to receive requests let say 5061, in this case the UA should inform the SIPServer that the contact point is uaIP:5061 (to receive incoming calls for instance) this is defined by the UA in register requests as contact details.

To summarize :
UA   -> REGISTER-> asterisk on 5060 (contact in regsiter request says UA:5061)
asterisk -> INVITE/CALL -> UA on 5061

Regards

Denis DIDIER
SR20 Service / France
0
 
LVL 19

Expert Comment

by:feptias
ID: 24412386
I think this discussion is now confusing the port number used by Asterisk with that used by the PAP2. Can you please check the following and report back exactly how they are set (well, scramble any IP addresses if you want):
PAP2 > Line 1 > SIP Settings > SIP Port
PAP2 > Line 1 > Proxy and Registration > Proxy
PAP2 > Line 1 > Proxy and Registration > Outbound Proxy
PAP2 > Line 2 > SIP Settings > SIP Port
PAP2 > Line 2 > Proxy and Registration > Proxy
PAP2 > Line 2 > Proxy and Registration > Outbound Proxy

On your Asterisk server, go to the Linux command prompt and type this command:
netstat -lunp
Paste back here the exact output. If your version of Linux doesn't recognise option p, then just use netstat -lun.
0
 
LVL 4

Author Comment

by:jkockler
ID: 24413339
Thanks fepitas, and denisdsr20, the info is below.  Remember that right now I have the PAP using 5061 because asterisk was sending data to it on 5061.  Originally I had the PAP on 5060 in line 1 and line 2 but it could only make calls and not receive.  In order to receive calls, I had to change the PAP lines to 5061

Another interesting piece of information I found, is that you CAN specify specific ports for each peer, using the "port=" command for the peer in sip.conf.  That might solve this whole question, but either way, here is the info:


PAP2 > Line 1 > SIP Settings > SIP Port = 5061
PAP2 > Line 1 > Proxy and Registration > Proxy = My public ip address of the asterisk server
PAP2 > Line 1 > Proxy and Registration > Outbound Proxy = My public ip address of the asterisk server
PAP2 > Line 2 > SIP Settings > SIP Port = 5061
PAP2 > Line 2 > Proxy and Registration > Proxy = asterisk public ip
PAP2 > Line 2 > Proxy and Registration > Outbound Proxy =  asterisk public ip


Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
udp        0      0 0.0.0.0:2727            0.0.0.0:*                           6946/asterisk  
udp        0      0 0.0.0.0:4520            0.0.0.0:*                           6946/asterisk  
udp        0      0 0.0.0.0:50608           0.0.0.0:*                           4785/avahi-daemon:
udp        0      0 0.0.0.0:5060            0.0.0.0:*                           6946/asterisk  
udp        0      0 0.0.0.0:68              0.0.0.0:*                           5573/dhclient  
udp        0      0 0.0.0.0:4569            0.0.0.0:*                           6946/asterisk  
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           4785/avahi-daemon:
0
 
LVL 19

Expert Comment

by:feptias
ID: 24413472
Your Asterisk server is only listening on port 5060 for SIP. Your PAP2 is using port 5061 - i.e. it is listening on port 5061 and will almost certainly send SIP messages from port 5061, but it will send them to port 5060 on the Asterisk server.
0
 
LVL 19

Expert Comment

by:feptias
ID: 24413548
By the way, the problem you had when using port 5060 on the PAP2 must be something else. It would not be because Asterisk was sending to 5061. It would have no reason to do so. Asterisk will send its SIP messages to whatever port the PAP2 tells it to at the time when the PAP2 registers. That will be the "SIP Port" setting on Line 1/2.

Another thing - I can't see any point in having the same registration details for line 1 and line 2. At least, you should not allow both lines to register with an Asterisk server, especially both using the same port. Asterisk will not accept multiple registrations for the same SIP user - it only remembers the most recent one (the last one that registered). It would also be unable to send SIP requests to a specific line on the PAP2 because they are both on the same port so cannot be distinguished.
0
 
LVL 4

Author Comment

by:jkockler
ID: 24413899
Then why am I seeing all communication from the PAP to the asterisk server through 5061 .. the ip address in the sip trace looks like this, for incoming and outgoing : xxx.x.xx.xxx : 5061

As for the original issue, as soon as I changed the PAP from 5060 to 5061, the problem resolved.  If I put the PAP back to 5060, then I can only make calls, and not receive them.

And I have a question about something you said, "i.e the pap is listening on 5061 but sending to asterisk on 5060" .... Wny do you assume it is sending to asterisk on 5060?
0
 
LVL 19

Assisted Solution

by:feptias
feptias earned 400 total points
ID: 24414147
Entirely reasonable questions which I shall do my best to answer:

1. Please can you post here a section of the sip trace so we can see exactly what you mean about all communication from PAP to Asterisk going through 5061. Is it a sip trace from Asterisk sip debug or Wireshark or something else?

2. There could be a number of other reasons why the PAP will not accept incoming calls when using 5060. Is the PAP behind NAT? Are there any other SIP devices on the same subnet as the PAP? Is there a firewall? Could the ISP be blocking 5060? Had the PAP re-registered since the last changes were made? Did you have both Line 1 and Line 2 configured with identical details? etc.

3. It will send to Asterisk on 5060 unless you tell it to use a different port. You would do that by specifying the port number in these settings:
PAP2 > Line 1 > Proxy and Registration > Proxy = My public ip address of the asterisk server
PAP2 > Line 1 > Proxy and Registration > Outbound Proxy = My public ip address of the asterisk server

For example,
PAP2 > Line 1 > Proxy and Registration > Outbound Proxy = 123.123.123.123:5061

Since you did not mention that you had appended a port number for these parameters, I concluded that the PAP would send to 5060.
0
 
LVL 19

Expert Comment

by:feptias
ID: 24414721
There is another possibility, mentioned earlier. Port 5061 is the default port for SIP over TLS. Asterisk 1.6 provides support for TLS and I believe the PAP2 is also capable of supporting it. You could check if Asterisk is listening on TCP port 5061 using this Linux command:
netstat -ltnp
You can also see if TLS is enabled by looking at the output from the Asterisk CLI command "sip show settings".

On the PAP, check this setting:
PAP2 > Line 1 > SIP Settings > SIP Transport
0
 
LVL 4

Author Comment

by:jkockler
ID: 24414828
Ahh ok.  That answers a lot.  Now that I know how to specify what port the PAP sends data to asterisk on, it makes more sense.  I thought the sip port setting controlled the listening and sending.  I am thinking that the ISP might have been blocking 5060.  It's a comcast residential account, so maybe they are trying to force people to use their phone service.

Now the "port=" command that I found for use with the peers in sip.conf .. I am assuming that is to tell asterisk what port the peer is listening on,, and Not what port asterisk is listening on for that peer.  Right??
0
 
LVL 4

Author Comment

by:jkockler
ID: 24414918
Thanks Fepitas!   I think we are done here, for now.

Could you check out my other thread, I am kind of dead in the water with it. Thanks

http://www.experts-exchange.com/viewQuestion.jsp?shareit=hrN7lDamWT7Tf5ZMZ9nQI1231uWUs4aIR/%2BCDvQJmXDjQBOk0fpA3p7c1zfPY27vV0z2jelXZa0%3D&shared=0&cid=864
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now