Adding CNAME for the root domain issue

Tony Finch dot at dotat.at
Wed Apr 27 16:03:49 UTC 2016


Baird, Josh <jbaird at follett.com> wrote:

> Any thoughts on a service like Cloudfare's 'CNAME Flattening' [1]?
>
> [1] https://blog.cloudflare.com/introducing-cname-flattening-rfc-compliant-cnames-at-a-domains-root/

Run a command like this from cron

	aname example.com www.example.com | nsupdate -l

Using the aname script below...

Tony.
-- 
f.anthony.n.finch  <dot at dotat.at>  http://dotat.at/  -  I xn--zr8h punycode
Biscay: North or northeast 4 or 5. Slight or moderate. Showers. Good.


#!/usr/bin/perl

use warnings;
use strict;

sub dig {
	my $domain = shift;
	my $type = shift;
	my $ttl;
	my @answer;
	my $qd = quotemeta $domain;
	my $qt = quotemeta $type;
	my @dig = qx{dig +norec $qd IN $qt};
	die "dig $domain IN $type: no reply\n"
	    unless @dig;
	while (@dig) {
		if ($dig[0] =~
			m{^;; ->>HEADER<<- opcode: QUERY, status: (\w+)}) {
			die "dig $domain IN $type: $1\n"
			    unless $1 eq 'NOERROR';
			last;
		}
		shift @dig;
	}
	die "dig $domain IN $type: no header\n"
	    unless @dig;
	while (@dig) {
		if ($dig[0] =~ m{^;; ANSWER SECTION:}) {
			last;
		}
		shift @dig;
	}
	die "dig $domain IN $type: no answer\n"
	    unless @dig;
	while (@dig) {
		if ($dig[0] =~ m{^\S+\s+(\d+)\s+IN\s+$qt\s+(\S+)}) {
			$ttl = $1;
			push @answer, $2;
		}
		if ($dig[0] =~ m{^;; AUTHORITY SECTION:}) {
			last;
		}
		shift @dig;
	}
	die "dig $domain IN $type: no authority\n"
	    unless @dig;
	return ($ttl, @answer);
}

sub nsupdate {
	my $domain = shift;
	my $type = shift;
	my $ttl = shift;
	print "update delete $domain IN $type\n";
	for (@_) {
		print "update add $domain $ttl IN $type $_\n";
	}
}

if (@ARGV != 2) {
	print STDERR "usage: aname <alias> <target>\n"
}

my ($alias,$target) = @ARGV;

my @A = dig $target, 'A';
my @AAAA = dig $target, 'AAAA';

nsupdate $alias, 'A', @A;
nsupdate $alias, 'AAAA', @AAAA;
print "show\nsend\nanswer\n";

exit;



More information about the bind-users mailing list