Install net: DNS Module
Perl-mcpan-e "Install net: DNS"
Script Simulation
#!/usr/bin/perluse Net::DNS::Nameserver;use strict;use warnings;sub reply_handler { my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_; my ($rcode, @ans, @auth, @add); print "Received query from $peerhost to ". $conn->{"sockhost"}. "\n"; $query->print; if ($qtype eq "A" && $qname eq "www.ddos.com" ) { my ($ttl, $rdata) = (3600, "10.1.2.3"); #push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata"); push @ans, Net::DNS::RR->new("www.ddos.com 0 IN CNAME guard.ddos.com"); $rcode = "NOERROR"; }elsif( $qname eq "www.ddos.com" ) { $rcode = "NOERROR"; }else{ $rcode = "NXDOMAIN"; } # mark the answer as authoritive (by setting the 'aa' flag return ($rcode, \@ans, \@auth, \@add, { aa => 1 });}my $ns = Net::DNS::Nameserver->new( LocalPort => 53, ReplyHandler => \&reply_handler, Verbose => 1, ) || die "couldn't create nameserver object\n";$ns->main_loop;
Execute scripts
Perl-W srv. pl