(RHEL7.2)复制vmware虚拟机后,systemctl network restart 失败问题,替代解决方案;网口配置文件修改后,网口生效。

【修改配置文件/etc/sysconfig/grub.cfg 禁用eno16777736后,用eth0和eth1】网口异常问题;

(1)修改vi /etc/sysconfig/network-scripts/ifcfg-eth0的IP和mac

       [root@228002 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

 (2)systemctl restart network.service 失败

Restarting network (via systemctl): Job for network.service failed. See ‘systemctl status network.service’ and ‘journalctl -xn’ for details.

(3)可以参考下楼的博客操作修改,重启;

(4)如果还是报错,我写了个restartEthernet程序,大家可以直接复制下载、使用;

(源代码如下:引用请注明)

[root@228002 ~]# vi restartEthernet

#!/bin/bash
LANG=C
TMPCHAR=/tmp/tmpchars
TMPCHAR1=/tmp/tmpchars1
TMPCHAR2=/tmp/tmpchars2

touch $TMPCHAR
touch $TMPCHAR1
touch $TMPCHAR2
chmod 777 $TMPCHAR
chmod 777 $TMPCHAR1
chmod 777 $TMPCHAR2

Print_help()
{
 echo -e "\e[1;33mInput the cmd is error ! \e[0m \n"
 echo -e "\e[1;32m sh restartEthnet <eth0/eth1/eno0/eno1/all>  \e[0m \n"
 echo -e "\e[1;32m eg:  sh restartEthnet eth0  \e[0m \n"
 echo -e "\e[1;32m eg:  sh restartEthnet eth1  \e[0m \n"
 echo -e "\e[1;32m eg:  sh restartEthnet eno0  \e[0m \n"
 echo -e "\e[1;32m eg:  sh restartEthnet all \e[0m \n"
 echo -e "\e[1;33m----------<version 1.0.1;create by amu.mu;date:20221107>------------- \e[0m \n"
}

if [ ! -f /usr/local/bin/restartEthernet ] ;then
{
        rm -rf /usr/local/bin/restartEthernet
        cp -f ./restartEthernet /usr/local/bin
        chmod +x /usr/local/restartEthernet
        echo -e "\e[1;33mthe [restartEthernet] in the </usr/local/bin> ,was created ! \e[0m \n"
}
else 
{
        echo -e "\e[1;32m the [restartEthernet] in the </usr/local/bin> ,continue ! \e[0m \n"
}
fi

if [ $# -eq 1 ];then 
        echo -e "\e[1;32m the parameter number = 1 ,[ok], continue ...\e[0m \n"
else
        echo -e "\e[1;31mthe parameter number is error !\e[0m \n"
        Print_help
        exit 1
fi
#echo "">$TMPCHAR

case $1 in
eth0|eth1|eno0|eno1)
        echo -e "$1 \n"
        ifdown $1
        ifup $1
        ifconfig $1
;;
all)
        echo -e "all of network restart!"
        array=`ifconfig -a|grep :\ |awk '{printf $1}' `
        echo -e "array=$array"
        O_IFS="IFS"
        IFS=":"
        for var in $array
        do 
                echo -e $var |tee -a $TMPCHAR
        #       paste "ifdown" $var |tee -a $TMPCHAR
        done
        awk '{print "ifdown "$0}' $TMPCHAR >$TMPCHAR1
        awk '{print "ifup "$0}' $TMPCHAR >$TMPCHAR2

        echo -e "---cat /tmp/tmpchars0~2---start---------------------"
        cat $TMPCHAR
        echo -e "[eth*]___________________"
        sleep 1
        cat $TMPCHAR1
        echo -e "[ifdown*]___________________"
        sleep 1
        cat $TMPCHAR2
        echo -e "[ifup*]___________________"
        echo -e "---cat /tmp/tmpchars0~2---end-----------------------"
        sleep 1
        sh $TMPCHAR1
        sleep 2
        sh $TMPCHAR2
        sleep 3
        echo -e "^-^:^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
        ifconfig -a
        echo -e "^-^:^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
;;
*)
        Print_help

;;
esac

rm -f $TMPCHAR
touch $TMPCHAR
#end

执行 :wq 保存;
[root@228002 ~]# 

(5)给执行权限:chmod +x restartEthernet 

(6)在当前目录下执行一次 :sh restartEthernet eth0     

        说明:(eth0为修改IP的网口),脚本会把restartEthernet 程序添加到/usr/local/bin目录下,以后可以在任意目录视图下执行:restartEthernet +网口;

例如:[root@228002 ~]# restartEthernet eth0

(7)查看是否生效?

 成功!

(8)restartEthernet 脚本程序集成了帮助信息,入手使用简单,可以参考如下:

参考博客:

Red Hat把网卡eno16777736修改成eth0,顺便解决了无网络的问题(超详细)_你白勺男孩TT的博客-CSDN博客_eno16777736

service network restart报错Job for network.service failed. See 'systemctl status network.service'....._sdfreregtrh的博客-CSDN博客

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值