Yes I know, we have dnsmasq as caching dns-proxy installed on the system which should take care of the annoying problem, that you can't use your internal phones when internet is down, but it doesn't. At least not always Or even at all. I don't know. I personally never had an raspbx installation where internal sip registrations "survived" the internet link going down.
So what can we do?
First take a look at what we've got: dnsmasq
Which is a good thing because it's capable of using more than one hosts file.
So we "just" need to write a little quick 'n dirty shell script that creates this additional hosts file for us, which contains the addresses of our external sip servers and tell dsnmasq to use it. Simple, isn't ist? ;-)
OK, but before we start scripting we need some prerequisites:
1. nslookup (part of the dnsutils package)
2. rcconf (for managing system services the easy way)
3. daemon (to run our tiny script as a service)
=> apt-get install dnsutils rcconf daemon
Then we can put together our little "dns-resolve-robot", let's call it lookup_sip_servers and put it in /usr/local/bin, which first checks if a given external (!!!) dns server (e.g. google-dns) is up and then looks up the IPs of our external sip servers, echoing them and their respective hostnames into our additional hosts file.
|
OK, an endless loop ist definetely not the most soophisticatdt way to do it, but it gets the job done.
Originally I intended tu use multiple external DNS servers, hence the respective for-loop still being there. EDIT: I don't know why parts of the code are not visible, but if you're interested in it just copy and paste the whole section into your local editor.
Our created additional hosts file then looks like this:.:
|
Now we tell dnsmasq to use this addtional hosts file. Therefore we put a dnsmasq.conf in /etc/dnsmasq.d containing the following line:
addn-hosts=/var/run/dnsmasq/hosts.dnsmasq
|
While still having momentum we can now install our little script as a system (startup) service by puttin another tiny script, let's also call it lookup_sip_servers, in /etc/init.d:
### BEGIN INIT INFO
# Provides: lookup_sip_servers
# Required-Start: $syslog
# Default-Start: 2 3 4 5
# Required-Stop:
# Default-Stop: 0 1 6
# Short-Description: lookup_sip_servers
# Description: periodically checks DNS records of certain hostnames via nslookup and echos them
# to a custom hostz file
### END INIT INFO
PIDFILE=/var/run/lookup_sip_servers.pid
# LOG=/var/log/messages
case "$1" in
start)
if [ -e $PIDFILE ]; then
echo -e "\nDaemon seems to be running already.\n
Use: '/etc/init.d/lookup_sip_servers restart' to restart."
else
echo -en '\nStarting lookup_sip_servers...'
daemon -U -n lookup_sip_servers -X /usr/local/bin/lookup_sip_servers -F $PIDFILE
while [ ! -e $PIDFILE ];do
sleep 1s;
done
PID=$(cat $PIDFILE)
echo -e ' done. (PID='$PID')'
fi
;;
stop)
if [ -e $PIDFILE ]; then
PID=$(cat $PIDFILE)
echo -en '\nStopping lookup_sip_servers (PID='$PID')...'
kill $PID
while [ -e $PIDFILE ];do
sleep 1s
done
echo -e ' done.'
else
echo -e "\nDaemon seems not to be running."
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo -e "\nUsage: /etc/init.d/lookup_sip_servers (start|stop|restart)\n"
exit 1
esac
exit 0
|
'and activate its execution at boot time with rcconf.
The end.
I hope somebody finds this to be useful...
Last edit: Anxifer 2016-07-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot help you with the script because I don't know anything about programming, but consider this:
You don't need dnsmasq to provide real IP addresses. If your internet is down, there's no need for a real IP address because you're not going to get through anyway. You just need dnsmasq to return SOMETHING so that Asterisk doesn't freeze. That something could be 10.10.10.10 for all you care.
That fact may make the script easier to write..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes I know, we have dnsmasq as caching dns-proxy installed on the system which should take care of the annoying problem, that you can't use your internal phones when internet is down, but it doesn't. At least not always Or even at all. I don't know. I personally never had an raspbx installation where internal sip registrations "survived" the internet link going down.
So what can we do?
First take a look at what we've got: dnsmasq
Which is a good thing because it's capable of using more than one hosts file.
So we "just" need to write a little quick 'n dirty shell script that creates this additional hosts file for us, which contains the addresses of our external sip servers and tell dsnmasq to use it. Simple, isn't ist? ;-)
OK, but before we start scripting we need some prerequisites:
1. nslookup (part of the dnsutils package)
2. rcconf (for managing system services the easy way)
3. daemon (to run our tiny script as a service)
=> apt-get install dnsutils rcconf daemon
Then we can put together our little "dns-resolve-robot", let's call it lookup_sip_servers and put it in /usr/local/bin, which first checks if a given external (!!!) dns server (e.g. google-dns) is up and then looks up the IPs of our external sip servers, echoing them and their respective hostnames into our additional hosts file.
So here we go:
|
OK, an endless loop ist definetely not the most soophisticatdt way to do it, but it gets the job done.
Originally I intended tu use multiple external DNS servers, hence the respective for-loop still being there.
EDIT: I don't know why parts of the code are not visible, but if you're interested in it just copy and paste the whole section into your local editor.
Our created additional hosts file then looks like this:.:
|
Now we tell dnsmasq to use this addtional hosts file. Therefore we put a dnsmasq.conf in /etc/dnsmasq.d containing the following line:
|
While still having momentum we can now install our little script as a system (startup) service by puttin another tiny script, let's also call it lookup_sip_servers, in /etc/init.d:
|
'and activate its execution at boot time with rcconf.
The end.
I hope somebody finds this to be useful...
Last edit: Anxifer 2016-07-31
I cannot help you with the script because I don't know anything about programming, but consider this:
You don't need dnsmasq to provide real IP addresses. If your internet is down, there's no need for a real IP address because you're not going to get through anyway. You just need dnsmasq to return SOMETHING so that Asterisk doesn't freeze. That something could be 10.10.10.10 for all you care.
That fact may make the script easier to write..