HighDots Forums  

DNS query

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss DNS query in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jhaagmans
 
Posts: n/a

Default DNS query - 11-05-2009 , 04:48 PM






Hi,

This is a bit of Ruby and a bit of Linux, but because I'm working on
this in a Rails environment, I've decided to post it here.

I use the net-dns gem to make SOA queries like the following:

def query_domain(domain)
require 'Net/DNS'
res = Net:NS::Resolver.new
result = res.query(domain, 'SOA')
return result.answer
end

This works fine and I'm happy with the results. However, this is part
of a server management setup that changes values in certain
nameservers. We also want to monitor these changes, but most of these
nameservers have a TTL of 4 hours for their domains. We can't have the
system wait for 4 hours before checking whether the procedure worked,
so I need a way to get the server at the other end to return the
result again, just a few seconds later. Is this possible? Is there a
way to make the queried DNS flush the results and request them again?

Thank you very much.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #2  
Old   
Jeffrey L. Taylor
 
Posts: n/a

Default Re: DNS query - 11-05-2009 , 05:55 PM






Quoting jhaagmans <jaap.haagmans (AT) gmail (DOT) com>:
Quote:
Hi,

This is a bit of Ruby and a bit of Linux, but because I'm working on
this in a Rails environment, I've decided to post it here.

I use the net-dns gem to make SOA queries like the following:

def query_domain(domain)
require 'Net/DNS'
res = Net:NS::Resolver.new
result = res.query(domain, 'SOA')
return result.answer
end

This works fine and I'm happy with the results. However, this is part
of a server management setup that changes values in certain
nameservers. We also want to monitor these changes, but most of these
nameservers have a TTL of 4 hours for their domains. We can't have the
system wait for 4 hours before checking whether the procedure worked,
so I need a way to get the server at the other end to return the
result again, just a few seconds later. Is this possible? Is there a
way to make the queried DNS flush the results and request them again?

How about just querying the authorative nameservers directly with:

res = Net:NS::Resolver.new
res.nameserver = '......'
result = res.query(domain, Net:NS::SOA)

or even (if I understand the docs right)

return Net:NS::Resolver.new(:nameservers => '....').query(domain, Net:NA::SOA).answer


HTH,
Jeffrey

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #3  
Old   
jhaagmans
 
Posts: n/a

Default Re: DNS query - 11-06-2009 , 07:44 AM



Multiple reasons. First, we don't really want to store the nameservers
as they might change alot, so we'd have to query our DNS for the
nameservers and then query the NS itself. After we do that, the NS
will return the same values for the time specified in the TTL. Second,
the above won't really work, it will just add the nameserver to the
default DNS list as specified in /etc/hosts, so you'd have to tell it
not to use /etc/hosts first. However, we sometimes do want to do that,
so it would be better if we could tell our own DNS (that we don't
control) not to send cached values, but query for new ones.

Thank you for your response though. The one-line-example is in fact
what we do, but not as readable


On 5 nov, 23:55, "Jeffrey L. Taylor" <r... (AT) abluz (DOT) dyndns.org> wrote:
Quote:
Quoting jhaagmans <jaap.haagm... (AT) gmail (DOT) com>:



Hi,

This is a bit of Ruby and a bit of Linux, but because I'm working on
this in a Rails environment, I've decided to post it here.

I use the net-dns gem to make SOA queries like the following:

def query_domain(domain)
* require 'Net/DNS'
* res * = Net:NS::Resolver.new
* result = res.query(domain, 'SOA')
* return result.answer
end

This works fine and I'm happy with the results. However, this is part
of a server management setup that changes values in certain
nameservers. We also want to monitor these changes, but most of these
nameservers have a TTL of 4 hours for their domains. We can't have the
system wait for 4 hours before checking whether the procedure worked,
so I need a way to get the server at the other end to return the
result again, just a few seconds later. Is this possible? Is there a
way to make the queried DNS flush the results and request them again?

How about just querying the authorative nameservers directly with:

res = Net:NS::Resolver.new
res.nameserver = '......'
result = res.query(domain, Net:NS::SOA)

or even (if I understand the docs right)

return Net:NS::Resolver.new(:nameservers => '....').query(domain, Net:NA::SOA).answer

HTH,
* Jeffrey
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #4  
Old   
jhaagmans
 
Posts: n/a

Default Re: DNS query - 11-06-2009 , 04:09 PM



Well, let's forget the above. I'd have to control the DNS server and
make sure it doesn't cache, that's not possible. Let's focus on what I
actually want to do: I want to monitor a domain for responsiveness.
But I want to do it more than once an hour and I want to make sure
nothing in between will return a cached response instead of the actual
response.

So I've written this method:

def make_request(domain)
response = Net::HTTP.new(domain).request_get('/')
if !response.nil?
domain.update_attribute(:last_up, Time.now)
end
end

It works. Once. After that, Net:HTTP.new(domain) will just give me the
cached information and I don't want that. I want to monitor it! If it
goes down, I want an empty response. How can I do that?

Thank you.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.