Created
March 16, 2013 02:57
-
-
Save hooopo/5174731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rubydns' | |
require 'rubydns/system' | |
# You can specify other DNS servers easily | |
# $R = Resolv::DNS.new(:nameserver => ["xx.xx.1.1", "xx.xx.2.2"]) | |
R = RubyDNS::Resolver.new(RubyDNS::System::nameservers) | |
Name = Resolv::DNS::Name | |
IN = Resolv::DNS::Resource::IN | |
RubyDNS::run_server do | |
# % dig +nocmd +noall +answer @localhost ANY dev.mydomain.org | |
# dev.mydomain.org. 16000 IN A 10.0.0.80 | |
# dev.mydomain.org. 16000 IN MX 10 mail.mydomain.org. | |
match(/dev.mydomain.org/, IN::ANY) do |match_data, transaction| | |
transaction.append_question! | |
[IN::A, IN::CNAME, IN::MX].each do |resource_class| | |
logger.debug "Appending query for #{resource_class}..." | |
transaction.append_query!(transaction.name, resource_class) | |
end | |
end | |
# For this exact address record, return an IP address | |
match("dev.mydomain.org", IN::A) do |transaction| | |
transaction.respond!("10.0.0.80") | |
end | |
match("80.0.0.10.in-addr.arpa", IN::PTR) do |transaction| | |
transaction.respond!(Name.create("dev.mydomain.org.")) | |
end | |
match("dev.mydomain.org", IN::MX) do |transaction| | |
transaction.respond!(10, Name.create("mail.mydomain.org.")) | |
end | |
match(/^test([0-9]+).mydomain.org$/, IN::A) do |match_data, transaction| | |
offset = match_data[1].to_i | |
if offset > 0 && offset < 10 | |
logger.info "Responding with address #{"10.0.0." + (90 + offset).to_s}..." | |
transaction.respond!("10.0.0." + (90 + offset).to_s) | |
else | |
logger.info "Address out of range: #{offset}!" | |
false | |
end | |
end | |
# Default DNS handler | |
otherwise do |transaction| | |
logger.info "Passing DNS request upstream..." | |
transaction.passthrough!(R) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment