Coder Social home page Coder Social logo

dns-zonefile's Introduction

dns-zonefile

An RFC1035 compliant DNS zone file generator for Node.js.

Installation

Standalone

sudo npm install dns-zonefile -g

Module

npm install dns-zonefile

Usage

Zone Information

dns-zonefile accepts both zone data expressed as a JSON object or plain text zone file. It supports SOA, NS, A, AAAA, CNAME, MX and PTR record types as well as the $ORIGIN keyword (for zone-wide use only). Each record type (and the $ORIGIN keyword) is optional, though bind expects to find at least an SOA record in a valid zone file.

Examples

Forward DNS Zone

The following JSON produces a zone file for a forward DNS zone:

{
    "$origin": "MYDOMAIN.COM.",
    "$ttl": 3600,
    "soa": {
        "mname": "NS1.NAMESERVER.NET.",
        "rname": "HOSTMASTER.MYDOMAIN.COM.",
        "serial": "{time}",
        "refresh": 3600,
        "retry": 600,
        "expire": 604800,
        "minimum": 86400
    },
    "ns": [
        "NS1.NAMESERVER.NET.",
        "NS2.NAMESERVER.NET."
    ],
    "a": {
        "@": "127.0.0.1",
        "www": "127.0.0.1",
        "mail": "127.0.0.1"
    },
    "aaaa": {
        "@": "::1",
        "mail": "2001:db8::1"
    },
    "cname": {
        "mail1": "mail",
        "mail2": "mail"
    },
    "mx": {
        "0": "mail1",
        "10": "mail2"
    }
}

dns-zonefile will produce the following zone file from the above information, while the following zone file can as well be parsed to produce the zone file like above:

$ORIGIN MYDOMAIN.COM.
$TTL 3600
@	IN	SOA	NS1.NAMESERVER.NET.	HOSTMASTER.MYDOMAIN.COM.	(
			1406291485	 ;serial
			3600	 ;refresh
			600	 ;retry
			604800	 ;expire
			86400	 ;minimum ttl
)

@	NS	NS1.NAMESERVER.NET.
@	NS	NS2.NAMESERVER.NET.

@	MX	0	mail1
@	MX	10	mail2

@	A	127.0.0.1
www	A	127.0.0.1
mail	A	127.0.0.1

@	AAAA	::1
mail	AAAA	2001:db8::1

mail1	CNAME	mail
mail2	CNAME	mail

Reverse DNS Zone

This JSON will produce a zone file for a reverse DNS zone (the $ORIGIN keyword is recommended for reverse DNS zones):

{
	"$origin": "0.168.192.IN-ADDR.ARPA.",
	"$ttl": 3600,
	"soa": {
		"mname": "NS1.NAMESERVER.NET.",
		"rname": "HOSTMASTER.MYDOMAIN.COM.",
		"serial": "{time}",
		"refresh": 3600,
		"retry": 600,
		"expire": 604800,
		"minimum": 86400
	},
	"ns": [
		"NS1.NAMESERVER.NET.",
		"NS2.NAMESERVER.NET."
	],
	"ptr": {
		"1": "HOST1.MYDOMAIN.COM.",
		"2": "HOST2.MYDOMAIN.COM."
	}
}

dns-zonefile will produce the following zone file from the above information, while the following zone file can as well be parsed to produce the zone file like above:

$ORIGIN 0.168.192.IN-ADDR.ARPA.
$TTL 3600
@   IN  SOA   NS1.NAMESERVER.NET.	   HOSTMASTER.MYDOMAIN.COM.	 (
			   1402203462	 ;serial
			   3600	 ;refresh
			   600	 ;retry
			   604800	 ;expire
			   86400	 ;minimum ttl
)

@	NS	NS1.NAMESERVER.NET.
@	NS	NS2.NAMESERVER.NET.

1	PTR	HOST1.MYDOMAIN.COM.
2	PTR	HOST2.MYDOMAIN.COM.

Standalone Usage

To use dns-zonefile to generate a zone file from JSON from the command line, place the desired JSON data in a file (zonefile_data.json in this example) and run the following command. Note that the resulting zone file will be printed to the console; to save the zone file to disk (my_zone.conf in this example), use redirection as in this example:

zonefile -g zonefile_data.json > my_zone.conf

To use dns-zonefile to parse a zone file to JSON from the command line, place the desired zone file data in a file (zonefile_data.txt in this example) and run the following command. Note that the resulting JSON will be printed to the console; to save the JSON to disk (my_zone.json in this example), use redirection as in this example:

zonefile -p zonefile_data.txt > my_zone.json

If the -g or -p is omitted, -g will be assumed if the lower cased filename contains .json, otherwise, -p will be assumed.

zonefile -v or zonefile --version will print the version information.

Module Usage

dns-zonefile can also be used as a module. Simply use require() to include it, then invoke its generate() function as shown in the following example:

var zonefile = require('dns-zonefile');
var options = require('./zonefile_forward.json');
var output = zonefile.generate(options);
console.log(output);

options can either be a parsed JSON object as shown above, or a regular Javascript object containing the same required fields.

It is also possible to parse a zone file to JSON by invoking its parse() function as shown in the following example:

var zonefile = require('dns-zonefile');
var text = fs.readFileSync('./zonefile_forward.txt', 'utf8');
output = zonefile.parse(text);
console.log(output);

#License ISC License (ISC)

Copyright (c) 2014, Elgs Qian Chen

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

dns-zonefile's People

Contributors

elgs avatar willfe avatar christophwitzko avatar

Watchers

James Cloos avatar Hapsoro Renaldy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.