02. 07. 2024 Andrea Mariani Development, NetEye

Migrating from Network Script to NetworkManager Service

In the near future NetEye will likely introduce the use of NetworkManager instead of the network scripts used so far for the configuration of network connectivity. In this blog I’d like to describe some simple steps to perform a migration to NetworkManager in case it becomes necessary to go through with the transition.

Let’s look at an example with this configuration:

[root@neteye ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:5e:05:e7 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.118/24 brd 10.0.0.255 scope global dynamic enp1s0
       valid_lft 7212sec preferred_lft 7212sec
    inet6 fe80::5054:ff:fe5e:5e7/64 scope link
       valid_lft forever preferred_lft forever

[root@neteye ~]# ll /etc/sysconfig/network-scripts/
total 224
-rw-r--r--. 1 root root   273 Apr 22 10:50 ifcfg-enp1s0
-rw-r--r--. 1 root root   254 Aug 10  2022 ifcfg-lo
-rwxr-xr-x. 1 root root  2123 Aug 10  2022 ifdown
-rwxr-xr-x. 1 root root   646 Aug 10  2022 ifdown-bnep
-rwxr-xr-x. 1 root root  6419 Aug 10  2022 ifdown-eth
-rwxr-xr-x. 1 root root   769 Aug 10  2022 ifdown-ippp
-rwxr-xr-x. 1 root root  4536 Aug 10  2022 ifdown-ipv6
lrwxrwxrwx. 1 root root    11 Aug 10  2022 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x. 1 root root  2064 Aug 10  2022 ifdown-post
-rwxr-xr-x. 1 root root   870 Aug 10  2022 ifdown-routes
-rwxr-xr-x. 1 root root  1458 Aug 10  2022 ifdown-sit
-rwxr-xr-x. 1 root root  1621 Jul 26  2020 ifdown-Team
-rwxr-xr-x. 1 root root  1556 Jul 26  2020 ifdown-TeamPort
-rwxr-xr-x. 1 root root  1462 Aug 10  2022 ifdown-tunnel
-rwxr-xr-x. 1 root root  5463 Aug 10  2022 ifup
-rwxr-xr-x. 1 root root 12270 Aug 10  2022 ifup-aliases
-rwxr-xr-x. 1 root root   906 Aug 10  2022 ifup-bnep
-rwxr-xr-x. 1 root root 13776 Aug 10  2022 ifup-eth
-rwxr-xr-x. 1 root root 12068 Aug 10  2022 ifup-ippp
-rwxr-xr-x. 1 root root 11891 Aug 10  2022 ifup-ipv6
lrwxrwxrwx. 1 root root     9 Aug 10  2022 ifup-isdn -> ifup-ippp
-rwxr-xr-x. 1 root root   643 Aug 10  2022 ifup-plip
-rwxr-xr-x. 1 root root  1057 Aug 10  2022 ifup-plusb
-rwxr-xr-x. 1 root root  5000 Aug 10  2022 ifup-post
-rwxr-xr-x. 1 root root  2427 Aug 10  2022 ifup-routes
-rwxr-xr-x. 1 root root  3303 Aug 10  2022 ifup-sit
-rwxr-xr-x. 1 root root  1755 Jul 26  2020 ifup-Team
-rwxr-xr-x. 1 root root  1876 Jul 26  2020 ifup-TeamPort
-rwxr-xr-x. 1 root root  2879 Aug 10  2022 ifup-tunnel
-rwxr-xr-x. 1 root root  1836 Aug 10  2022 ifup-wireless
-rwxr-xr-x. 1 root root  5421 Aug 10  2022 init.ipv6-global
-rw-r--r--. 1 root root 20431 Aug 10  2022 network-functions
-rw-r--r--. 1 root root 31037 Aug 10  2022 network-functions-ipv6

[root@neteye ~]# ll /etc/NetworkManager/system-connections/
total 0

[root@neteye ~]# nmcli
Error: NetworkManager is not running.

The first step is to back up the current configurations:

[root@neteye ~]# mkdir /root/BCK_Network_Scripts
[root@neteye ~]# cp -p /etc/sysconfig/network-scripts/ifcfg-* /root/BCK_Network_Scripts/

The second step is to verify and start the NetworkManager service, and then enable it in automatic startup:

[root@neteye ~]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:NetworkManager(8)

[root@neteye ~]# systemctl start NetworkManager

[root@neteye ~]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2024-07-01 17:54:24 CEST; 4s ago
     Docs: man:NetworkManager(8)
 Main PID: 7350 (NetworkManager)
    Tasks: 4 (limit: 100513)
   Memory: 6.9M
   CGroup: /system.slice/NetworkManager.service
           └─7350 /usr/sbin/NetworkManager --no-daemon

Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1225] dhcp4 (enp1s0): state changed no lease
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1245] dhcp4 (enp1s0): state changed new lease, address=10.0.0.118
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1246] policy: set 'enp1s0' (enp1s0) as default for IPv4 routing and DNS
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1327] device (enp1s0): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'assume')
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1339] device (enp1s0): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'assume')
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1341] device (enp1s0): state change: secondaries -> activated (reason 'none', sys-iface-state: 'assume')
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1344] manager: NetworkManager state is now CONNECTED_SITE
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1347] device (enp1s0): Activation: successful, device activated.
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1352] manager: NetworkManager state is now CONNECTED_GLOBAL
Jul 01 17:54:25 neteye NetworkManager[7350]: <info>  [1719849265.1355] manager: startup complete

[root@neteye ~]# systemctl enable NetworkManager
Created symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service → /usr/lib/systemd/system/NetworkManager.service.
Created symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service → /usr/lib/systemd/system/NetworkManager-dispatcher.service.
Created symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service → /usr/lib/systemd/system/NetworkManager-wait-online.service.

The third step consists of the actual migration from Network Scripts to NetworkManager:

[root@neteye ~]# nmcli connection migrate
Connection 'enp1s0' (d7c704c5-8f15-408e-b221-b33048c00e06) successfully migrated.

We then verify that everything went correctly:

[root@neteye ~]# ll /etc/NetworkManager/system-connections/
total 4
-rw-------. 1 root root 182 Jul  1 17:54 enp1s0.nmconnection

[root@neteye ~]# ll /etc/sysconfig/network-scripts/
total 220
-rw-r--r--. 1 root root   254 Aug 10  2022 ifcfg-lo
-rwxr-xr-x. 1 root root  2123 Aug 10  2022 ifdown
-rwxr-xr-x. 1 root root   646 Aug 10  2022 ifdown-bnep
-rwxr-xr-x. 1 root root  6419 Aug 10  2022 ifdown-eth
-rwxr-xr-x. 1 root root   769 Aug 10  2022 ifdown-ippp
-rwxr-xr-x. 1 root root  4536 Aug 10  2022 ifdown-ipv6
lrwxrwxrwx. 1 root root    11 Aug 10  2022 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x. 1 root root  2064 Aug 10  2022 ifdown-post
-rwxr-xr-x. 1 root root   870 Aug 10  2022 ifdown-routes
-rwxr-xr-x. 1 root root  1458 Aug 10  2022 ifdown-sit
-rwxr-xr-x. 1 root root  1621 Jul 26  2020 ifdown-Team
-rwxr-xr-x. 1 root root  1556 Jul 26  2020 ifdown-TeamPort
-rwxr-xr-x. 1 root root  1462 Aug 10  2022 ifdown-tunnel
-rwxr-xr-x. 1 root root  5463 Aug 10  2022 ifup
-rwxr-xr-x. 1 root root 12270 Aug 10  2022 ifup-aliases
-rwxr-xr-x. 1 root root   906 Aug 10  2022 ifup-bnep
-rwxr-xr-x. 1 root root 13776 Aug 10  2022 ifup-eth
-rwxr-xr-x. 1 root root 12068 Aug 10  2022 ifup-ippp
-rwxr-xr-x. 1 root root 11891 Aug 10  2022 ifup-ipv6
lrwxrwxrwx. 1 root root     9 Aug 10  2022 ifup-isdn -> ifup-ippp
-rwxr-xr-x. 1 root root   643 Aug 10  2022 ifup-plip
-rwxr-xr-x. 1 root root  1057 Aug 10  2022 ifup-plusb
-rwxr-xr-x. 1 root root  5000 Aug 10  2022 ifup-post
-rwxr-xr-x. 1 root root  2427 Aug 10  2022 ifup-routes
-rwxr-xr-x. 1 root root  3303 Aug 10  2022 ifup-sit
-rwxr-xr-x. 1 root root  1755 Jul 26  2020 ifup-Team
-rwxr-xr-x. 1 root root  1876 Jul 26  2020 ifup-TeamPort
-rwxr-xr-x. 1 root root  2879 Aug 10  2022 ifup-tunnel
-rwxr-xr-x. 1 root root  1836 Aug 10  2022 ifup-wireless
-rwxr-xr-x. 1 root root  5421 Aug 10  2022 init.ipv6-global
-rw-r--r--. 1 root root 20431 Aug 10  2022 network-functions
-rw-r--r--. 1 root root 31037 Aug 10  2022 network-functions-ipv6

Now we finish by restarting the NetworkManager service, then disabling and finally turning off the old network.service:

[root@neteye ~]# systemctl restart NetworkManager

[root@neteye ~]# systemctl disable network.service
network.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install disable network

[root@neteye ~]# systemctl stop network.service

[root@neteye ~]# nmcli
enp1s0: connected to enp1s0
        "Red Hat Virtio"
        ethernet (virtio_net), 52:54:00:5E:05:E7, hw, mtu 1500
        ip4 default
        inet4 10.0.0.118/24
        route4 default via 10.0.0.1 metric 0
        route4 default via 10.0.0.1 metric 100
        route4 10.0.0.0/24 metric 0
        route4 10.0.0.0/24 metric 100
        route4 169.254.0.0/16 metric 1002
        inet6 fe80::5054:ff:fe5e:5e7/64
        route6 fe80::/64 metric 256
        route6 fe80::/64 metric 1024

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

DNS configuration:
        servers: 10.0.0.10 10.0.0.1
        interface: enp1s0

Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.

Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.

With these simple steps, you can perform a migration without necessarily rebooting the server after the changes are made (although a reboot is always recommended).

These Solutions are Engineered by Humans

Did you find this article interesting? Does it match your skill set? Programming is at the heart of how we develop customized solutions. In fact, we’re currently hiring for roles just like this and others here at Würth Phoenix.

Andrea Mariani

Andrea Mariani

Author

Andrea Mariani

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive