I thought I'd share this simple fix here because this happens to me all the time and it really helped me on so many installations now.

Problem:

NOTICE[1234]: chan_sip.c:15876 sip_reg_timeout:-- Registration for 'XXXXXXXX@SIPPROVIDERIP' timed out, trying again (Attempt #2)

NOTICE[18755]: chan_sip.c:30121 sip_poke_noanswer: Peer 'TRUNKNAME' is now UNREACHABLE! Last qualify: 0

Description:

Asterisk trunks timeout/unreachable after WAN reconnect behind pfsende/ipfire etc

fwconsole reload does not do the trick. Cron rebooting the machine every 24 hours sucks.

Example:

https://community.freepbx.org/t/sip-trunk-turns-to-rejected-and-only-re-registers-after-a-reload/44552

Solution:

Instead of rebooting the asterisk or checking every device inbetween the asterisk and the SIP provider let's just down the NIC when the flakey SIP connection is unreachable.

1. Log into your asterisk (if you are remote)

$ ssh root@asteriskIP

2. Create a simple bash script

$ nano sipfix.sh

#!/bin/bash

test=`/usr/sbin/asterisk -rx "sip show peers"|grep UNREACHABLE|grep PATTERN`

if [ -z "$test" ]; then

echo "All trunks are online."

else

echo "Fail! A Trunk is offline."

ifdown eth0

sleep 60

ifup eth0

fi

exit 0

Note: For PATTERN I use a unique part of the trunk name(s), e.g. SIP or something. You can also monitor multiple trunks by using a common naming pattern.

3. make executalbe

$ chmod +x sipfix.sh

4. start the crontab. when prompted for editor pick nano.

$ crontab -e

5.paste this cronjob

*/5 * * * * /root/sipfix.sh > /dev/null

(strg+x)

This will check every 5 minutes.