How exactly are NetworkManager, networkd, netplan, ifupdown2, and iproute2 interacting?

32,034

Solution 1

systemd-networkd when its enabled honors configurations in /etc/systemd/network

Whereas NetworkManager will follow some automatic rules like it will try to connect to a wired connection if it finds one.

Both are enabled and disabled as systemd services and systemd using udev creates the device files for the network adapters. Generally you probably shouldn't have both enabled at the same time but if you do you'd need to be careful that their configurations don't conflict.

netplan before either network manager starts creates configurations for either based on its own configuration. In this way netplan is really a configuration abstraction and wheather it uses systemd-networkd or NetworkManager is part of the configuration.

iproute2 is a package of tools for configuring network interfaces at the command line. It includes link configuration similar to network managers and the old ifconfig. While net-tools, ipupdown and ifupdown2 use network configurations in /etc/network/interfaces to configure and deconfigure interfaces.

ifupdown or its other versions can be used to manage networks but its not automatic but a systemd service can be used to start it at boot.

ifupdown2 uses dependency graphs similar to what systemd does but with network interfaces. Further it acts as an abstraction to other tools like iproute2

Solution 2

I won't try to answer your entire question,
but I've found a few things that helped me understand how these systems fit together.
Hope this helps someone as this was very confusing to me


1 - The old network interfaces configuration file, and it's ifup & ifdown commands:

The /etc/network/interfaces network configuration file seems to be fairly old, but is still used by ifup, ifdown and ifquery.

These seem to be the old way to bring network 'interfaces' (MAC based links) and 'connections' (IP based connections) up and down.

man 8 ifup says:

DESCRIPTION
The ifup and ifdown commands may be used to configure (or, respectively, deconfigure) network interfaces based on interface definitions in the file /etc/network/interfaces.

The important implication is this:

if an interface isn't defined in /etc/network/interfaces, then ifup/ifdown won't manage that interface.


2 - What about the old ifconfig command?

The legacy networking package named net-tools on Debian, includes the depreciated: arp, ifconfig, ipmaddr, iptunnel, iwconfig, nameif, netstat, route, and vconfig commands.

Now you want to be using the package named iproute2 instead which includes the newer ip, iw, ss, and ifrename commands.


3 - If the ip command can bring an interface up or down, why not use it rather than ifup and ifdown?

What ifup/down does, (via the ifupdown package or presumable also the Python rewrite in ifupdown2), that ip does not do, is to run legacy scripts before and after network changes. But note what man ifup says:

NOTES

The program does not configure network interfaces directly; it runs low level utilities such as ip to do its dirty work.

SEE ALSO
interfaces(5), ip(8), ifconfig(8).

So it appears that ifup/ifdown has been upgraded from using the depreciated ifconfig back-end, to now using the ip back-end, provided by the newer iproute2 package.


4 - What about NetworkManager? (2004)

From man 5 NetworkManager,

[IFUPDOWN]

This section contains ifupdown-specific options and thus only has effect when using the ifupdown plugin.

managed

If set to true, then interfaces listed in /etc/network/interfaces are managed by NetworkManager. If set to false, then any interface listed in /etc/network/interfaces will be ignored by NetworkManager. Remember that NetworkManager controls the default route, so because the interface is ignored, NetworkManager may assign the default route to some other interface.

So its unclear if NetworkManager can also run ifup/ifdown scripts, but what is clear, is that NetworkManager can stay clear of legacy interfaces (again "MAC based hardware links") that ifup/ifdown are still using. In other words, either ifup is using a hardware link, or NetworkManager, or possibly something else, but not both ifup and NetworkManager at the same time.


5 - systemd-networkd (2010)

This is newer than NetworkManager, and used for wired servers and when a GUI environment is not available.

But it appears that for wireless connections, NetworkManager is the way to go as it is more difficult to manually configure systemd-networkd.

In man 8 systemd-networkd it says,

systemd-networkd will manage network addresses and routes for any link for which it finds a .network file with an appropriate [Match] section, see systemd.network(5) (real network devices). For those links, it will flush existing network addresses and routes when bringing up the device. Any links not matched by one of the .network files will be ignored. It is also possible to explicitly tell systemd-networkd to ignore a link by using Unmanaged=yes option, see systemd.network(5).

Hope I've got this all right, but if not please let me know. Thanks.

Share:
32,034

Related videos on Youtube

Oleg
Author by

Oleg

Updated on September 18, 2022

Comments

  • Oleg
    Oleg almost 2 years

    I am learning about Linux networking on my Kubuntu 18.04 workstation, and I see there that both NetworkManager and networkd-dispatcher are running:

    oleg@eclectic:~$ sudo ps -ef | grep -i net
    root        56     2  0 Oct11 ?        00:00:00 [netns]
    root      1097     1  0 Oct11 ?        00:00:02 /usr/sbin/NetworkManager --no-daemon
    root      1098     1  0 Oct11 ?        00:00:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
    root      1250     1  0 Oct11 ?        00:00:02 /usr/sbin/inetd
    root      1593  1097  0 Oct11 ?        00:00:00 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper...
    

    NetworkManager seems to be configured to handle "everything" by netplan:

    oleg@eclectic:~$ cat /etc/netplan/01-network-manager-all.yaml 
    # Let NetworkManager manage all devices on this system
    network:
      version: 2
      renderer: NetworkManager
    

    I believe that netplan would hand everything off to networkd if NetworkManager was not installed.

    There are also a bunch of files in /etc/network/, and I am not sure what is handling those. A lot of packages seem to use this directory:

    oleg@eclectic:~$ dpkg -S /etc/network
    avahi-daemon, ifupdown2, wpasupplicant, openvpn, postfix, netbase, avahi-autoipd, wireless-tools, clamav-freshclam: /etc/network
    

    My initial thoughts after some Googling are that NetworkManager and networkd are both running, but netplan generates configuration such that only one is actually doing something. But I do not know how I would verify this, figure out the chain of operations, or configure it to suit my nefarious plans for dummy0.

    Question: How exactly are NetworkManager, networkd, and netplan working together? In other words, as the computer boots up, which processes hand what of to what other processes? How do tools from packages like net-tools, ifupdown2, and iproute2 and directories like /etc/network/ fit into all this? And finally, how can I figure this out myself and learn the details using the command line?

    Update: I am not looking for a high-level overview. Rather, I want to know how these components are interacting, conflicting, or avoiding conflict on the kernel level or similar.

  • Oleg
    Oleg over 5 years
    Thank you for the compare/ contrast, but I was looking for more about how these components interact with each other, on a much deeper level. For example, what exactly happens in the kernel when both systemd and NetworkManager try to control the same interface at the same time? What do the iproute2/ ifupdown tools do in the kernel that conflicts (or avoids conflict) with networkd/ NetworkManager? What commands can I use to see which tools did what to which interfaces (on the udev/ kernel level)?
  • Craig  Hicks
    Craig Hicks about 5 years
    Best explanation I've seen so far as there is general confusion with many explanations claiming that netplan is either NetworkManager or systemd-networkd, but not both. Some links would have been helpful. E.g. manpages.ubuntu.com/manpages/cosmic/man5/netplan.5.html
  • Stephen Boston
    Stephen Boston over 4 years
    After reading this I expect to find configuration files in /etc/systemd/network but in my Ubuntu 19.10 with systemd-networkd enabled and running, that directory is empty. However I find files in /lib/systemd/network. Is this a new config? Rogue ubuntu? An error?
  • 4xy
    4xy almost 4 years
    Looks like nobody knows what happens under the hood. I've been looking for explanation on the web for couple of days with no success.