0

Centos 7.6 fresh installation.

I need a static IP during boot for decrypting my LUKS-Container by using Clevis / TANG and following dracut.conf

kernel_cmdline="ip=10.30.0.25 netmask=255.255.255.0 gateway=10.30.0.1 nameserver=10.30.0.1"
omit_dracutmodules+="ifcfg"

With this config the Container is opened an the system is booted and the ifcfg-Files are not touched.

I configured a NetworkManager-Connection with nmtui with a different IP-Address (10.30.0.26).

When I boot the system, the NetworkManager doesn't load the configured connection, because the IP-Address is different. For this a temporary in-memory Connection with the "dracut-IP" is created.

Debug-Log-File nm

Mär 14 18:55:07 mgmt1 NetworkManager[4686]: <debug> [1552586107.8933] Connection 'enp0s25' differs from candidate 'AAAA' in ipv4.addresses

Mär 14 18:55:07 mgmt1 NetworkManager[4686]: <debug> [1552586107.8933] manager: (enp0s25): assume: generated connection 'enp0s25' (21f53190-22d9-4bc0-9526-9dc5afab2cf4)

Is it possible to "force" NetworkManager to user the provided connection I created instead of creating a temporary based on the dracut-IP?

  • More info about this seems to be recorded in Red Hat's article entitled --Network configuration ifcfg files are overwritten at boot and contain a comment "Generated by dracut initrd" -- at access.redhat.com/solutions/3017441. However, no specific resolution is provided. – John Call Sep 12 '19 at 17:13
  • It seems there is a specific solution in the link you posted (omit_dracutmodules+="ifcfg") - did not tested it. – Markus Sep 14 '19 at 18:48
1

I resolved the problem by using a separate systemd-Service which starts before the network and flushes the IP.

# /etc/systemd/system/networkflushforclevis.service
[Unit]
Description=Network Flush Service for Clevis / Dracut problem
Before=network-pre.target
Wants=network-pre.target

[Service]
ExecStart=/usr/bin/networkflush.sh

[Install]
WantedBy=default.target

/usr/bin/networkflush.sh:

#!/bin/bash
ip addr flush dev enp0s25
  • I'm facing this same issue. Do you mind sharing the unit file you created to resolve this? – John Call Sep 12 '19 at 17:06
  • Updated solution. But probably try the solution recommended by redhat - didn't have time to test it. Probably you can give a feedback here? – Markus Sep 14 '19 at 18:52
  • Thanks again for sharing your unit file. I used it as a template to create a new one that allows me to pass in the interface name to flush. The combination of Red Hat's recommendation (omit ifcfg plugin) and your systemd unit file made this work for me! – John Call Sep 16 '19 at 19:52
0

For Clevis+Tang I found it useful to:

  1. allow dracut to configure networking to unlock the root LUKS volume
  2. tell dracut to skip creating ifcfg-* files and
  3. remove the IP addresses that dracut installed, which allows NetworkManager to configure the interface(s).
[root@clevis ~]# cat /etc/dracut.conf.d/clevis-nbde.conf
# DHCP for a specific interface
kernel_cmdline="ip=eth0:dhcp"

# Static IP for a specific interface
# man dracut.cmdline
#   ip=<client-IP>:[<peer>]:<gateway-IP>:<netmask>:<client_hostname>:<interface>:{none|off|dhcp|on|any|dhcp6|auto6|ibft}[:[<dns1>][:<dns2>]]
#kernel_cmdline="ip=192.168.0.221::192.168.0.1:255.255.255.0::eth0:none:192.168.0.99"

# Don't create /etc/sysconfig/network-scripts/ifcfg-* files during boot
omit_dracutmodules+="ifcfg"
[root@clevis ~]# cat /etc/systemd/system/flush-dracut-network\@.service 
# Remove Dracut's network configuration
# https://access.redhat.com/solutions/3017441
# https://unix.stackexchange.com/questions/506331/networkmanager-doesnt-change-ip-address-when-dracut-cmdline-provided-static-ip

[Unit]
Description=Remove dracut's network configuration for %I
Before=network-pre.target
Wants=network-pre.target

[Service]
ExecStartPre=/usr/sbin/ip address show %i
ExecStart=/usr/sbin/ip -statistics address flush dev %i

[Install]
WantedBy=default.target
[root@clevis ~]# systemctl daemon-reload

[root@clevis ~]# systemctl enable flush-dracut-network@eth0
Created symlink from /etc/systemd/system/default.target.wants/flush-dracut-network@eth0.service to /usr/lib/systemd/system/flush-dracut-network@.service.
0

The following service also works:

[Unit]
Description=Remove dracut's NetworkManager connection for %I
After=NetworkManager.service
Wants=NetworkManager.service

[Service]
ExecStart=/usr/bin/bash -c "test $(nmcli c show |grep '%I'|wc -l) -gt 1 && nmcli c delete $(nmcli c show |grep '%I'|head -n 1|awk '{print $2; }')"

[Install] WantedBy=multi-user.target

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.