Issue
I am developing an embedded system accessed through a node server running express.js. One of the functions that I'm trying to provide our users is the ability to configure the network interfaces via a web UI/REST call, without the need to drop down to a SSH session.
Here's my question: Is there a programmatic way of setting an interface as DHCP or static? Short of editing /etc/network/interfaces, I haven't been able to google or stackoverflow search a programmatic method. Can anyone recommend a direction and/or best practices for doing this?
p.s., I should mention that as part of my change, I would have the necessary configuration parameters (e.g., address, netmask, gateway) and, of course, I would preface any changes with ifconfig down.
Solution
Not really. If you want to modify network configuration, you'll need to edit the config file and invoke /etc/init.d/networking script to apply the changes.
If you want to change active network configuration, you need to exec() appropriate tools, e.g. ifconfig of dhcpcd.
Answered By - Oleksandr Kravchuk Answer Checked By - Gilberto Lyons (WPSolving Admin)