Skip to content
Search AlmaLinux

    Browse this documentation

    AlmaLinux 9: pre-generate a static IP keyfile with nmcli --offline

    Executed in an almalinux:9 container (AlmaLinux 9.8, NetworkManager 1.54.3-5.el9_8): nmcli --version, nmcli general status, and nmcli --offline connection add … for a static and a DHCP profile. Log: plans/content-expansion/evidence/logs/alma-network-basics.log.

    nmcli connection up, nmcli device reapply and autoconnect after reboot were not tested here (the container has no NetworkManager daemon) and are marked E3.

    Terminal window
    nmcli --version
    nmcli general status
    nmcli tool, version 1.54.3-5.el9_8
    Error: Could not create NMClient object: Could not connect: No such file or directory.

    Regular nmcli subcommands talk to the NetworkManager daemon over D-Bus, which is unavailable in containers, rescue environments, or hosts where NM is not running yet.

    nmcli --offline needs no daemon: it builds the profile in memory and prints the keyfile, which is exactly what you want to prepare a configuration elsewhere and carry it to the target host.

    Terminal window
    nmcli --offline connection add type ethernet ifname enp1s0 con-name static-enp1s0 \
    ipv4.method manual ipv4.addresses 192.0.2.10/24 \
    ipv4.gateway 192.0.2.1 ipv4.dns 192.0.2.53
    [connection]
    id=static-enp1s0
    uuid=bd58671c-def9-4f00-b5fe-4cc6c41d09fc
    type=ethernet
    interface-name=enp1s0
    [ethernet]
    [ipv4]
    address1=192.0.2.10/24
    dns=192.0.2.53;
    gateway=192.0.2.1
    method=manual
    [ipv6]
    addr-gen-mode=default
    method=auto

    Field notes:

    FieldMeaning
    ipv4.method=manualStatic address (auto means DHCP)
    ipv4.address1Address/prefix; additional addresses become address2=…
    ipv4.gatewayDefault route
    ipv4.dnsDNS servers, semicolon separated

    Save the output directly:

    Terminal window
    nmcli --offline connection add type ethernet ifname enp1s0 con-name static-enp1s0 \
    ipv4.method manual ipv4.addresses 192.0.2.10/24 ipv4.gateway 192.0.2.1 ipv4.dns 192.0.2.53 \
    | sudo tee /etc/NetworkManager/system-connections/static-enp1s0.nmconnection
    sudo chmod 600 /etc/NetworkManager/system-connections/static-enp1s0.nmconnection

    The mode must be 600: NetworkManager ignores a keyfile with wider permissions.

    Terminal window
    sudo nmcli connection reload
    sudo nmcli connection up static-enp1s0
    nmcli -p connection show static-enp1s0

    reload makes NM re-read the directory, up actually applies the profile to the interface. Changing networking can drop your session — have console access ready.

    Terminal window
    ip -4 addr show enp1s0
    ip route show default
    cat /etc/resolv.conf
    ping -c 2 192.0.2.1

    Address present, default route pointing at the gateway, a nameserver in resolv.conf, and the gateway answering ping — all four before you call it done.

    • Keyfile not mode 600: NM silently ignores the file and it looks like “the configuration did nothing”;
    • reload without up: the profile is loaded but never applied to the device;
    • Hand-written ifcfg files: EL9 defaults to the keyfile backend, so /etc/sysconfig/network-scripts/ifcfg-* may have no effect at all.

    Practice: pre-generate a profile for another host

    Section titled “Practice: pre-generate a profile for another host”
    Terminal window
    nmcli --offline connection add type ethernet ifname enp1s0 con-name app01-static \
    ipv4.method manual ipv4.addresses 10.0.0.10/24 ipv4.gateway 10.0.0.1 ipv4.dns 10.0.0.2 \
    | sudo tee /etc/NetworkManager/system-connections/app01-static.nmconnection
    sudo chmod 600 /etc/NetworkManager/system-connections/app01-static.nmconnection
    sudo nmcli connection reload
    sudo nmcli connection up app01-static

    Checks:

    1. nmcli -f ipv4.method,ipv4.addresses connection show app01-static → manual and the target address
    2. ip -4 addr show enp1s0 → the address is active
    3. ip route show default → the gateway is correct
    4. After reboot, nmcli connection show --active → the connection is still active

    常见问题

    Can the keyfile from `nmcli --offline` be used as-is?

    Yes, it is a standard keyfile. Save it under /etc/NetworkManager/system-connections/, chmod 600, then nmcli connection reload and up. Make sure the uuid and con-name are unique on the target host.

    Why does nmcli report Could not create NMClient object?

    There is no running NetworkManager daemon (container, rescue mode, or the service is stopped). Regular subcommands need D-Bus; use nmcli --offline when you only need to generate configuration.

    Can a keyfile carry several addresses and DNS servers?

    Yes. Addresses become address1=, address2=… and DNS servers are semicolon separated (dns=1.1.1.1;8.8.8.8;). Read the result back with nmcli --offline connection show to confirm how it was parsed.