Wether you want to be able to register silly domain names like check.out.this.silly.domain.iamhigham.com or you wish to create domain entries programmatically, the following handy piece of Ruby is for you.
One of the reasons I enjoy using Ruby so much is the wider community’s passion for creating just about anything in this awesome language, for example RubyDNS by OrionTransfer. Looking at the example on the aforementioned link you can see a a fully daemonised DNS server which can resolve anything you can throw at it.
It doesn’t take a total genius (me!) to then integrate a very simple collection queried from MongoDB using the “mongo” gem and add a few more “transaction.respond!” statements…
db = Connection.new.db('dnsstore')
entries = db.collection('dnsentries')
entries.find().each do |entry|
puts "Matching entry #{entry['domain']}"
match(entry["domain"], :A) do |transaction|
transaction.respond!(entry["host"])
end
end
Add this to the code on the examples page to form a DNS server that loads records from a database on start-up!
Add an entry to my servers IP tables for UDP:53 and were done. All I need to do now is wait for my registrar to register ns1.tactusworks.com as a name server! Let me check…. nope, nothing
Go ahead though, try it, open up bash, run nslookup tell it which nameserver to use;
server www.tactusworks.com
and then just type in a domain to check, any old domain name is from my datacenter’s DNS server and dev.rackableapps.com is from the Ruby DNS server!
One Comment
Hi, thanks for mentioning my project, RubyDNS. I thought I’d mention that while the current version (1.x) works fine, it only supports UDP. I’ve been working on a complete rewrite (2.x) but haven’t released it yet, which supports both UDP and TCP. Until it supports TCP, it cannot respond to some types of queries (larger than a single UDP packet). Again, thanks for mentioning my project