# Pjsip issues: wrong phone rings

**URL:** <https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957>\
**Category:** Endpoints\
**Created:** [April 28, 2023, 8:22pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957 "2023-04-28T20:22:43Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bksales](https://community.freepbx.org/user_avatar/community.freepbx.org/bksales/32/9405_2.png) [@bksales](https://community.freepbx.org/u/bksales)\
**Post date:** [April 28, 2023, 8:22pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/1 "2023-04-28T20:22:43Z")

</div>

Not sure how to better title this, but what i see happening is that after the internet drops and comes back sometimes the PBX is confusing phones. One time x101 rang but the server thought it was x108 that took the call. On another PBX x1005 rang but it thinks it’s x1002 that was on the phone. In both cases the phones are at the same public IP, so I assume that’s related to the issue. I’m sure there is some setting that was changed somewhere. What am I missing?

---

<div class="post-metadata">

**Author:** ![bksales](https://community.freepbx.org/user_avatar/community.freepbx.org/bksales/32/9405_2.png) [@bksales](https://community.freepbx.org/u/bksales)\
**Post date:** [April 28, 2023, 8:28pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/2 "2023-04-28T20:28:59Z")

</div>

Also, in both cases restarting the phone seems to fix the issue. The PBX sees the correct phone unregister and re-register and then the behavior is corrected. Extensions have randomly generated and unique SIP secrets.

---

<div class="post-metadata">

**Author:** ![jcolp](https://community.freepbx.org/user_avatar/community.freepbx.org/jcolp/32/29924_2.png) [@jcolp](https://community.freepbx.org/u/jcolp)\
**Post date:** [April 28, 2023, 8:49pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/3 "2023-04-28T20:49:35Z")

</div>

There’s no setting in PJSIP. It sends the SIP INVITE to the registered IP address and port. If the router changes the mapping such that the external IP address and port go to a different internal IP address and port, then this would happen. You could check by looking at the log of where they originally registered and where Asterisk sent the SIP INVITE. If it’s the same, then that’s the problem and outside of anything Asterisk can do.

---

<div class="post-metadata">

**Author:** ![bksales](https://community.freepbx.org/user_avatar/community.freepbx.org/bksales/32/9405_2.png) [@bksales](https://community.freepbx.org/u/bksales)\
**Post date:** [April 28, 2023, 9:13pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/4 "2023-04-28T21:13:58Z")

</div>

That’s probably it. The first phone to reach out registers on 5160 and the others get another port number. I’m guessing that restarting the router or breaking the connection is causing the ports to get moved around. Whats the best way around this if I dont have access to the router?

---

<div class="post-metadata">

**Author:** ![david55](https://community.freepbx.org/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@david55](https://community.freepbx.org/u/david55)\
**Post date:** [April 28, 2023, 9:46pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/5 "2023-04-28T21:46:07Z")

</div>

If the phones are scattered over the internet, I can only think of setting a very short re-registration interval. and setting new registration to overwrite old ones.

If they are all on one remote, site, use a VPN.

---

<div class="post-metadata">

**Author:** ![bksales](https://community.freepbx.org/user_avatar/community.freepbx.org/bksales/32/9405_2.png) [@bksales](https://community.freepbx.org/u/bksales)\
**Post date:** [May 1, 2023, 6:22pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/6 "2023-05-01T18:22:07Z")

</div>

Between each phone and the phone system, or between the router and the phone system?

---

<div class="post-metadata">

**Author:** ![dobrosavljevic](https://community.freepbx.org/user_avatar/community.freepbx.org/dobrosavljevic/32/30258_2.png) [@dobrosavljevic](https://community.freepbx.org/u/dobrosavljevic)\
**Post date:** [May 1, 2023, 6:23pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/7 "2023-05-01T18:23:13Z")

</div>

Depending on your environment but if the phones are all over and not in a single location then between the individual phones and the phone system.

---

<div class="post-metadata">

**Author:** ![david55](https://community.freepbx.org/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@david55](https://community.freepbx.org/u/david55)\
**Post date:** [May 1, 2023, 7:09pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/8 "2023-05-01T19:09:09Z")

</div>

Between the single remote site and the site with Asterisk.

---

<div class="post-metadata">

**Author:** ![david55](https://community.freepbx.org/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@david55](https://community.freepbx.org/u/david55)\
**Post date:** [May 1, 2023, 7:35pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/9 "2023-05-01T19:35:53Z")

</div>

I think there is a risk that the VPN “connection” will get shuffled.

---

<div class="post-metadata">

**Author:** ![dobrosavljevic](https://community.freepbx.org/user_avatar/community.freepbx.org/dobrosavljevic/32/30258_2.png) [@dobrosavljevic](https://community.freepbx.org/u/dobrosavljevic)\
**Post date:** [May 1, 2023, 8:00pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/10 "2023-05-01T20:00:49Z")

</div>

Yea, you are correct. I guess it all depends on the upstream hardware and how it handles the different connections. I guess if it’s screwing up the SIP sessions then maybe it won’t be that good at handling NAT of the OpenVPN tunnels either.

---

<div class="post-metadata">

**Author:** ![Stewart1](https://community.freepbx.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@Stewart1](https://community.freepbx.org/u/Stewart1)\
**Post date:** [May 2, 2023, 1:04am UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/11 "2023-05-02T01:04:32Z")

</div>

There is almost certainly no need to set up a VPN or other complex solution.

First, check the value of Contact at Reports → Asterisk Info → Peers to see whether one of the phones at a multiphone location shows the same port as its SIP local port. If so, that indicates that the router/firewall at that location rewrites the source port only to avoid a conflict. In that case, setting a unique local port on each device should eliminate this issue.

However, regardless of the above, set a short registration expiry, e.g. 120 seconds on each device. If source ports are always being rewritten, this will at least ensure that any calls received at least two minutes after an internet outage is over will be properly routed. If you can avoid rewriting with unique ports, this should ensure that a call can be received within two minutes after a router restart.

Note that some devices have different timeouts for registration retry that you may need to adjust.

If you still have trouble,

> [@Max\_contacts, remove\_existing, and unavailable contacts](https://community.freepbx.org/t/max-contacts-remove-existing-and-unavailable-contacts/77090):
>
> This is really an Asterisk issue, but because this first appeared in these forums recently I’m posting this here. The default behavior in FreePBX is when max\_contacts for a PJSIP endpoint is set greater than 1, remove\_existing is set to no. This will ensure that the first endpoints to register to a particular endpoint will not be overwritten by subsequent registrations that exceed max\_contacts. I have run into a problem several times now, especially when my endpoints are behind SonicWALL rout…

may be helpful.

---

<div class="post-metadata">

**Author:** ![bksales](https://community.freepbx.org/user_avatar/community.freepbx.org/bksales/32/9405_2.png) [@bksales](https://community.freepbx.org/u/bksales)\
**Post date:** [May 2, 2023, 6:31pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/12 "2023-05-02T18:31:31Z")

</div>

Thanks, it helps, but what is your recomendation? Leave the “remove existing” as no or set it to yes? Can I force the phone to pick a port or can that only be done in the router?

---

<div class="post-metadata">

**Author:** ![system](https://community.freepbx.org/uploads/default/original/3X/f/7/f7056d57e04fdbf71c6ad967e1ced351317f5c3f.png) [@system](https://community.freepbx.org/u/system)\
**Post date:** [June 2, 2023, 6:32pm UTC](https://community.freepbx.org/t/pjsip-issues-wrong-phone-rings/89957/13 "2023-06-02T18:32:26Z")

</div>

Closed on June 2, 2023, 6:32pm UTC

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
