All phones lost registration and unable to register until asterisk is restarted

At first I saw some errors:
pjsip: tsx0xa908f11c .Failed to send Request msg OPTIONS/cseq=47035 (tdta0xa3dbedb0)! err=320046 (No working DNS nameserver (PJLIB_UTIL_EDNSNOWORKINGNS))
pjsip: tsx0xb3fd360c Failed to send Request msg OPTIONS/cseq=37043 (tdta0xa6dd23d0)! err=70009 (Operation timed out (PJ_ETIMEDOUT))

I have experienced problems with chan_sip if dns service was unresponsive.

after sometime phones started to unregister:
res_pjsip/pjsip_configuration.c: Contact 101/sip:[email protected]:5060 has been deleted
res_pjsip/pjsip_configuration.c: Endpoint 101is now Unreachable

And they did not reregister after that.
I have restarted asterisk - now everything works fine.
What is it? How did it happen? How to prevent it?

Asterisk 13.5.0 built by mockbuild @ on a i686 running Linux on 2015-08-10 13:54:19 UTC
FreePBX 13.0.79

Obvious stupid answer: set up a forwarding DNS in your local domain and add all of your phones and servers to the phone server’s “/etc/hosts” file.