· sysadmin linux

Local DNS Override for Testing

One of of primary projects involves a local telemetry agent which needs to speak to two separate endpoints. One endpoint is a command channel which provides configuration information while the second is an event channel where the agent sends telemetry and security event data.

Currently we use HAProxy to balance the event channel traffic among several servers. I wanted to move to Amazon Elastic Load Balancing to take advantage of their redundancy and reliability. So now the question is, “How can I test this before we cut all of our customers over?”

I can’t control where the agent aims event data (it looks up the DNS name of the event channel from the command channel.)

My first approach was to use DNSMasq and the alias command to simply overwrite the incoming DNS reply with the hardcoded IP of the ELB. This worked for a while but each time the ELB changes its public IP you have to update your configuration and restart DNSMasq. This is because ELB DNS names are really just fast flux A records.

If you want to use the DNSMasq approach simply add a line like this in your DNSMasq file:

# In this example rewrite so the client really
#  receives Update to use IPs as you need.

So instead I decided to find a way to just handle DNS the way I want. I found an excellent Ruby project called RubyDNS. Simply gem install rubydns to get started.

Here is my sanitized Ruby script, also available on my GitHub.

#!/usr/bin/env ruby
require 'rubydns'

    [:udp, "", 5300],
    [:tcp, "", 5300]
Name = Resolv::DNS::Name
IN = Resolv::DNS::Resource::IN

# Use upstream DNS for name resolution.
UPSTREAM = RubyDNS::Resolver.new([[:udp, "", 53], [:tcp, "", 53]])

# Start the RubyDNS server
RubyDNS::run_server(:listen => INTERFACES) do
    match(/the\.current\.dnshost/, IN::A) do |transaction|
        new = UPSTREAM.query("the.cname.i.want.to.test")

    # Default DNS handler
    otherwise do |transaction|
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket