npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netplan-config

v1.0.5

Published

Network configuration using netplan

Downloads

364

Readme

netplan-config

NPM wrapper that provides Linux network configuration using netplan

This is inspired by fgribreau's network-config package. This module has the same goals, but using netplan and ip instead of the outdated ifconfig and /etc/network/interfaces.

Netplan info and examples: https://netplan.io/examples/

Installation

npm i netplan-config

Example usage

const Netplan = require('netplan-config');

// Initialize
const net = new Netplan();

/*  If /etc/netplan/config.yanml is present, you may want to load it first
 *  before making changes.
 *  If you just want to create a new config from scratch and define all
 *  the interfaces, don't bother with this.
 */
net.loadConfig()

// Configure eth0 as a DHCP WAN interface
net.configureInterface('eth0', {
  dhcp: true
});

// Configure eth0 as a static WAN interface
net.configureInterface('eth0', {
  ip: '192.168.4.8',
  defaultGateway: '192.168.4.1',
  nameservers: ['192.168.4.1'],
  domain: 'guardian-angel.local'
});

// Configure eth0 as a static LAN interface
net.configureInterface('eth0', {
  ip: '192.168.4.8'
});

/*  Configure wlan0 as a static LAN interface so that I can run hostapd
 *  on it.
 *  Use 255.255.0.0 (/16) subnet
*/
net.configureInterface('wlan0', {
  ip: '192.168.0.1',
  prefix: 16
});

// Configure wlan0 as a DHCP WAN interface
net.configureInterface('wlan0', {
  dhcp: true,
  accessPoint: {
    ssid: 'TellMyWiFiLoveHer',
    wifiPassword: 'supersecretpassword'
  }
});

// Configure wlan0 as a static IP WAN interface
net.configureInterface('wlan0', {
  dhcp: false,
  ip: '192.168.1.1',
  nameservers: ['192.168.1.1'],
  defaultGateway: '192.168.1.1',
  accessPoint: {
    ssid: 'TellMyWiFiLoveHer',
    wifiPassword: 'supersecretpassword'
  }
});

/* Now that I have made up my mind, don't forget to write back to
 * /etc/netplan/config.yaml
 */
net.writeConfig();

// I am now ready to apply.
net.apply().then(result => {
  console.log(`Successfully returned code=${result.code}`);
}).catch(err => {
  console.error('Uh oh, something went wrong.');
});

/*  The changes are now in the system!
 *  I can get all the IP information for every interface
 * by calling this:
 */
net.status().then(status => {
  console.log(status);
});

/********************************************************
OUTPUT:
{
  lo: {
    type: 'loopback',
    mac: '00:00:00:00:00:00',
    ipv4: { ip: '127.0.0.1', prefix: 8 },
    ipv6: { ip: '::1', prefix: 128 }
  },
  eno1: {
    type: 'ether',
    mac: 'aa:bb:cc:dd:ee:ff',
    ipv4: {
      ip: '192.168.4.8',
      broadcast: '192.168.4.255',
      prefix: 24,
    },
    ipv6: { ip: 'fe80::4639:c4ff:fe54:dbd3', prefix: 64 }
  },
  wlan0: {
    type: 'ether',
    mac: 'ff:ee:dd:cc:bb:aa',
    ipv4: {
      ip: '192.168.1.67',
      broadcast: '192.168.1.255',
      prefix: 24,
      gateway: '192.168.1.1'
    }
  }
}
********************************************************/

Advanced config

If you are too good and fancy to use my simple configureInterface method above, then you can provide your own custom netplan config.

For example, maybe you want to use NetworkManager instead of networkd for your renderer:

const net = new Netplan({
  network: {
    version: 2,
    renderer: 'NetworkManager'
  }
});

Also if you want to write a custom interface your own way, you can use netplan's format and create it using configureNetplanInterface:

net.configureNetplanInterface({
  name: 'eth0',
  type: 'wifi',
  definition: {
    // netplan format interface definition here
    dhcp4: true,
    'access-points': {
      'TellMyWiFiLoveHer': {
        password: 'supersecretpassword'
      }
    }
  }
});

Happy configging!