Science and technology

How I migrated to NetworkManager keyfiles for configuration

NetworkManager was launched in 2004 to make community configuration extra versatile and dynamic. The outdated SystemV startup shell scripts, of which the interface configuration information had been an element, had been incapable of dealing with WiFi, wired, VPNs, broadband modems, and extra—or no less than incapable of doing it shortly or effectively.

In a collection of articles, I’ve written about why I’m a fan of NetworkManager and the way I’ve used it. In part 1, I checked out what NetworkManager does and among the instruments it gives for viewing community connections and gadgets. In that article, I discussed that NetworkManager doesn’t want interface configuration information for many hosts. However, it might create its personal ini-style configuration information, and it acknowledges the older community interface configuration information. The NetworkManager configuration information are formally known as keyfiles. In part 2, I seemed on the deprecated interface configuration information and configure them, do you have to nonetheless be utilizing them.

Support for the deprecated ifcfg information is not supplied by default for brand new installations starting with Fedora 36. It will proceed to make use of them on programs which have been upgraded from earlier variations of Fedora to launch 36—no less than for some time longer. Still, it isn’t a good suggestion at this late stage to rely upon deprecated ifcfg configuration information. So for half 3 of this collection, I’ll reveal migrating present interface configuration information to the NetworkManager keyfiles utilizing the command-line instrument supplied. I may also have a look at utilizing each command-line and GUI instruments to create new keyfiles from scratch and examine them for ease of use.

The migration is significantly extra easy than it sounds. I used the nmcli connection migrate command on the 2 programs I wanted emigrate, one with a single community interface card (NIC) and one, my router/firewall, with three NICs. After some in depth testing on a VM, it additionally labored completely the primary time on each manufacturing hosts. That’s it: No different instructions, choices, or arguments required. And it’s quick, taking a lot lower than one second on each hosts.

Why ought to I migrate my information?

Most of the restrictions of the outdated shell scripts lay within the construction—or lack thereof—of the ifcfg information. NetworkManager launched the brand new community connection keyfiles to beat these points. But till Fedora 36, it nonetheless would acknowledge the outdated ifcfg configuration information. Now, NetworkManager not creates or helps ifcfg information for brand new installations.

I experimented with NetworkManager on a brand new Fedora 36 set up and couldn’t persuade it to make use of newly created ifcfg information. It continued to deal with the interfaces as dynamic host configuration protocol (DHCP) and procure its configuration values from the DHCP server. The ifcfg information are not supported on new installations as a result of the NetworkManager-initscripts-ifcfg-rh bundle is not put in. That bundle incorporates the instruments wanted to make use of the ifcfg information. Hosts upgraded from older releases of Fedora will nonetheless have the NetworkManager-initscripts-ifcfg-rh bundle put in, so it can, in the intervening time, be upgraded together with the remainder of the set up to Fedora 36. This is probably not true sooner or later.

If you’re utilizing DHCP configuration in your community hosts, you do not want emigrate any ifcfg information. In reality, you’ll be able to merely delete them, in the event that they nonetheless exist, and NetworkManager will cope with managing the community connections. Personally, I desire to maneuver deprecated information like these to an archive subdirectory in /root in order that I can discover them later, simply in case.

All hosts with static connections ought to be migrated. This often consists of servers, firewalls, and different hosts that will have to carry out their community features with out the DHCP server being energetic. I’ve two hosts like this: my foremost server and my firewall/router.

My experiments

When NetworkManager formally deprecated the interface configuration information situated in /and so on/sysconfig/network-scripts, it didn’t instantly cease utilizing them, however the replace process did drop in a readme file, /and so on/sysconfig/network-scripts/readme-ifcfg-rh.txt. This quick file states explicitly that the ifcfg-style information are deprecated. It additionally gives a easy command that performs the migration for us.

I recommend you learn that file in your host after which experiment in a non-production setting. I used a VM for my experiments and discovered loads. Before I began making modifications, I displayed the connection information proven under to get the present state of the community connection.

[root@myserver ~]# nmcli
enp0s3: related to Wired connection 1
        "Intel 82540EM"
        ethernet (e1000), 08:00:27:07:CD:FE, hw, mtu 1500
        ip4 default
        inet4 192.168.0.136/24
        route4 192.168.0.0/24 metric 100
        route4 default through 192.168.0.254 metric 100

lo: unmanaged
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

DNS configuration:
        servers: 192.168.0.52 8.8.8.8 8.8.4.4
        domains: instance.org
        interface: enp0s3

I created a easy ifcfg file that defines a static configuration on one among my VMs then examined it to confirm that this static config labored correctly. Here is the ifcfg-enp0s3 file I created for this testing:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
# HWADDR=08:00:27:07:CD:FE
IPADDR=192.168.0.95
PREFIX=24
DEFROUTE=no
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=enp0s3
ONBOOT=sure
DNS1=192.168.0.52
DNS2=8.8.8.8
AUTOCONNECT_PRIORITY=-999
DEVICE=enp0s3

I commented out the {hardware} handle within the ifcfg-enp0s3 file as a result of it doesn’t appear mandatory. I attempted it each methods, and it really works simply as effectively both manner—as soon as I lastly received it working in any respect. NetworkManager utterly ignored the contents of this file till I put in the NetworkManager-initscripts-ifcfg-rh bundle. After that, NetworkManager was in a position to set the community configuration from this ifcfg-enp0s3 file.

Then it was time to attempt the migration instrument. I ran the command proven under emigrate the ifcfg file to a keyfile.

[root@myserver system-connections]# nmcli connection migrate
Connection 'Wired connection 1' (c7b11d30-522e-306f-8622-527119911afc) efficiently migrated.
[root@myserver system-connections]#

This command took lower than a second. It creates the brand new keyfile after which deletes the ifcfg file. I recommend making a duplicate of the unique ifcfg file earlier than operating this migration instrument. It created the /and so on/NetworkManager/system-connections/enp0s3.nmconnection file for my host. Without specifying a particular interface, this command will migrate all ifcfg information situated in /and so on/sysconfig/network-scripts. If a number has a number of NICs and corresponding ifcfg information, solely a few of which you need to migrate, you’ll be able to specify an inventory of connections emigrate.

The keyfiles will be modified utilizing your favourite editor. I attempted this by altering the IPADDR entry and restarting NetworkManager simply to ensure it labored. The nmcli connection reload command didn’t work for me. Making modifications on to the keyfiles utilizing an editor shouldn’t be really helpful, however it does work. To be sincere, many skilled sysadmins (like me) actually desire modifying ASCII textual content configuration information instantly, so—really helpful or not—that’s how I do issues more often than not. I similar to to know what is definitely in these information so I can acknowledge when one thing is improper with them. It helps with fixing configuration issues.

Doing it for actual

After a day of experimenting in order that I absolutely understood how this all works and get well in case it fails, I used to be able to do it for actual. I selected my foremost server for this preliminary try as a result of it solely has a single NIC, which can make it quicker to get again on-line if there’s a downside.

First, I copied the file /and so on/sysconfig/network-scripts/ifcfg-eno1 proven in under to /root as a backup. The nmcli connection migrate command could make the conversion again from keyfile to ifcfg file. But why trouble once I can have an actual backup able to drop again in?

HWADDR=e0:d5:5e:a2:de:a4
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=sure
IPADDR=192.168.0.52
PREFIX=24
GATEWAY=192.168.0.254
DOMAIN=instance.org
IPV6INIT=no
DNS1=192.168.0.52
DNS2=8.8.8.8
DNS3=8.8.4.4
IPV4_FAILURE_FATAL=no
IPV6INIT=no
PEERROUTES=no
NAME="enp0s31f6"
ONBOOT=sure
AUTOCONNECT_PRIORITY=-999
DEVICE="enp0s31f6"

After operating the nmcli connection migrate command, I verified that it emits the standing line to point that the conversion passed off, which it did. I subsequent verified that the ifcfg file was gone and the /and so on/NetworkManager/system-connections/enp0s31f6.nmconnection keyfile was in place:

[connection]
id=enp0s31f6
uuid=abf4c85b-57cc-4484-4fa9-b4a71689c359
sort=ethernet
autoconnect-priority=-999
interface-name=enp0s31f6

[ethernet]
mac-address=E0:D5:5E:A2:DE:A4

[ipv4]
address1=192.168.0.52/24,192.168.0.254
dns=192.168.0.52;8.8.8.8;8.8.4.4;
dns-search=instance.org;
ignore-auto-routes=true
methodology=guide

[ipv6]
addr-gen-mode=stable-privacy
methodology=ignore
never-default=true

[proxy]

This file won’t be used till the NetworkManager is restarted or the host is rebooted. I first restarted NetworkManager after which checked the consequence, as proven under. The community configuration appears to be like appropriate:

[root@myserver ~]# nmcli
enp0s31f6: related to enp0s31f6
        "Intel I219-V"
        ethernet (e1000e), E0:D5:5E:A2:DE:A4, hw, mtu 1500
        ip4 default
        inet4 192.168.0.52/24
        route4 default through 192.168.0.254 metric 100
        route4 192.168.0.0/24 metric 100

lo: unmanaged
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

DNS configuration:
        servers: 192.168.0.52 8.8.8.8 8.8.4.4
        domains: instance.org
        interface: enp0s31f6

After an entire reboot, I verified the community configuration once more, and it seemed similar to the output above. With that working, I eliminated the NetworkManager-initscripts-ifcfg-rh bundle and rebooted once more, simply because it might’t damage to confirm every thing.

Once I knew that the migration instrument works on one among my manufacturing programs, and an vital one at that, I used to be prepared to do that on my firewall/router, the one with three NICs. I ran the identical nmcli connection migrate command on that host and verified the outcomes. After making certain all was working appropriately, I used DNF to take away the NetworkManager-initscripts-ifcfg-rh bundle from each manufacturing hosts. And I examined with a pair extra reboots of every host simply to make sure nothing received borked through the removing of the initscripts bundle.

What if I haven’t got ifcfg information?

New installations of Fedora do not create any sort of community interface configuration information. The default is for NetworkManager to deal with community interfaces as DHCP connections. So you needn’t do something for hosts that use DHCP to acquire their community configuration data.

However, it’s possible you’ll have to create a static configuration for some new hosts even whenever you dont have a deprecated ifcfg file emigrate.

Reverting to DHCP

Reversion to using DHCP is simple. Just take away the keyfile for the specified connection from /and so on/NetworkManager/system-connections/ and restart the NetworkManager. Remove can imply transferring the file some other place or simply deleting it.

In preparation for my subsequent collection of experiments in creating new keyfiles, I moved the enp0s31f6.nmconnection keyfile to /root and restarted NetworkManager.

Creating new keyfiles

Although the outdated ip command can nonetheless be used to switch community interface settings in a dwell setting, these modifications usually are not persistent after a reboot. Changes made utilizing NetworkManager instruments reminiscent of nmcli or nmtui, the GUI NetworkManager connection editor (nm-connection-editor), and your favourite textual content editor are persistent. The connection editor is accessible for Fedora on the system tray for every of the desktops I attempted—Xfce, Cinnamon, LXDE, KDE Plasma—and possibly the remainder of the desktops I have never but tried.

Text editor

Assuming you’re acquainted with the keyfile construction, syntax, and variables, creating or modifying keyfiles from scratch is feasible with simply an ASCII textual content editor. As a lot as I recognize and use that functionality, utilizing one of many three instruments supplied is often a lot less complicated.

Using nmtui

The nmtui instrument (NetworkManager Text User Interface) is my second alternative for a instrument on this trio. I discover the interface cumbersome, unattractive, and never intuitive. This instrument shouldn’t be put in by default, and I most likely wouldn’t have put in it if I weren’t writing this text.

However, it does work, and it created a keyfile for me that was primarily similar to the one created by the GUI Connection Manager I focus on under. The solely variations I discovered  (utilizing the diff command, in fact) had been the timestamp subject within the file and one totally different choice I deliberately made when configuring the connection. The interface does present some clues concerning the information it’s essential present to create a working keyfile.

Start this instrument by getting into the command nmtui on the command line. In normal, the arrow keys permit motion between the fields on the displayed pages, and the Enter key selects an merchandise to switch or add. The Page Up/Page Down keys scroll the web page. Select Edit a connection and press Enter to create a brand new keyfile.

(David Both, CC BY-SA 4.0)

After wending my manner by the interface, I arrived on the Edit Connection web page. It was not clear to me from this interface that the CIDR prefix ought to be appended to the IP handle, however I did that anyway, and it labored. Fill within the applicable information on this web page to configure the interface. Notice that I’ve disabled IPV6.

(David Both, CC BY-SA 4.0)

Next, scroll right down to the underside of the web page utilizing the keyboard and press OK to avoid wasting the keyfile. The keyfile is saved instantly, however NetworkManager should be restarted to activate this file, whether or not new or modified. Although this isn’t my favourite interface for creating and managing NetworkManager keyfiles, I plan to make use of it when the GUI Connection Editor is unavailable, reminiscent of when engaged on a distant host.

Using nmcli

I’ve used the nmcli instrument (Network Manager Command Line Interface) to configure an interface up to now, and this instrument additionally works very effectively. I similar to it the least as a result of it requires probably the most typing and studying of the person web page and on-line references. Executing the command instantly creates the interface configuration file within the /and so on/NetworkManager/system-connections/ listing.

The command proven under provides the wanted keyfile, similar to the opposite instruments.

[root@myserver system-connections]# nmcli connection add connection-name enp0s3-Wired ifname enp0s3 sort ethernet ipv4.addresses 192.168.0.136/24 ipv4.gateway 192.168.0.254 ipv4.dns 192.168.0.254,8.8.8.8,8.8.4.4 ipv4.dns-search instance.org ipv6.methodology disabled
Connection 'ethernet-enp0s3' (67d3a3c1-3d08-474b-ae91-a1005f323459) efficiently added.
[root@myserver system-connections]# cat enp0s3-Wired.nmconnection
[connection]
id=ethernet-enp0s3
uuid=67d3a3c1-3d08-474b-ae91-a1005f323459
sort=ethernet
interface-name=enp0s3

[ethernet]

[ipv4]
address1=192.168.0.136/32,192.168.0.254
dns=192.168.0.52;8.8.8.8;8.8.4.4;
dns-search=instance.org;
methodology=guide

[ipv6]
addr-gen-mode=stable-privacy
methodology=disabled

[proxy]
[root@myserver system-connections]#

One of the help instruments out there whereas utilizing nmcli connection add is the Bash tab-completion sequence that reveals the out there subcommands:

[root@myserver system-connections]# nmcli connection add <tab><tab>
autoconnect                        ifname                             ipv6.dhcp-send-hostname
con-name                           ipv4.addresses                     ipv6.dhcp-timeout
connection.auth-retries            ipv4.dad-timeout                   ipv6.dns
connection.autoconnect             ipv4.dhcp-client-id                ipv6.dns-options
connection.autoconnect-priority    ipv4.dhcp-fqdn                     ipv6.dns-priority
connection.autoconnect-retries     ipv4.dhcp-hostname                 ipv6.dns-search
connection.autoconnect-slaves      ipv4.dhcp-hostname-flags           ipv6.gateway
connection.dns-over-tls            ipv4.dhcp-iaid                     ipv6.ignore-auto-dns
connection.gateway-ping-timeout    ipv4.dhcp-reject-servers           ipv6.ignore-auto-routes
connection.id                      ipv4.dhcp-send-hostname            ipv6.ip6-privacy
connection.interface-name          ipv4.dhcp-timeout                  ipv6.may-fail
connection.lldp                    ipv4.dhcp-vendor-class-identifier  ipv6.methodology
connection.llmnr                   ipv4.dns                           ipv6.never-default
connection.grasp                  ipv4.dns-options                   ipv6.ra-timeout
connection.mdns                    ipv4.dns-priority                  ipv6.required-timeout
connection.metered                 ipv4.dns-search                    ipv6.route-metric
connection.mud-url                 ipv4.gateway                       ipv6.routes
connection.multi-connect           ipv4.ignore-auto-dns               ipv6.route-table
connection.permissions             ipv4.ignore-auto-routes            ipv6.routing-rules
connection.read-only               ipv4.may-fail                      ipv6.token
connection.secondaries             ipv4.methodology                        grasp
connection.slave-type              ipv4.never-default                 match.driver
connection.stable-id               ipv4.required-timeout              match.interface-name
connection.timestamp               ipv4.route-metric                  match.kernel-command-line
connection.sort                    ipv4.routes                        match.path
connection.uuid                    ipv4.route-table                   proxy.browser-only
connection.wait-device-timeout     ipv4.routing-rules                 proxy.methodology
connection.zone                    ipv6.addresses                     proxy.pac-script
assist                               ipv6.addr-gen-mode                 proxy.pac-url
hostname.from-dhcp                 ipv6.dhcp-duid                     slave-type
hostname.from-dns-lookup           ipv6.dhcp-hostname                 tc.qdiscs
hostname.only-from-default         ipv6.dhcp-hostname-flags           tc.tfilters
hostname.precedence                  ipv6.dhcp-iaid                     sort
[root@myserver system-connections]# nmcli connection add

I sometimes desire the command line for many duties. However, the complexity of getting the syntax and choices of this command appropriate implies that I need to at all times use the person web page and analysis the command earlier than I difficulty it. That takes time. And it nonetheless complained about issues I missed or received incorrect. Even when it didn’t throw an error, it created keyfiles that labored poorly, if in any respect. For instance, the connection labored once I would SSH out from the check VM, however I couldn’t SSH into the check VM. I’m nonetheless undecided what the issue was, however that keyfile had the improper CIDR prefix for the IP handle. I finally received the command appropriate by referring to the instance on the guide web page nmcli-examples(7).

When that is the one out there methodology, I can do it, however it’s my least most well-liked instrument.

Using the GUI NetworkManager connection editor

I’ve used one among my laptops for components of this part to point out each wired and wi-fi connections. Although I sometimes desire command-line instruments, I like this GUI NetworkManager connection editor instrument better of all of the three out there instrument choices. It is simple to make use of, intuitive, gives quick entry to any configuration merchandise that might ever be wanted, and is instantly out there itself within the desktop system tray of all of the desktops I’ve tried.

Just right-click on the community icon, the one that appears like a pair of computer systems, within the system tray. Then select Edit Connections.

(David Both, CC BY-SA 4.0)

This opens the connection modifying window, as pictured under. Double-click the specified connection from the connection record, often Wired Connection 1 or a WiFi SSID. The illustration under reveals each wired and wi-fi connections open for modifying on one among my laptops. I’ve by no means wanted to edit a wi-fi connection as a result of those I connect with at all times use DHCP for configuration. It is feasible to require static addressing for wi-fi connections, however I’ve by no means encountered that.

(David Both, CC BY-SA 4.0)

The Ethernet tab of the Editing Wired Connection 1 dialog window reveals the machine identify enp111s0 for this laptop computer. In most instances, nothing on this web page must be modified.

Back on my VM, I modified the Method subject from Automatic (DHCP) to Manual. I added the IP Address, the CIDR prefix, and the default route (gateway) I would like for this host. I additionally added three DNS servers and the search area. These are the minimal configuration variables wanted for a community connection. They are additionally the identical ones outlined within the interface configuration information and the earlier keyfiles. The machine identify for this NIC is enp0s3. Here is the configuration for the wired connection utilizing the GUI NetworkManager connection editor instrument.

(David Both, CC BY-SA 4.0)

Another possibility out there for the Method subject is Disabled. I set the IPV6 to Disabled since I do not use IPV6.

After setting these values, clicking the Save button creates the brand new keyfile instantly. Making modifications to present keyfiles is simply as simple. However, NetworkManager should be restarted for these configuration modifications to take impact.

In phrases of the period of time and work concerned in creating new NetworkManager keyfiles, the GUI Connection Editor is much better than the opposite choices. It gives an easy-to-use interface with sufficient details about the information required to be useful.

Conclusions

Fedora 36 modifications the equation for utilizing the old-style, deprecated interface configuration information. For new installations of Fedora 36, these information won’t work except the NetworkManager-initscripts-ifcfg-rh bundle is explicitly put in. This is a warning signal that each one assist for these deprecated ifcfg scripts will likely be utterly ignored sooner or later.

Fortunately, the migration from any present ifcfg scripts is trivially simple, and creating new ones shouldn’t be far more tough utilizing one of many three instruments out there. I desire the GUI NetworkManager connection editor instrument as a result of it’s clear and straightforward. I can use the nmtui instrument, which does the identical factor because the GUI model however has a considerably clunkier consumer interface. I attempt to not use the nmcli instrument if I will help it. It does work however is cumbersome and takes loads of studying and experimentation to get the proper command syntax and the entire proper arguments to create a totally usable keyfile.

So go forward and migrate now. I did, and it was simple.

Most Popular

To Top