STATIC_IP=“192.168.47.146”
NETMASK=“255.255.255.0”
GATEWAY=“192.168.47.1”
DNS1=“8.8.8.8”
ONBOOT=“yes”
CONFIG_FILE=“/etc/sysconfig/network-scripts/ifcfg-$NIC”
检查配置文件是否存在
if [ ! -f “$CONFIG_FILE” ]; then
echo “配置文件 $CONFIG_FILE 不存在,请检查网卡名是否正确。”
exit 1
fi
更新或添加网络配置项
function update_or_add_config {
KEY=$1
VALUE=KaTeX parse error: Expected group after '^' at position 14: 2 grep -q "^̲KEY=" “ C O N F I G F I L E " ∣ ∣ e c h o " CONFIG_FILE" || echo " CONFIGFILE"∣∣echo"KEY= V A L U E " > > " VALUE" >> " VALUE">>"