aboutsummaryrefslogtreecommitdiffstats
path: root/examples/tg15/dns/loopback.txt
blob: 87a16a8bbd92008dbe9e6e5f11dd845793bc09fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
rs1.tele 151.216.255.0 2a02:ed02:FFFF::0
rs1.distro0 151.216.255.1 2a02:ed02:FFFF::1
rs1.distro1 151.216.255.2 2a02:ed02:FFFF::2
rs1.distro2 151.216.255.3 2a02:ed02:FFFF::3
rs1.distro3 151.216.255.4 2a02:ed02:FFFF::4
rs1.distro4 151.216.255.5 2a02:ed02:FFFF::5
rs1.distro5 151.216.255.6 2a02:ed02:FFFF::6
rs1.distro6 151.216.255.7 2a02:ed02:FFFF::7
rs1.distro7 151.216.255.8 2a02:ed02:FFFF::8
fw1.tele 151.216.255.9 2a02:ed02:FFFF::9
rs1.core 151.216.255.10 2a02:ed02:FFFF::10
rs1.noc 151.216.255.11 2a02:ed02:FFFF::11
rs1.south 151.216.255.12 2a02:ed02:FFFF::12
rs1.log 151.216.255.13 2a02:ed02:FFFF::13
rs1.gamehq 151.216.255.14 2a02:ed02:FFFF::14
rs1.backstage 151.216.255.15 2a02:ed02:FFFF::15
rs1.north 151.216.255.16 2a02:ed02:FFFF::16
rs1.crew 151.216.255.17 2a02:ed02:FFFF::17
italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/perl -I /root/tgmanage
#
# USAGE:
#  Generate BIND Zone-file data based on the file hosts-to-add.txt
#  cat hosts-to-add.txt | tools/generate-dnsrr.pl 
#
#  Generate input data for nsupdate, to add FORWARD records based on hosts-to-add.txt
#  cat hosts-to-add.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns
#  
#  Generate input data for nsupdate, to add REVERSE records based on hosts-to-add.txt
#  cat hosts-to-add.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns -rev
#
#  Generate input data for nsupdate, to DELETE forward records based on hosts-to-add.txt
#  cat hosts-to-DELETE.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns -del
#  
#  Generate input data for nsupdate, to DELETE reverse records based on hosts-to-add.txt
#  cat hosts-to-DELETE.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns -rev -del
# 
#  Command-syntax to send this to nsupdate, running it on the DNS server:
#  cat file.txt | tools/generate-dnsrr.pl --dom foo -ns | ssh $dnsserver "nsupdate -k /etc/bind/Kdhcp_updater.+157+XXXXX"
#
# Format of input:
# hostname  ipv4-adress ipv6-address
#  If any of ipv4-address or ipv6-address are NOT set for the host, specify "nope"
#  Lines starting with # will (should) be skipped (comments)
#
# Example:
#
# host1  192.168.0.1 2001:db8:f00::1
# host2  nope        2001:db8:f00::2
# host3  192.168.0.3 nope
# # comment, to be ignored.
# host4  192.168.0.4

use strict;
use warnings;
use lib '..';
BEGIN {
        require "include/config.pm";
        eval {
                require "include/config.local.pm";
        };
}
use Net::IP;
use Getopt::Long;

my ($delete, $auto, $nsupdate, $reverse, $domain);

if (@ARGV > 0) {
	GetOptions(
	'del|delete'		=> \$delete,
	'a|auto'		=> \$auto,
	'ns|nsupdate'		=> \$nsupdate,
	'r|reverse'		=> \$reverse,
	'domain=s'		=> \$domain
	)
}

if ($nsupdate || $reverse){
	unless (defined($domain)){
		print "Missing domain.\n";
		exit 1 unless defined($domain);
	}
}

$domain = "." . $domain if defined($domain);

print "server $nms::config::pri_v4\n" if ($nsupdate || $reverse);

while (<STDIN>) {
	next if /^(#|\s+$)/;	# skip if comment, or blank line

	my ($hostname, $ipv4, $ipv6) = split;
	$hostname = lc($hostname);
	
	unless ($ipv6){
		if ($auto){
			# Get IPv6-address based on IPv4-address
		
			my ($first, $second, $third, $fourth) = split('\.', $ipv4);
			# TODO: Need to do some more logic, since base_ipv6net looks like '2a02:ed02::/32'
			#$ipv6 = $nms::config::base_ipv6net . $third . "::" . $fourth;
		}
	}
	
	if ($reverse){
		# print ptr
		print_ptr($hostname, $ipv4, $ipv6);
	} else {
		# print forward
		print_fwd($hostname, $ipv4, $ipv6);
	}
}

sub print_ptr{
	my ($hostname, $ipv4, $ipv6) = @_;

	# IPv4
	unless ( $ipv4 eq "nope" ) {
		my $v4 = new Net::IP($ipv4);
		
		print "prereq nxdomain " . $v4->reverse_ip() . "\n" unless $delete;
		print "update add " . $v4->reverse_ip() . " 3600 IN PTR " . $hostname . $domain .".\n" unless $delete;
		print "update delete "  . $v4->reverse_ip() . " IN PTR\n" if $delete;
		print "send\n";
	}	

	# IPv6
	if (( not ($ipv6 eq "nope") ) && ( $ipv6 )) {
		my $v6 = new Net::IP($ipv6);
		
		print "prereq nxdomain " . $v6->reverse_ip() . "\n" unless $delete;
		print "update add " . $v6->reverse_ip() . " 3600 IN PTR " . $hostname . $domain . ".\n" unless $delete;
		print "update delete " . $v6->reverse_ip() . " IN PTR\n" if $delete;
		print "send\n";
	}
}

sub print_fwd{
	my ($hostname, $ipv4, $ipv6) = @_;
	
	if ($nsupdate){

		unless ( $ipv4 eq "nope" ) {
			# IPv4
			print "prereq nxrrset " . $hostname . $domain . " IN A\n" unless $delete;
			print "update add " . $hostname . $domain . " 3600 IN A $ipv4\n" unless $delete;
			print "update delete " . $hostname . $domain . " IN A\n" if $delete;
			print "send\n";
		}
		if (( not ($ipv6 eq "nope") ) && ( $ipv6 )) {
			# IPv6
			print "prereq nxrrset " . $hostname . $domain . " IN AAAA\n" unless $delete;
                	print "update add " . $hostname . $domain . " 3600 IN AAAA $ipv6\n" unless $delete;
	                print "update delete " . $hostname . $domain . " IN AAAA\n" if $delete;
        	        print "send\n";
		}
	} else {
		# IPv4
		unless ( $ipv4 eq "nope" ) {
			printf ("%-24s%s\t%s\t%s\n", $hostname, "IN", "A", $ipv4);
		}
		# IPv6
		if (( not ($ipv6 eq "nope") ) && ( $ipv6 )) {
			printf ("%-24s%s\t%s\t%s\n", $hostname, "IN", "AAAA", $ipv6) if ($ipv6);
		}
	}
}