设置网络
系统安装完成后,请使用 ip a查看网络状态。平台安装时校验网卡名称以eth开头,请按照修改网络配置的步骤修改网口。Ip a 的使用方法如下。
#ip a ---查看网络配置 ![]() ----需要修改网络配置 |
说明:
多网口情况下,需要将所有的 enp修改为 eth,如 enp0s1 改为 eth0,enp0s2 改为 eth1,配置网口时所有网口均需配置 ip 地址(需包含 eth0 网口并启用)。否则可能会引起业务程序无法启动.
1.上传文件
本手册的上传文件与安装软件操作均借助于 FTP 工具,通过 FTP 工具与服务器成功建立连接后实现,上传修改网卡脚本文件
修改网卡脚本:rename_if_permanently
2.修改网卡名称
在平台后台执行: chmod +x rename_if_permanently ----加执行权限 ./rename_if_permanently ----执行脚本修改配置 reboot ---重启平台 ip a ---平台重启后连接ssh,查看网卡名称是否修改成功 到此已完成!!! |
脚本文件
#!/bin/bash
#!/bin/bash
if [ -z "$include_global_common_variables__" ]; then
include_global_common_variables__=1;
#!/bin/bash
if [ -z "$include_system_utils_sh__" ]; then
include_system_utils_sh__=1;
readonly SYSTEM_ID_CENTOS="centos";
readonly SYSTEM_ID_OPENEULER="openeuler";
readonly SYSTEM_ID_KYLIN="kylin";
readonly SYSTEM_ID_UOS="uos";
function get_operation_system_id()
{
grep -P "^ID=" /etc/os-release |awk -F= '{print $2}'|grep -oP "[\w\s]+";
}
function is_openeuler_os()
{
[ "$(get_operation_system_id)" == "${SYSTEM_ID_OPENEULER}" ];
}
function is_virtual_machine_env()
{
[ $(systemd-detect-virt) == "none" ];
}
readonly BOOT_MODE_LEGACY=1;
readonly BOOT_MODE_UEFI=2;
function get_bios_boot_mode_from_mount_status()
{
local boot_mode=0;
if mount |grep -q " on /boot/efi type vfat"; then
boot_mode=$BOOT_MODE_UEFI;
else
boot_mode=$BOOT_MODE_LEGACY;
fi;
echo $boot_mode;
}
function is_bios_boot_mode_uefi()
{
#1st way
#local result=`get_bios_boot_mode_from_mount_status`;
#[[ $result -eq $BOOT_MODE_UEFI ]];
#2nd way
[ -d /sys/firmware/efi ]
}
function is_bios_boot_mode_legacy()
{
#1st way
#local result=`get_bios_boot_mode_from_mount_status`;
#[[ $result -eq $BOOT_MODE_LEGACY ]];
#2nd way
! is_bios_boot_mode_uefi;
}
fi;#$include_system_utils_sh__
grub_dir=/etc/default
#grub_dir=/etc/sysconfig
#this path validated on virtualbox
#dst_grub_cfg_dir=/boot/grub2
#this path validated on realmachine
dst_grub_cfg_dir=/boot/efi/EFI/openEuler
echo "dst_grub_cfg_dir: $dst_grub_cfg_dir"
if is_bios_boot_mode_uefi ; then
echo "bios boot mode uefi detected"
dst_grub_cfg_dir=`find / -type f -name grub.cfg|grep /boot/efi/EFI |xargs -i{} dirname {}`
#/boot/efi/EFI/openEuler
else
echo "bios boot mode legacy detected"
dst_grub_cfg_dir=`find / -type f -name grub.cfg|grep /boot/grub2 |xargs -i{} dirname {}`
#/boot/grub2
fi;
# if [ "$BIOS_BOOT_MODE" == "legacy" ]; then
# dst_grub_cfg_dir=/boot/grub2
# elif [ "$BIOS_BOOT_MODE" == "uefi" ]; then
# dst_grub_cfg_dir=/boot/efi/EFI/openEuler
# fi
echo "grub_dir: $grub_dir"
fi;
#include_global_common_variables__
#!/bin/bash
if [ -z $include_net_utils_sh__ ]; then
function get_ifnames()
{
ip addr|grep " mtu "|awk '{print $2}'|grep -oP "\w+";
}
fi; #include_net_utils_sh__
if [ -z "$include_rename_if_permanent_sh__" ]; then
include_rename_if_permanent_sh__=1;
has_eth0=`get_ifnames | grep eth0`
#has_eth0=`ifconfig | awk '$1~/:/{print $1}'|grep -oP "\w+"|grep eth0`;
#the minimalized os installation does not contains "net-tools/ifconfig"
if [ ! -z "$has_eth0" ]; then
echo "already has eth0"
exit;
fi;
#grub_dir=/etc/default
#grub_dir=/etc/sysconfig
if [ -z "$grub_dir" ]; then
echo "grub_dir not defined"
exit 1;
fi;
grub_file=${grub_dir}/grub
old_GRUB_CMDLINE_LINUX=`cat $grub_file| awk -F\" '/GRUB_CMDLINE_LINUX/{print $2}'`
echo "old GRUB_CMDLINE_LINUX=${old_GRUB_CMDLINE_LINUX}"
has_iframe=`echo $old_GRUB_CMDLINE_LINUX|grep net.ifnames`
biosdevname=`echo $old_GRUB_CMDLINE_LINUX|grep biosdevname`
new_GRUB_CMDLINE_LINUX=$old_GRUB_CMDLINE_LINUX
require_update_grub=0;
if [ -z "$has_iframe" ]; then
new_GRUB_CMDLINE_LINUX="${new_GRUB_CMDLINE_LINUX} net.ifnames=0"
require_update_grub=1;
fi;
if [ -z "$biosdevname" ]; then
new_GRUB_CMDLINE_LINUX="${new_GRUB_CMDLINE_LINUX} biosdevname=0"
require_update_grub=1;
fi;
if [[ $require_update_grub -eq 1 ]]; then
echo "new_GRUB_CMDLINE_LINUX: $new_GRUB_CMDLINE_LINUX"
replace_line="GRUB_CMDLINE_LINUX=\"$new_GRUB_CMDLINE_LINUX\"";
echo "replace_line: $replace_line"
pushd $grub_dir
if [ ! -f grub.bk ]; then
cp -v grub grub.bk
fi;
popd
sed -i -r "s#^\s*GRUB_CMDLINE_LINUX\s*=.+#$replace_line#" $grub_file
echo "grub updated"
fi;
pushd /etc/sysconfig/network-scripts/
mkdir if_backup
#if_list=`ifconfig|grep -oP "^\w+"|grep -vP "^lo$"`;
if_list=`get_ifnames | grep -vwP "^lo$"`;
if_idx=0;
for if_interface in $if_list
do
old_if_file="ifcfg-${if_interface}";
new_if_name="eth${if_idx}";
new_if_file="ifcfg-${new_if_name}"
if [ ! -f if_backup/$old_if_file ]; then
cp -v $old_if_file if_backup
fi;
mv -v $old_if_file $new_if_file;
sed -i -r "s#^s*NAME\s*=.+#NAME=${new_if_name}#" $new_if_file;
sed -i -r "s#^s*DEVICE\s*=.+#DEVICE=${new_if_name}#" $new_if_file;
#echo "$old_if_file => $new_if_file"
if_idx=$(($if_idx+1));
done
popd
if [ -z "$dst_grub_cfg_dir" ]; then
echo "invalid: dst_grub_cfg_dir"
exit 1;
fi;
echo "begin regenerate grub config"
grub2-mkconfig -o $dst_grub_cfg_dir/grub.cfg
echo "rename if name finished"
fi; # $include_rename_if_permanent_sh__