Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to fix this error:"java.net.UnknownHostException: DNS service refused [response code 5]" #315

Open
smithice opened this issue Apr 17, 2017 · 12 comments

Comments

@smithice
Copy link

I use skydns as my dns server.when use ping or nslookup ,all is ok.when use java:
`import java.net.InetAddress;
import java.net.UnknownHostException;

public class FindDomain {

static {
	System.setProperty("sun.net.spi.nameservice.nameservers", "192.168.48.222");
	System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");	
}

public static void main(String[] args) {

	try {
		getHostByIPAddress();

	} catch (UnknownHostException e) {
		e.printStackTrace();
	}

}

public static void getHostByIPAddress() throws UnknownHostException {
	System.out.println(InetAddress.getByName("test.mydnsserver.com").getHostAddress());
}

}get below error:java.net.UnknownHostException: DNS service refused [response code 5]
at sun.net.spi.nameservice.dns.DNSNameService.resolve(DNSNameService.java:180)
at sun.net.spi.nameservice.dns.DNSNameService.lookupAllHostAddr(DNSNameService.java:291)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at java.net.InetAddress.getByName(InetAddress.java:1076)
at com.hundsun.FindDomain.getHostByIPAddress(FindDomain.java:33)
at com.hundsun.FindDomain.main(FindDomain.java:23)
`
am i missing some setting in skydns?

@miekg
Copy link

miekg commented Apr 17, 2017

Interesting, do you have any tcpdumps when this happens?

@miekg
Copy link

miekg commented Apr 17, 2017

Also, are you able to replicate this with coredns? (github.com/coredns/coredns)

@smithice
Copy link
Author

here is the tcpdumps:
Standard query 0x9443 ANY test.mydnsserver.com Standard query response 0x9443 Refused ANY test.mydnsserver.com
it seems like the issue (#97)
JAVA InetAddress seem use 'ANY' query...

@miekg
Copy link

miekg commented Apr 18, 2017

ANY!!!???1!? Why?

We block ANY in SkyDNS because it is such a useless query. (Didn't port that particular feature over to CoreDNS, because filtering is done in a separate middleware).

Think in CoreDNS you'll by served A records when doing an ANY lookup, meaning the above code may work.

Can this ANY behavior be disabled in Java?

@smithice
Copy link
Author

i can't find InetAddress's source code...
CoreDNS allow ANY lookup ,but find following error:
Exception in thread "main" java.net.UnknownHostException: DNS record not found at sun.net.spi.nameservice.dns.DNSNameService.resolve(DNSNameService.java:186) at sun.net.spi.nameservice.dns.DNSNameService.lookupAllHostAddr(DNSNameService.java:291) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) at java.net.InetAddress.getAllByName0(InetAddress.java:1276) at java.net.InetAddress.getAllByName(InetAddress.java:1192) at java.net.InetAddress.getAllByName(InetAddress.java:1126) at java.net.InetAddress.getByName(InetAddress.java:1076) at FindDomain.getHostByIPAddress(FindDomain.java:49) at FindDomain.main(FindDomain.java:43)
here is tcpdump:
Standard query 0x8c4e ANY test.mydomain.com Standard query response 0x8c4e ANY test.mydomain.com SOA ns.dns.mydomain.com
(nslookup or ping is ok )

here is my Corefile:
.:53 { etcd mydomain.com { stubzones path /skydns endpoint http://127.0.0.1:2379 upstream 8.8.8.8:53 } prometheus cache 160 mydomain.com loadbalance proxy . 8.8.8.8:53 }

@miekg
Copy link

miekg commented Apr 19, 2017 via email

@smithice
Copy link
Author

why return 'NODATA'? i already add A record to etcd.
am i missing something?
here is dig ANY,and A query
dig ANY @192.168.48.223 test.mydomain.com
`
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6 <<>> ANY @192.168.48.223 test.mydomain.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36889
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;test.mydomain.com. IN ANY

;; AUTHORITY SECTION:
mydomain.com. 5 IN SOA ns.dns.mydomain.com. hostmaster.mydomain.com. 1492736874 7200 1800 86400 60

;; Query time: 5 msec
;; SERVER: 192.168.48.223#53(192.168.48.223)
;; WHEN: Fri Apr 21 09:10:16 2017
;; MSG SIZE rcvd: 88
`

`
dig A @192.168.48.223 test.mydomain.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6 <<>> A @192.168.48.223 test.mydomain.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27650
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;test.mydomain.com. IN A

;; ANSWER SECTION:
test.mydomain.com. 5 IN A 192.168.48.106

;; Query time: 2 msec
;; SERVER: 192.168.48.223#53(192.168.48.223)
;; WHEN: Fri Apr 21 09:12:12 2017
;; MSG SIZE rcvd: 50
`

@smithice
Copy link
Author

smithice commented Apr 21, 2017

Cordns supported ANY lookup indeed! InetAddress is common use case in Java. am i missing something in etcd or Coredns config?

@miekg
Copy link

miekg commented Apr 21, 2017 via email

@smithice
Copy link
Author

thanks a lot!!

@miekg
Copy link

miekg commented Apr 24, 2017 via email

@smithice
Copy link
Author

smithice commented May 3, 2017

yes,i thought it can be fix in CoreDNS,but it is a problem in skydns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants