Zone File JS
An RFC1035-compliant DNS zone file parser and generator for Node.js and the browser. Based on the dns-zonefile
library by Elgs Qian Chen.
Installation
$ npm install zone-file
Usage
Making Zone Files
let zoneFileText =
Parsing Zone Files
let zoneFileJson =
Zone File Objects
let zoneFileData = "$origin": "MYDOMAIN.COM." "$ttl": 3600 "a": "name": "@" "ip": "127.0.0.1" "name": "www" "ip": "127.0.0.1" let zoneFile = zoneFileDatalet zoneFileString = zoneFilelet zoneFileJson = zoneFile
Background Info
This library accepts both zone data expressed as a JSON object or as a plain text zone file. It supports SOA
, NS
, A
, AAAA
, CNAME
, MX
, PTR
, SRV
, TXT
and URI
record types as well as the $ORIGIN
keyword (for zone-wide use only). Each record type
(and the $ORIGIN
keyword) is optional, although bind expects to find at least an SOA
record in a valid zone file.
Forward DNS Zone Files
The following JSON produces a zone file for a forward DNS zone:
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:
; Zone: MYDOMAIN.COM.
; Exported (yyyy-mm-ddThh:mm:ss.sssZ): 2014-09-22T21:10:36.697Z
$ORIGIN MYDOMAIN.COM.
$TTL 3600
; SOA Record
@ IN SOA NS1.NAMESERVER.NET. HOSTMASTER.MYDOMAIN.COM. (
1411420237 ;serial
3600 ;refresh
600 ;retry
604800 ;expire
86400 ;minimum ttl
)
; NS Records
@ IN NS NS1.NAMESERVER.NET.
@ IN NS NS2.NAMESERVER.NET.
; MX Records
@ IN MX 0 mail1
@ IN MX 10 mail2
; A Records
@ IN A 127.0.0.1
www IN A 127.0.0.1
mail IN A 127.0.0.1
; AAAA Records
@ IN AAAA ::1
mail IN AAAA 2001:db8::1
; CNAME Records
mail1 IN CNAME mail
mail2 IN CNAME mail
; TXT Records
txt1 IN TXT "hello"
txt2 IN TXT "world"
; SRV Records
_xmpp-client._tcp IN SRV 10 0 5222 jabber
_xmpp-server._tcp IN SRV 10 0 5269 jabber
Reverse DNS Zone Files
This JSON will produce a zone file for a reverse DNS zone (the $ORIGIN
keyword is recommended for reverse DNS zones):
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:
; Zone: 0.168.192.IN-ADDR.ARPA.
; Exported (yyyy-mm-ddThh:mm:ss.sssZ): 2014-09-22T21:10:36.698Z
$ORIGIN 0.168.192.IN-ADDR.ARPA.
$TTL 3600
; SOA Record
@ IN SOA NS1.NAMESERVER.NET. HOSTMASTER.MYDOMAIN.COM. (
1411420237 ;serial
3600 ;refresh
600 ;retry
604800 ;expire
86400 ;minimum ttl
)
; NS Records
@ IN NS NS1.NAMESERVER.NET.
@ IN NS NS2.NAMESERVER.NET.
; PTR Records
1 IN PTR HOST1.MYDOMAIN.COM.
2 IN PTR HOST2.MYDOMAIN.COM.