host.txt中信息,已配置DNS正反解。
bigdata-hive-tidb005.bjthq.vivo.lan 10.20.94.5 bigdata-hive-tidb004.bjthq.vivo.lan 10.20.94.4 bigdata-hive-tidb003.bjthq.vivo.lan 10.20.94.3 bigdata-hive-tidb002.bjthq.vivo.lan 10.20.94.2 bigdata-hive-tidb001.bjthq.vivo.lan 10.20.94.1
DNS自检脚本:
- 检查网络是否是连通的;
- 检查主机名是否更改,和DNS中主机名不对应。
while read line do # DNS中主机名及对应的ip dnshost=`echo $line |awk '{print $1}'` ip=`echo $line |awk '{print $2}'` # 获取ping结果的行数,小于等于5则是ping不通的 line=`ping -c 5 -t 10 $ip |wc -l` if [ $line -lt 10 ] then content="$ip网络不通" python sendvnews.py "11085245" "$content" else # 获取主机真实的hostname realhost=`sshpass -p *** ssh -p 22 user@$ip 'hostname' < /dev/null` # 免密码登录到远程主机获取主机名 if [ "$dnshost"x != "$realhost"x ] then echo "$ip主机hostname和dns中不一致" fi fi done < "hosts.txt" #hosts.txt存放 主机名和ip 的对应信息