PJSIP dns lookup problem

Hi,

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
server=/ims.otenet.gr/195.167.21.200
server=/ims.otenet.gr/195.167.22.200

Additionally, the first DNS of the pbx is 127.0.0.1

[[email protected] ~]# cat /etc/resolv.conf
nameserver 127.0.0.1
nameserver 192.168.57.10
nameserver 8.8.8.8

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

[[email protected] ~]# nslookup ims.otenet.gr
Server:         127.0.0.1
Address:        127.0.0.1#53

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

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
Address:  195.167.16.30

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 (195.167.16.30) instead of the right one (195.167.16.182).
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
[general]
enable=yes
refreshinterval=300

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
server=/[local-domain-name.com]/192.168.57.10

DNS Servers of the ITSP on resolv.conf

cat /etc/resolv.conf
nameserver 127.0.0.1
nameserver 195.167.21.200
nameserver 195.167.22.200

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 127.0.0.1 so I can set all dns configuration from dnsmasq?

Thanks,
Nik Sar

It should not be necessary to have any special DNS settings. If OTEnet wants you to send REGSITER requests to 195.167.16.182, you should set Outbound Proxy in the trunk to
sip:195.167.16.182\;lr\;hide

If there is a name that resolves (via public DNS) to 195.167.16.182, 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 195.167.16.182, 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

server=/ims.otenet.gr/195.167.21.200
server=/ims.otenet.gr/195.167.22.200

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.