自动重启网卡

自动重启网卡(网卡不稳,常常掉线)

如上述代码所示,假如三次均不能ping
通某个IP地址(这里用的是局域网的网关),则重新启动网卡,之后休眠10秒,然后再重复。

创建sh文件:restart_net.sh

while true; do
    ping -c 3 192.168.0.193;
    if [ $? -ne 0 ]; then
        ifup eth0;
    fi
    sleep 10;
done

执行

/bin/bash  restart_net.sh 2>&1 > /root/shell/log/restart_net.log &

查看日志: tail -f /root/shell/log/restart_net.log

发布了263 篇原创文章 · 获赞 46 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/qq_27229113/article/details/103458777