opensuse: 修复静态+动态双网卡时无法设置 onlink 路由

This commit is contained in:
bin456789 2025-01-01 17:38:29 +08:00
parent dbc38b5b26
commit ea4af1f18d
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
2 changed files with 28 additions and 18 deletions

View File

@ -88,8 +88,11 @@ EOF
sed -i '/gateway[4|6]:/d' $conf sed -i '/gateway[4|6]:/d' $conf
# 重新应用配置 # 重新应用配置
netplan apply if command -v netplan && {
systemctl restart systemd-networkd systemctl is-enabled systemd-networkd || systemctl is-enabled NetworkManager
}; then
netplan apply
fi
} }
fix_networkd_conf() { fix_networkd_conf() {
@ -145,7 +148,9 @@ GatewayOnLink=yes
# 重新应用配置 # 重新应用配置
# networkctl reload 不起作用 # networkctl reload 不起作用
systemctl restart systemd-networkd if systemctl is-enabled systemd-networkd; then
systemctl restart systemd-networkd
fi
} }
fix_wicked_conf() { fix_wicked_conf() {
@ -184,16 +189,23 @@ fix_wicked_conf() {
done done
# 重新应用配置 # 重新应用配置
systemctl restart wicked if systemctl is-enabled wicked; then
systemctl restart wicked
fi
} }
# debian 11/12: netplan + networkd/resolved # ubuntu 18.04 cloud-init 版本 23.1.2,因此不用处理
# debian 10/11 云镜像原本用 ifupdown + resolvconf脚本改成用 netplan + networkd/resolved
# debian 12 云镜像: netplan + networkd/resolved
# 23.1.1 修复 # 23.1.1 修复
fix_netplan_conf fix_netplan_conf
# arch: networkd/resolved # arch: networkd/resolved
# gentoo: networkd/resolved # gentoo: networkd/resolved
# 24.2 修复 # 24.2 修复
# 只需对云镜像处理
# 因为普通安装用的是 alpine 的 cloud-init版本够新不用处理
fix_networkd_conf fix_networkd_conf
# opensuse 15.5: ifcfg + netconfig (dns) + wicked # opensuse 15.5: ifcfg + netconfig (dns) + wicked

View File

@ -1787,13 +1787,8 @@ EOF
rm -rf net.cfg rm -rf net.cfg
apk del cloud-init apk del cloud-init
# 修复 onlink 网关 # arch gentoo 网络配置是用 alpine cloud-init 生成的
if is_staticv4 || is_staticv6; then # cloud-init 版本够新,因此无需修复 onlink 网关
fix_sh=cloud-init-fix-onlink.sh
download $confhome/$fix_sh $os_dir/$fix_sh
chroot $os_dir bash /$fix_sh
rm -f $os_dir/$fix_sh
fi
# ntp 用 systemd 自带的 # ntp 用 systemd 自带的
# TODO: vm agent + 随机数生成器 # TODO: vm agent + 随机数生成器
@ -2566,13 +2561,16 @@ modify_linux() {
# 修复 onlink 网关 # 修复 onlink 网关
add_onlink_script_if_need() { add_onlink_script_if_need() {
if is_staticv4 || is_staticv6; then for ethx in $(get_eths); do
fix_sh=cloud-init-fix-onlink.sh if is_staticv4 || is_staticv6; then
download $confhome/$fix_sh $os_dir/$fix_sh fix_sh=cloud-init-fix-onlink.sh
insert_into_file $ci_file after '^runcmd:' <<EOF download "$confhome/$fix_sh" "$os_dir/$fix_sh"
- bash /$fix_sh && rm -f /$fix_sh insert_into_file "$ci_file" after '^runcmd:' <<EOF
- bash "/$fix_sh" && rm -f "/$fix_sh"
EOF EOF
fi break
fi
done
} }
download_cloud_init_config $os_dir download_cloud_init_config $os_dir