Bug #11152

Resolv::DNS should use Search Domains provided in /etc/resolv.conf by default

Added by IronYuppie (David Aronchick) about 5 years ago. Updated 9 months ago.

Target version:


For some reason Resolv::DNS does not use search domains. Many downstream projects rely on Resolv, and this appears broken. I'm showing this below in Kubernetes, but it's based on the search domain(s), rather than a cluster issue.

[1] pry(main)> require 'resolv'
=> true
[2] pry(main)>'client')
=> []
[3] pry(main)> nameservers = ["", "", ""]
[4] pry(main)> search_domains = ["default.kubernetes.local", "kubernetes.local", "", "", "google.internal."]
[5] pry(main)> a = => nameservers, :search => search_domains)
[6] pry(main)> a.getaddresses('client')
=> [#<Resolv::IPv4>]

Updated by tenderlovemaking (Aaron Patterson) almost 5 years ago

  • Status changed from Open to Feedback


It should parse your /etc/resolv.conf file. Can you post your /etc/resolv.conf? Maybe it's a problem with the parser.

Updated by lisinge (Micke Lisinge) almost 4 years ago

Aaron Patterson wrote:


It should parse your /etc/resolv.conf file. Can you post your /etc/resolv.conf? Maybe it's a problem with the parser.

I am seeing the same problem, tested with Ruby 2.2.5 and 2.3.1.

My code is running on a kubernetes cluster with docker just like David's.

This is the resolv.conf and David's probably looks the same:

search staging.svc.cluster.local svc.cluster.local cluster.local google.internal.
options ndots:5

With the config above Resolv::DNS::Config.default_config_hash returns:

=> {:nameserver=>[""], :search=>nil, :ndots=>1}

Updated by jeremyevans0 (Jeremy Evans) 10 months ago

It looks like the problem is a kubernetes-specific issue. With your resolv.conf file, I get the following for Resolv::DNS::Config.default_config_hash:

{:nameserver=>[""], :search=>["staging.svc.cluster.local", "svc.cluster.local", "cluster.local", "", "google.internal."], :ndots=>5}

Based on the results of yourResolv::DNS::Config.default_config_hash output, I think the only explanation is that it is the /etc/resolv.conf is different from what is displayed. What is'/etc/resolv.conf') if run directly after require 'resolv'? Alternatively, you can provide a self-contained reproducible example showing the problem?


Updated by jeremyevans0 (Jeremy Evans) 9 months ago

  • Status changed from Feedback to Closed

Also available in: Atom PDF