2

I'm developing a tool for managing remote devices. This tool includes 2 parts:

  • server: dashboard manager, GUI to view and manage the connected devices
  • client: worked as agencies, get tasks from server and execute them

When the admin wants to change network settings for a device, he specify that device as target of task, and new settings will become task's params. For example:

{
  target: DEVICE_ID,
  action: 'CONFIGURE_NETWORK',
  params: {
    ip_addr: '192.168.1.77',
    default_gateway: '192.168.1.1',
    primary_dns: '8.8.8.8',
    ...
  }
}

Once target device gets this task, client agency will try to apply new settings values to OS.

In the past, we only support Raspberry PI devices, so using DHCPCD resolved task as well. More advanced, it's also able to restore if network setting failed.

Now we expect to support more kinds of device, those based on Ubuntu 16.04 and newer, maybe run any desktop environment. And the problem causes. There are many ways and tools to manage network in Ubuntu family. A few distros use netplan, while other shipped with NetworkManager, and wicd, and DHCPCD5, and so on.

What is the best way to get the above task done? Which approach fit for all variants? Could you give me some advises?

4
  • 1
    DHCP or bootp. Or configure a static network config in /etc/network/interfaces if you have console access. You can't use ssh because the machine doesn't have an IP address yet (unless it has another network interface that does).
    – cas
    Aug 27, 2019 at 3:16
  • @cas thanks, the target machine is connecting to the internet as normal. I've used dhcpcd before but it's just available on few platforms. It does not present in Ubuntu 18.04 Gnome for example. Some machines even use dhcpcd5, some machines use NetworkManager, other use netplan, wicd, etc. That's problem. Aug 27, 2019 at 6:44
  • Usually DHCP is enabled by default, and if you connect it to any router it obtains an IP. So what exactly is your problem? Please refine your question and describe what you try to achieve, what you already tried, and why it didn't work for you.
    – Murphy
    Aug 27, 2019 at 15:27
  • @Murphy ok, I will describe clearer Aug 28, 2019 at 3:19

1 Answer 1

1

The most generic way I can think of is to disable/uninstall all these management tools, and perform the network configuration using the basic command line tools/OS mechanisms.

  1. ifup and ifdown if available on all your supported platforms (package ifupdown on Ubuntu), using /etc/network/interfaces.

  2. ifconfig (net-tools) and some custom script(s) to call it with the provided values should be the most basic approach (except implementing your own tool, which I don't recommend), but needs some effort to get it right for non-trivial setups.

To get the current settings, you can either parse the output of ifconfig <interface> (not recommended), or that of the ip command (from iproute2), which should be more convenient and deterministic.

7
  • I tried these commands early, and can use them at regular level. However I found that with them, I can only set the settings down, cannot get the current settings. In additional, I have to explore all other network management tools/servieces, that's another challenge. Aug 29, 2019 at 2:07
  • 1
    @DongNguyen I extended my answer.
    – Murphy
    Aug 29, 2019 at 6:44
  • 1
    thank you, my worker is python script, I can use netifaces to get the current settings as well. Now the most difficult thing is figure out a strategy to detect all current network management tools and disable them (and make sure that they will not start again after rebooting). Aug 30, 2019 at 3:09
  • 1
    As my latest research, ifconfig/ifup/ifdown.. no longer be recommended by Ubuntu since 18.04, instead I can use nmcli to control NetworkManager, or netplan at higher level. Sep 4, 2019 at 8:35
  • 1
    Thanks for sharing. It's interesting, and indeed Netplan seems to be the future replacement for ifupdown. However, with Ubuntu 18.04 that isn't gone, and still a valid alternative. Now it depends on which distributions you need to support whether you can focus on using it, or still need to support other alternatives. Can't give you much of advice here. What's interesting is that Netplan can use NM as backend.
    – Murphy
    Sep 5, 2019 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .