diff --git a/scripts/provision-host.sh b/scripts/provision-host.sh index a5db062..411b9f9 100644 --- a/scripts/provision-host.sh +++ b/scripts/provision-host.sh @@ -9,6 +9,8 @@ # 4. 禁用 cloud-init 网络管理,netplan renderer 切换为 NetworkManager # 5. rfkill 解锁无线网卡 # 6. 安装 polkit 放行规则(容器内 root 调用 NM/systemd D-Bus) +# 7. 禁止 NM 开机收编 initramfs 抢配的连接(keep-configuration=no), +# 确保开机按 autoconnect-priority 选路,静态档案不被绕过 # # 用法: sudo bash provision-host.sh # 回滚: sudo bash rollback-host.sh @@ -41,6 +43,16 @@ cat > /etc/NetworkManager/conf.d/99-mixingx.conf <<'EOF' no-auto-default=* EOF +# 禁止 NM 开机收编 initramfs 阶段(dracut 遗留 DHCP 配置)抢配的现状: +# 默认 keep-configuration 走 connection-assumed,autoconnect-priority 选路不执行, +# 静态档案开机被绕过(表现为"重启后静态 IP 变回 DHCP")。 +# 设为 no 后 NM 开机总是按最高 autoconnect-priority 激活持久档案; +# initrd 抢到的 DHCP 租约会以副地址共存(双 IP:静态主 + DHCP 副兜底)。 +cat > /etc/NetworkManager/conf.d/98-keep-configuration.conf <<'EOF' +[device] +keep-configuration=no +EOF + systemctl enable --now NetworkManager >/dev/null 2>&1 || true # ── 2. 识别主网口并读取当前参数 ─────────────────────────────────────────── diff --git a/scripts/rollback-host.sh b/scripts/rollback-host.sh index 680d639..5b8dfd8 100644 --- a/scripts/rollback-host.sh +++ b/scripts/rollback-host.sh @@ -42,6 +42,7 @@ systemctl disable --now NetworkManager >/dev/null 2>&1 || true # ── 4. 移除 polkit 规则 / NM 覆盖配置 ───────────────────────────────────── rm -f /etc/polkit-1/localauthority/50-local.d/49-mixingx-network-agent.pkla rm -f /etc/NetworkManager/conf.d/99-mixingx.conf +rm -f /etc/NetworkManager/conf.d/98-keep-configuration.conf sleep 3 ip -4 addr show | awk '/inet /{print " " $2 " @ " $NF}'