I'd like to resolve a domain name somedomain.com to a CNAME (AWS load balancer, e.g. some-balancer-1213231237.ap-southeast-2.elb.amazonaws.com), but only locally.

What I mean to achieve is that whenever I try to visit somedomain.com, I want to be served by the above mentioned load-balancer - this should only be limited to my own computer.

It's not possible to achieve this by editing /etc/hosts as in there only A records (IP addresses) can be mapped. I read somewhere that dnsmasq would be the most robust solution to achieve this. However, the documentation is very unclear about how this can be achieve. I'd appreciate your advice and perhaps a piece of config with an example. Thanks!

  • I'm sorry I don't know if it's possible with dnsmasq (I think it probably isn't). But if you're willing to use Bind, it'd be quite easy. – rsuarez Mar 10 '17 at 12:42
  • I found an alternative with Unbound. serverfault.com/a/137984/368240 – Christophe Morio Dec 27 '17 at 14:22

You can add the following to your configuration file in dnsmasq:


as specified in the man page:


Return a CNAME record which indicates that <cname> is really <target>. There are significant limitations on the target; it must be a DNS name which is known to dnsmasq from /etc/hosts (or additional hosts files), from DHCP, from --interface-name or from another --cname. If the target does not satisfy this criteria, the whole cname is ignored. The cname must be unique, but it is permissible to have more than one cname pointing to the same target. Indeed it's possible to declare multiple cnames to a target in a single line, like so: --cname=cname1,cname2,target

If the time-to-live is given, it overrides the default, which is zero or the value of --local-ttl. The value is a positive integer and gives the time-to-live in seconds.

As the man page specifies, you will have to define the target in your /etc/hosts file though:   some-balancer-1213231237.ap-southeast-2.elb.amazonaws.com

So I'm not sure this would be very useful to you.

|improve this answer|||||
  • I get that this is how the dnsmasq manual is written, but them referring to the owner name as cname when it's clearly the record data that is the cname (what they call target) just makes for very confusing reading (particularly as they keep referring to cname in the text, with the opposite meaning of what one would expect). I don't know if there's any way to fix that without just giving up on quoting the manual, though. – Håkan Lindqvist Jan 5 '19 at 15:49
  • 1
    A CNAME record in dnsmasq won't work for this use case. As written in the dnsmaq manual that you quoted: "there are significant limitations on the target". An external target like what @luqo33 mentioned (e.g. some-balancer-1213231237.ap-southeast-2.elb.amazonaws.com) won't be accepted by dnsmasq. – dllud Jan 21 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.