HEX
Server: nginx/1.29.3
System: Linux 11979.bigscoots-wpo.com 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64
User: nginx (1068)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,proc_open,proc_close,popen,show_source,cmd# Do not modify this line # 1684243876
Upload Files
File: //bigscoots/lxd/nm-to-networkd.sh
#!/bin/bash

INTERFACE="eth0"
CONF_PATH="/etc/systemd/network/00-$INTERFACE-static.network"

echo "--- Starting Migration to networkd (IPv4 Only / Static DNS) ---"

# 1. Safety Gate: Don't run if already migrated
if [ -f "$CONF_PATH" ]; then
    echo "SKIP: $CONF_PATH already exists. Container is likely already on networkd."
    exit 0
fi

# 2. Safety Gate: Don't run if NetworkManager is missing
if ! command -v nmcli &> /dev/null; then
    echo "SKIP: nmcli not found. NetworkManager might already be removed or disabled."
    exit 0
fi

# 3. Install systemd-networkd if missing
if ! command -v networkctl &> /dev/null; then
    echo "Installing systemd-networkd..."
    yum install -y systemd-networkd
fi

# 4. Extract IP and Gateway
IP_CIDR=$(nmcli -g IP4.ADDRESS device show "$INTERFACE")
GATEWAY=$(nmcli -g IP4.GATEWAY device show "$INTERFACE")

if [[ -z "$IP_CIDR" || -z "$GATEWAY" ]]; then
    echo "ERROR: Data extraction failed. Aborting."
    exit 1
fi

echo "Captured IP: $IP_CIDR"
echo "Captured GW: $GATEWAY"

# 5. Create the networkd config (With IPv6 Disabled)
cat <<EOF > "$CONF_PATH"
[Match]
Name=$INTERFACE

[Network]
Address=$IP_CIDR
Gateway=$GATEWAY
# Disable IPv6
LinkLocalAddressing=no
IPv6AcceptRA=no

[IPv6AcceptRA]
UseDNS=no
EOF

# 6. Create the static /etc/resolv.conf
echo "Writing static /etc/resolv.conf..."
rm -f /etc/resolv.conf
cat <<EOF > /etc/resolv.conf
search bigscoots-wpo.com
nameserver 1.1.1.1
nameserver 1.0.0.1
EOF

# 7. The Atomic Swap
echo "Swapping services..."
{
    systemctl stop NetworkManager
    systemctl disable NetworkManager
    systemctl mask NetworkManager
    
    # Clean the interface hardware state
    ip addr flush dev "$INTERFACE"
    ip link set "$INTERFACE" down
    ip link set "$INTERFACE" up
    
    systemctl unmask systemd-networkd
    systemctl enable --now systemd-networkd
    
    # Ensure route is applied
    sleep 1
    ip route add default via "$GATEWAY" dev "$INTERFACE" 2>/dev/null
}

echo "--- Migration Complete ---"
ping -c 3 google.com