在vmware workstation 6.0版下,使用Bridged 方式,linux系统启动时,有时候能访问实机网络,有时候不可以。
在不可以访问网络时,在linux下重启动网络:/etc/rc.d/init.d/network restart ,有时候执行一次这个命令,就可以访问网络,有时候还得执行两三次才可以。
在不可以访问网络时,在linux下重启动网络:/etc/rc.d/init.d/network restart ,有时候执行一次这个命令,就可以访问网络,有时候还得执行两三次才可以。
解决办法:在虚拟机下的Linux系统启动时,自动检查网络情况,发现不能ping外网时,自动重启网络。
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
i=0
j=0
rm -rf /root/netlog
while [ $i = 0 ]
do
ping -w20 192.168.0.1 -c 2 >> /root/netlog
if [ $? = 0 ] ; then
i=1
else
service network restart
(( j++ ))
if [ $j = 10 ]; then
i=1
echo "10 time" >> /root/net/log
fi
fi
done
j=0
rm -rf /root/netlog
while [ $i = 0 ]
do
ping -w20 192.168.0.1 -c 2 >> /root/netlog
if [ $? = 0 ] ; then
i=1
else
service network restart
(( j++ ))
if [ $j = 10 ]; then
i=1
echo "10 time" >> /root/net/log
fi
fi
done
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
192.168.0.1 是网络中的IP,上述方法是使用了10次重启network 的限制,以免因一些特殊原因造成一直无法访问外网,从而导致无法进入系统。
netlog 是启动日志。
netlog 是启动日志。
虽然不是很好的方法,确也勉强达到了要求,若有更好的方法,谢谢回贴!
转载于:https://blog.51cto.com/fdsazi/410908