skynetservices / skydns

DNS service discovery for etcd
MIT License
2.2k stars 304 forks source link

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

Open smithice opened 7 years ago

smithice commented 7 years ago

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 commented 7 years ago

Interesting, do you have any tcpdumps when this happens?

miekg commented 7 years ago

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

smithice commented 7 years ago

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 (https://github.com/skynetservices/skydns/issues/97) JAVA InetAddress seem use 'ANY' query...

miekg commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

[ Quoting notifications@github.com in "Re: [skynetservices/skydns] how to ..." ]

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

Yes, supported, but returns NODATA (I think), can't really see. What does dig ANY @coredns_server_ip test.mydomain.com return?

(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 }

Yes, supported but not doing the right thing. We could make ANY returns all A and AAAA records to accomodate this usecase, but I'm not a fan. Is there anything easy on the java side that could be done here?

smithice commented 7 years ago

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 commented 7 years ago

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

miekg commented 7 years ago

[ Quoting notifications@github.com in "Re: [skynetservices/skydns] how to ..." ]

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

No you're not missing something. Java is doing it wrong. Doing an ANY lookup to find A/AAAA records is not the correct way of doing the lookup. But we can extend the lookup mechanism to return A/AAAA in this case.

/Miek

-- Miek Gieben

smithice commented 7 years ago

thanks a lot!!

miekg commented 7 years ago

[ Quoting notifications@github.com in "Re: [skynetservices/skydns] how to ..." ]

Closed #315.

Why did you close it? You're want us to reply to ANY in CoreDNS?

/Miek

-- Miek Gieben

smithice commented 7 years ago

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