DNS query

View: New views
4 Messages — Rating Filter:   Alert me  

DNS query

by jhaagmans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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::DNS::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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: DNS query

by Jeffrey L. Taylor-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Quoting jhaagmans <jaap.haagmans@...>:

>
> 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::DNS::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::DNS::Resolver.new
res.nameserver = '......'
result = res.query(domain, Net::DNS::SOA)

or even (if I understand the docs right)

return Net::DNS::Resolver.new(:nameservers => '....').query(domain, Net::DNA::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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: DNS query

by jhaagmans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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...@...> wrote:

> Quoting jhaagmans <jaap.haagm...@...>:
>
>
>
> > 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::DNS::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::DNS::Resolver.new
> res.nameserver = '......'
> result = res.query(domain, Net::DNS::SOA)
>
> or even (if I understand the docs right)
>
> return Net::DNS::Resolver.new(:nameservers => '....').query(domain, Net::DNA::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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: DNS query

by jhaagmans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---