Linux常见使用


1. 检测网络是否ping通

ping -c1 www.baidu.com
if [ $? -ne 0 ];then
    echo "当前环境判断为隔离内网环境"
    sed -ri '/(114.114.114.114|8.8.)/d' /etc/resolv.conf
    echo -e "#nameserver 114.114.114.114\n#nameserver 8.8.8.8" >> /etc/resolv.conf
else
    echo "当前环境判断为可访问公网环境"
fi