1.1.9 • Published 5 years ago

node_dns_changer v1.1.9

Weekly downloads
-
License
GPL-3.0
Repository
gitlab
Last release
5 years ago

node_dns_changer

A multiplatform (Linux, Windows, macOS) DNS library for changing DNS servers written in NodeJS.

Notes

  • IMPORTANT: Requires root/sudo/admin privileges to adjust any settings.
  • DNSbackupName doesn't need to be provided
  • Tested on: - Linux: - openSUSE Leap 15 - Ubuntu 18.04 - Fedora 28 - Windows - 7 (SP1) - 8.1 - 10 (1803, 1809) - macOS (El Capitan, Sierra, Mojave)
  • May have problems working with Hyper-V switches on Windows

Installing

$ npm i node_dns_changer

Usage

Standard usage:

const dns_changer = require('node_dns_changer');

// set DNS servers with backup name of 'dnsBackup'
dns_changer.setDNSservers({
	DNSservers: ['8.8.8.8','8.8.4.4'],
	mkBackup: true,
	DNSbackupName: 'dnsBackup'
});

// restore settings with logging enabled
dns_changer.restoreDNSservers({
	DNSbackupName: 'dnsBackup',
	loggingEnable: true,
	rmBackup: true
});

// setup DNS servers without a custom backup name
dns_changer.setDNSservers({
	DNSservers: ['8.8.8.8','8.8.4.4']
});

// restore settings without a custom backup name
dns_changer.restoreDNSservers({});

Promises support:

const dns_changer = require('node_dns_changer');

// set DNS servers with backup name of 'dnsBackup'
dns_changer.setDNSservers({
	DNSservers: ['8.8.8.8','8.8.4.4'],
	mkBackup: true,
	DNSbackupName: 'dnsBackup'
}).then((response) => {
    if (response) console.log(`${response === true ? "DNS changing complete" : "DNS changing failed"}.`);
});

Arguments

ArgDescriptionFound inData typeDefault value
DNSserversA variable in which the DNS servers are inputtedsetDNSservers; restoreDNSserversArray of strings, or a string with a spacenull
loggingEnableLog the events as they take placesetDNSservers; restoreDNSserversbooleanfalse
mkBackupMake a backup when applicablesetDNSserversbooleantrue
rmBackupRemove a backup when applicablerestoreDNSserversbooleanfalse
macOSuseDHCPRestore DNS servers given via DHCP on macOSrestoreDNSserversbooleantrue
windowsPreferNetshUse netsh instead of powershell for functions on Windows 8 and abovesetDNSservers; restoreDNSserversbooleanfalse

How it works

Installation

PlatformDescription
Linux1. /etc/resolv.conf is backed up to /etc/resolv.conf.(backupname) 2. A new /etc/resolv.conf file is written with the given servers 3. /etc/resolv.conf is made immutible 4. DNS cache is flushed.
Windows1. DNS settings are applied to all ethernet and wireless interfaces 2. DNS cache is flushed.
macOS1. DNS settings are applied to all network interfaces 2. DNS cache is flushed.

Restoration

PlatformDescription
Linux1. /etc/resolv.conf is made mutible 2. /etc/resolv.conf/.(backupname) is restored to /etc/resolv.conf 3. DNS cache is flushed.
Windows1. All ethernet and wireless interfaces are told to fetch DNS settings from DHCP 2. DNS cache is flushed.
macOS1. DNS addresses are either retrieved from the backup made during installation or fetched from DHCP then are set on all network interfaces 2. DNS cache is flushed.

Test it in Docker

Build: docker build -t node_dns_changer .
Run: docker run --rm -it node_dns_changer
Go to folder: cd /root/node_dns_changer && node
Use:

const dns_changer = require('./index.js');

dns_changer.setDNSservers({
	DNSservers: ['8.8.8.8','8.8.4.4'],
	mkBackup: true,
	DNSbackupName: 'dnsBackup',
	loggingEnable: true
});

dns_changer.restoreDNSservers({
	DNSbackupName:'dnsBackup',
	loggingEnable: true,
	rmBackup: true
});
1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago