PJSIP dns lookup problem


I have a SIP Trunk with ITSP (OTENET from Greece) where I have configured a CHAN_PJSIP correctly. The problem arises from the fact that SIP Server is FQDN, but REGISTER goes to wrong IP.

More specifically,
In order to get the correct IP of the SIP Server, I have to do DNS request to specific DNS server that they have provided. So I have configured dnsmasq to ask those DNS servers for SIP Server:

[[email protected] ~]# cat /etc/dnsmasq.d/dnsmasq-ote.conf

Additionally, the first DNS of the pbx is

[[email protected] ~]# cat /etc/resolv.conf

So when I do ping or nslookup, it returns the correct IP.

[[email protected] ~]# nslookup ims.otenet.gr

Non-authoritative answer:
Name:   ims.otenet.gr

Without the dnsmasq configuration, nslookup returns the wrong IP for SIP Server. Eg from my PC:

 nslookup ims.otenet.gr
Server:  local
Address:  XX.XX.XX.XX

Non-authoritative answer:
Name:    ims.otenet.gr

Now, what happens is that even though from linux (it’s freepbx distro) I get the correct IP from nslookup, the PJSIP trunk sends REGISTER packets to wrong IP ( instead of the right one (
If I wait long enough, eventually it uses the correct IP. And everything else works correctly (OPTIONS,INVITE etc are also being sent to correct IP after that).
But on system reboot, again it sends REGISTER to wrong IP.

IF I setup the trunk as CHAN_SIP, it works flawlessly. Having said that it’s the last configuration left for me in order to convert into full-PJSIP. So I am trying to figure that out.

Is it something I am doing wrong? What is the expected behaviour?

[[email protected] ~]# cat /etc/asterisk/dnsmgr.conf

UPDATE: If I use DNS between resolv.conf and dnsmasq the other way round, it works and returns the correct IP.
Local DNS server for local domain on dnsmasq.

[[email protected] /]# cat /etc/dnsmasq.d/dnsmasq-local.conf

DNS Servers of the ITSP on resolv.conf

cat /etc/resolv.conf

This begs the question, what is the proper configuration in such cases where there are various SIP Server FQDNs that have to be resolved from different DNS servers.

Does asterisk use resolv.conf by default and ignores dnsmasq?

Maybe I need to “ditch” resolv.conf and have only so I can set all dns configuration from dnsmasq?

Nik Sar

It should not be necessary to have any special DNS settings. If OTEnet wants you to send REGSITER requests to, you should set Outbound Proxy in the trunk to

If there is a name that resolves (via public DNS) to, you can use that in the Outbound Proxy setting.

Thanks for the reply.

In case I was misunderstood, OTEnet provides 2 different SIP Trunking services (one bundled with broadband and one just SIP Trunk for Businesses).

Both services use FQDN “ims.otenet.gr” BUT the actual IP of SIP Servers are different. For the Business SIP Trunk that I am using, I have to use otenet’s DNS, not public in order to resolve to correct SIP Server. If I use public DNS, it resolves to the broadband service IP, which is the wrong one.

Also, according to their guidelines, I HAVE to use FQDN, not IP, they advise against using IP except for testing purposes only.

If there is a name that resolves (via public DNS) to, you can use that in the Outbound Proxy setting.

No, unfortunately there is no FQDN that resolves to that IP by using public DNS. Also they probably have failover SBC with different actual IP.

My problem was the order of the DNS servers used by asterisk when resolving FQDN. It seemed to not follow specific rules defined in dnsmasq


As I mentioned in update section, I believe I solved it by using otenet DNS servers in resolv.conf and the rest DNS servers in dnsmasq. It works correctly so far, after 3 reboots.

It is still weird that it worked, because when I created the trunk as chan_sip trunk, it worked without any change.

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