Skip to content

Making DNS queries using Perl really simple

That is it!

use Net::DNS::Simple;
my $res = Net::DNS::Simple->new("", "MX");

I have been working with DNS for while using Perl and Net::DNS module. However something always annoyed me when I needed to write a new Perl tool, I had to spend too much time writing all the things that Net::DNS needs.

Given that I wrote a very simple module that is 100% based on Net::DNS module. I called it Net::DNS::Simple, previously named as MYResolver. There are other modules similar to Net::DNS usage easier such as Net::DNS::Resolver and  Net::DNS:Dig*.


I always use ‘local::lib’/perlbrew strategy because I don’t want to mix my production server with crazy modules.

You need the Net::DNS module. Follow all ‘cpan’ procedure by default, just press enter.

$ cpan install Net::DNS

Assuming that you have Perl modules into your ~/perl5  (PERL_LOCAL_LIB_ROOT:

Cloning Net::DNS::Simple (It is not at CPAN yet)

$ git clone

Change for whatever place your PERL_LOCAL_LIB_ROOT is pointing to:

$ cd net-dns-simple; perl Makefile.PL INSTALL_BASE=/home/kaiorafael/perl5

Make and install it

$ make ; make install

I have this output

kaiorafael $ make
cp lib/Net/DNS/ blib/lib/Net/DNS/
Manifying 1 pod document
kaiorafael $ make install
Manifying 1 pod document
Installing /home/kaiorafael/perl5/lib/perl5/Net/DNS/
Installing /home/kaiorafael/perl5/man/man3/Net::DNS::Simple.3pm
Appending installation info to /home/kaiorafael/perl5/lib/perl5/x86_64-kfreebsd-gnu-thread-multi/perllocal.pod

Please make sure that you have

$ ls  $PERL5LIB/Net/DNS/

Tested on Debian Jessie amd64/ Debian Wheezy kFreeBSD

Current Methods

*A word about About Net::DNS::Dig. It has a very week Query ID number generator and susceptible to Kaminsky’s DNS Bug. I have tried to tell the maintainer without success.

my $ID	= time % 65536;
print $ID;
[kaiorafael $] perl 
[kaiorafael $] perl 

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.