Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm having trouble with my current web host's DNS server which doesn't correctly resolve IP addresses for Baidu.

shell_exec('host -W 2 180.76.5.168');
shell_exec('nslookup 180.76.5.168');

Is there a way I can define my own DNS server address when trying to resolve the host?

Quoted output of my localhost result...

host: baiduspider-180-76-5-168.crawl.baidu.com

Server: Wireless_Broadband_Router.home Address: 192.168.1.1 Name: baiduspider-180-76-5-168.crawl.baidu.com Address: 180.76.5.168

share|improve this question
    
What is trying to resolve the name? –  Ignacio Vazquez-Abrams Jul 9 '13 at 3:34
    
@IgnacioVazquez-Abrams The IP "180.76.5.168" should resolve to "baiduspider-180-76-5-168.crawl.baidu.com" which means I can verify that this and other IP addresses are legitimate Baidu search engines. –  John Jul 9 '13 at 3:36
    
That's... not what I asked. –  Ignacio Vazquez-Abrams Jul 9 '13 at 3:37
    
@IgnacioVazquez-Abrams I think you're referring to this: php.net/shell_exec ? –  John Jul 9 '13 at 3:49
    
That function doesn't resolve anything. Are you saying that you run external executables that perform name resolution? –  Ignacio Vazquez-Abrams Jul 9 '13 at 3:50

2 Answers 2

up vote 3 down vote accepted

Is there a way I can define my own DNS server address when trying to resolve the host?

Yes, we can using following method .

Method #1 - All Method trying to resolve from Google Public DNS, you can change as you wish.

nslookup  180.76.5.168  8.8.8.8

Method #2

dig -x 180.76.5.168 @8.8.8.8

Method #3

host -W 2 180.76.5.168  8.8.8.8
share|improve this answer
    
This worked great! $p = trim(trim(explode(' pointer',shell_exec('host -W 2 180.76.5.168 68.238.96.12'))[1]),'.'); Thanks! –  John Jul 10 '13 at 5:12

On a Unix system there is a file called nsswitch.conf which controls how names of various things get resolved. For example, host names would be governed by this line in that file:

hosts:      files mdns4_minimal [NOTFOUND=return] dns

This line says:

  • Look to "files" first (such as /etc/hosts).
  • Next try "mdns4_minimal" which means try to resolve the name using Multicast DNS.
  • The "NOTFOUND" means that any response of notfound by the preceeding mdns4_minimal process should be treated as authoritative and that the system should not try to continue hunting for an answer.
  • Lastly the "dns" parameter means to use a legacy unicast DNS query.

When the name is attempting to be resolved via mdns4_minimal the file /etc/resolv.conf will be consulted to determine things such as:

  • nameservers to query
  • default search domain name
  • default domain name

For example:

# Generated by NetworkManager
domain somedom.net.
search somedom.net.
nameserver 192.168.1.101
nameserver 8.8.8.8
nameserver 8.8.4.4

So to control your default DNS server outside of the options that @RahulPatil listed in his answer you'll need to change the DNS server in your /etc/resolv.conf file.

References

share|improve this answer
    
This looks good but my question was in the context of web development with the ability to access a different DNS server on a shared server. It does look like this would be very useful to someone else though, thanks for answering. –  John Jul 10 '13 at 5:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.