意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

自动重启网卡

来源:恒创科技 编辑:恒创科技编辑部
2022-08-18 14:28:34


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

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


自动重启网卡

创建sh文件:restart_net.sh

#! /bin/sh

while true; do
ping -c 3 www.baidu.com;
if [ $? -ne 0 ]; then
service network restart;
echo 'ping www.baidu.com fail. restart network done';
fi

ping -c 3 192.168.0.193;
if [ $? -ne 0 ]; then
service network restart;
echo 'ping 192.168.0.193 fail. restart network done';
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

自动重启网卡_重新启动

上一篇: 租用美国服务器:潜在的风险与应对策略。 下一篇: LINUX系统怎么关闭防火墙