{"id":124367,"date":"2022-04-29T08:22:00","date_gmt":"2022-04-29T08:22:00","guid":{"rendered":"https:\/\/fedoramagazine.org\/?p=36375"},"modified":"2022-04-29T08:22:00","modified_gmt":"2022-04-29T08:22:00","slug":"from-ifcfg-to-keyfiles-modernizing-networkmanager-configuration-in-fedora-linux-36","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/04\/29\/from-ifcfg-to-keyfiles-modernizing-networkmanager-configuration-in-fedora-linux-36\/","title":{"rendered":"From ifcfg to keyfiles: modernizing NetworkManager configuration in Fedora Linux 36"},"content":{"rendered":"<p>One of the changes in Fedora Linux 36 is that new installations will <a href=\"https:\/\/fedoraproject.org\/wiki\/Releases\/36\/ChangeSet#No_ifcfg_by_default\" target=\"_blank\" rel=\"noreferrer noopener\">no longer support the ifcfg files to configure networking<\/a>. What are those and what replaces them?<\/p>\n<p> <span id=\"more-36375\"><\/span> <\/p>\n<h2>A bit of history<\/h2>\n<p>In the good old days, connecting a Linux box to a network was easy. For each of the interface cards connected to a network, the system administrator would drop a configuration file into the <em>\/etc<\/em> directory. That configuration file would describe the addressing configuration for a particular network. On Fedora Linux, the configuration file would actually be a shell script snippet like this:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>cat \/etc\/sysconfig\/network-scripts\/ifcfg-eth0<\/strong>\nTYPE=Ethernet\nDEVICE=eth0\nBOOTPROTO=dhcp<\/pre>\n<p>A shell script executed on startup would read the file and apply the configuration. Simple.<\/p>\n<p>Towards the end of 2004, however, a change was in the air. Quite literally &#8212; the Wi-Fi has become ubiquitous. The portable computers of the day could rapidly connect to new networks and the USB bus allowed even the wired network adapters to come and go while the system was up and running. The network configuration became more dynamic than ever before, rendering the existing network configuration tooling impractical. To the rescue came <a href=\"https:\/\/networkmanager.dev\/\" target=\"_blank\" rel=\"noreferrer noopener\">NetworkManager<\/a>. On a Fedora Linux system, NetworkManager uses configuration like this:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>cat \/etc\/sysconfig\/network-scripts\/ifcfg-eth0<\/strong>\nTYPE=Ethernet\nDEVICE=eth0\nBOOTPROTO=dhcp<\/pre>\n<p>Looks familiar? It should. From the beginning, NetworkManager was intended to work with the existing configuration formats. In fact, it ended up with plugins which would seamlessly convert between NetworkManager&#8217;s internal configuration model and the distribution&#8217;s native format. On Fedora, it would be the aforementioned <em>ifcfg<\/em> files.<\/p>\n<p>Let&#8217;s take a closer look at them.<\/p>\n<h2>Ifcfg files<\/h2>\n<p>The legacy network service, now part of the <em>network-scripts<\/em> package, originally defined the <em>ifcfg<\/em> file format. Along with the package comes a file called <a href=\"https:\/\/github.com\/fedora-sysv\/initscripts\/blob\/master\/doc\/sysconfig.txt#L416\" target=\"_blank\" rel=\"noreferrer noopener\">sysconfig.txt<\/a> that, quite helpfully, documents the format.<\/p>\n<p>As NetworkManager gained traction it often found itself in need of expressing a configuration that was not supported by the old fashioned network service. Given the nature of configuring things with shell scripts, adding new settings is no big deal. The unknown ones are generally just silently ignored. The NetworkManager&#8217;s idea of what ifcfg files should look like is described in the <a href=\"https:\/\/networkmanager.dev\/docs\/api\/latest\/nm-settings-ifcfg-rh.html\" target=\"_blank\" rel=\"noreferrer noopener\">nm-settings-ifcfg-rh(5)<\/a> manual.<\/p>\n<p>In general, NetworkManager tries hard to write <em>ifcfg<\/em> files that work well with the legacy network service. Nevertheless, sometimes it is just not possible. These days, the number of network connection types that NetworkManager supports vastly outnumber what the legacy network service can configure. . A new format is now used to express what the legacy format can not. This includes VPN connections, broadband modems and more.<\/p>\n<h2>Keyfiles<\/h2>\n<p>The new format closely resembled the NetworkManager&#8217;s native configuration model:<\/p>\n<div class=\"wp-container-626c7bc4121c1 wp-block-group\">\n<div class=\"wp-block-group__inner-container\">\n<pre class=\"wp-block-preformatted\">$ <strong>cat \/etc\/NetworkManager\/system-connections\/VPN.ovpn<\/strong>\n[connection]\nid=My VPN\nuuid=c85a7cdb-973b-491f-998d-b09a590af10e\ntype=vpn [vpn]\nca=\/etc\/pki\/tls\/certs\/vpn-ca.pem\nconnection-type=password\nremote=vpn.example.com\nusername=lkundrak\nservice-type=org.freedesktop.NetworkManager.openvpn [ipv6]\nmethod=auto\nnever-default=true<\/pre>\n<\/div>\n<\/div>\n<p>The actual format should be instantly familiar to everyone familiar with Linux systems. It&#8217;s the &#8220;ini file&#8221; or &#8220;keyfile&#8221; &#8212; a bunch of plain text key-value pairs, much like the ifcfg files use, grouped into sections. The <a href=\"https:\/\/networkmanager.dev\/docs\/api\/latest\/nm-settings-ifcfg-keyfile.html\" target=\"_blank\" rel=\"noreferrer noopener\">nm-settings-ifcfg-keyfile(5)<\/a> manual documents the format thoroughly.<\/p>\n<p>The main advantage of using this format is that it closely resembles NetworkManager&#8217;s idea of how to express network configuration, used both internally and on the D-Bus API. It&#8217;s easier to extend without taking into consideration the quirks of the mechanism that was designed in without the benefit of foresight back when the world was young. This means less code, less surprises and less bugs.<\/p>\n<p>In fact there&#8217;s nothing the <em>keyfile<\/em> format can&#8217;t express that <em>ifcfg<\/em> files can. It can express the simple wired connections just as well as the VPNs or modems.<\/p>\n<h2>Migrating to keyfiles<\/h2>\n<p>The legacy network service served us well for many years, but its days are now long over. Fedora Linux dropped it many releases ago and without it there is seemingly little reason to use the ifcfg files. That is, for new configurations. While Fedora Linux still supports the <em>ifcfg<\/em> files, it has defaulted to writing <em>keyfiles<\/em> for quite some time.<\/p>\n<p>Starting with Fedora Linux 36, the ifcfg support will no longer be present in new installations. If you&#8217;re still using <em>ifcfg<\/em> files, do not worry &#8212; the existing systems will keep it on upgrades. Nevertheless, you can still decide to uninstall it and carry your configuration over to <em>keyfiles<\/em>. Keep on reading to learn how.<\/p>\n<p>If you&#8217;re like me, you installed your system years ago and you have a mixture of <em>keyfiles<\/em> and <em>ifcfg<\/em> files. Here&#8217;s how can you check:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>nmcli -f TYPE,FILENAME,NAME conn<\/strong>\nTYPE FILENAME NAME\nethernet \/etc\/sysconfig\/network-scripts\/ifcfg-eth0 eth0\nwifi \/etc\/sysconfig\/network-scripts\/ifcfg-Guest Guest\nwifi \/etc\/NetworkManager\/system-connections\/Base48 Base48\nvpn \/etc\/NetworkManager\/system-connections\/VPN.ovpn My VPN<\/pre>\n<p>This example shows a VPN connection that must have always used a keyfile and a Wi-Fi connection presumably created after Fedora Linux switched to writing <em>keyfiles<\/em> by default. There&#8217;s also an Ethernet connection and Wi-Fi one from back in the day that use the <em>ifcfg<\/em> plugin. Let&#8217;s see how we can convert those to keyfiles.<\/p>\n<p>The NetworkManager&#8217;s command line utility, <a href=\"https:\/\/networkmanager.dev\/docs\/api\/latest\/nmcli.html\" target=\"_blank\" rel=\"noreferrer noopener\">nmcli(1)<\/a>, acquired a new <em>connection migrate<\/em> command, that can change the configuration backend used by a connection profile.<\/p>\n<p>It&#8217;s a good idea to make a backup of <em>\/etc\/sysconfig\/network-scripts\/ifcfg-*<\/em> files, in case anything goes wrong. Once you have the backup you can try migrating a single connection to a different configuration backend (<em>keyfile<\/em> by default):<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>nmcli connection migrate eth0<\/strong>\nConnection 'eth0' (336aba93-1cd7-4cf4-8e90-e2009db3d4d0) successfully migrated.<\/pre>\n<p>Did it work?<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>nmcli -f TYPE,FILENAME,NAME conn<\/strong>\nTYPE FILENAME NAME\nethernet \/etc\/NetworkManager\/system-connections\/eth0.nmc eth0\nwifi \/etc\/sysconfig\/network-scripts\/ifcfg-Guest Guest\nwifi \/etc\/NetworkManager\/system-connections\/Base48 Base48\nvpn \/etc\/NetworkManager\/system-connections\/VPN.ovpn My VPN<\/pre>\n<p>Cool. Can I migrate it back, for no good reason?<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>nmcli conn migrate --plugin ifcfg-rh eth0<\/strong>\nConnection 'eth0' (336aba93-1cd7-4cf4-8e90-e2009db3d4d0) successfully migrated.<\/pre>\n<p>Excellent. Without specifying more options, the &#8220;connection migrate&#8221; command ensures all connections use the keyfile backend:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>nmcli conn migrate<\/strong>\nConnection '336aba93-1cd7-4cf4-8e90-e2009db3d4d0' (eth0) successfully migrated.\nConnection '3802a9bc-6ca5-4a17-9d0b-346f7212f2d3' (Red Hat Guest) successfully migrated.\nConnection 'a082d5a0-5e29-4c67-8b6b-09af1b8d55a0' (Base48) successfully migrated.\nConnection 'c85a7cdb-973b-491f-998d-b09a590af10e' (Oh My VPN) successfully migrated.<\/pre>\n<p>And that&#8217;s all. Now that your system has no <em>ifcfg<\/em> files, the configuration backend that supports them is of no use and you can remove it:<\/p>\n<pre class=\"wp-block-preformatted\"># <strong>dnf remove NetworkManager-initscripts-ifcfg-rh<\/strong>\n\u2026<\/pre>\n<p>Your system now works the same as it did before, but you can rejoice, for it is now modern.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the changes in Fedora Linux 36 is that new installations will no longer support the ifcfg files to configure networking. What are those and what replaces them? A bit of history In the good old days, connecting a Linux box to a network was easy. For each of the interface cards connected to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[45,61,46,47],"class_list":["post-124367","post","type-post","status-publish","format-standard","hentry","category-fedora-os","tag-fedora","tag-fedora-project-community","tag-magazine","tag-news"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/124367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=124367"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/124367\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=124367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=124367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=124367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}