network-config
v3.0.0
Published
debian ip network configuration for NodeJS
Downloads
277
Maintainers
Readme
network-config
Network configuration for NodeJS. Only used & tested on Debian
Setup
npm install network-config
Usage
List active interfaces
To check the state of dhcp you have to enable parsing the interfaces file.
var network = require('network-config');
network.interfaces(function(err, interfaces){
/* interfaces should be something like:
[{
name: 'eth0',
ip: '1.1.1.77',
netmask: '1.1.1.0',
mac: 'aa:aa:aa:aa:aa:aa',
gateway: '10.10.10.1',
},
{ ... }, { ... }]
*/
});
network.interfaces(function(err, interfaces){
/* interfaces should be something like:
[{
name: 'eth0',
ip: '1.1.1.77',
netmask: '1.1.1.0',
mac: 'aa:aa:aa:aa:aa:aa',
gateway: '10.10.10.1',
dhcp: false
},
{ ... }, { ... }]
*/
}, {interfaces: {parse: true, file: '/etc/network/interfaces'}}); //default: parse: false, file: '/etc/network/interfaces'
// ipv6 support
network.interfaces(function(err, interfaces){
/* interfaces should be something like:
[{
name: 'enxb827ebf6e3b1',
ip: '192.168.10.10',
ip6: 'fe80::2866:af76:5fd6:11e2',
ip6Gateway: 'fe80::dea6:32ff:fe63:b8f2',
ip6prefixlen: '64',
netmask: '255.255.255.0',
broadcast: '192.168.10.255',
mac: 'b8:27:eb:f6:e3:b1',
gateway: '192.168.10.1'
}, {
name: 'lo',
ip: '127.0.0.1',
ip6: '::1',
ip6Gateway: 'fe80::dea6:32ff:fe63:b8f2',
ip6prefixlen: '128',
netmask: '255.0.0.0',
broadcast: null,
mac: null,
gateway: '192.168.10.1'
}, {
name: 'rename3',
ip: null,
ip6Gateway: 'fe80::dea6:32ff:fe63:b8f2',
netmask: null,
broadcast: null,
mac: "b8:27:eb:f6:e3:b1",
gateway: '192.168.10.1'
}]
*/
}, {gateway: {resolveHostNames: false, route6: true}});
Update interface (static)
network.configure('eth0', {
ip: 'x.x.x.x',
netmask:'x.x.x.x',
broadcast: 'x.x.x.x',
gateway: 'x.x.x.x',
restart: true // (default) restart networking service right away
}, function(err){
})
Update interface (dhcp)
network.configure('eth0', {
dhcp: true,
restart: false // don't restart networking service
}, function(err){
});