recipe_gentoo/recipes/recipe_check_dns_config.sh

69 lines
1.8 KiB
Bash
Executable file

print_config_title 'CHECK DNS CONFIG'
# Test resolver
for name_to_resolv in ${NAMES_TO_RESOLV_AND_PING[@]};
do
echo -e "Check resolve ${BLUE}${name_to_resolv}${NC}"
# Check if name is resolved
# We use nslookup because return code can be used in our case
nslookup ${name_to_resolv} &>/dev/null
# Return Code
RC=$?
# Resolving failed
if [ $RC -ne 0 ]
then
RESOLV_FAILED="${RESOLV_FAILED} ${name_to_resolv}"
echo -e "${RED}Resolve ${name_to_resolv} FAILED : check KO${NC}\n"
# Resolving succeded
else
echo -e "${GREEN}Resolve ${name_to_resolv} SUCCEDED : check OK${NC}\n"
fi
done
# Check /etc/resolv.conf
for resolver in ${RESOLVERS[@]}
do
echo -e "Check in /etc/resolv.conf if this name server is present : ${BLUE}${resolver}${NC}"
# Check /etc/resolv.conf
grep -qi "^nameserver[[:space:]]*${resolver}[[:space:]]*$" /etc/resolv.conf
# Return Code
RC=$?
# Resolver is NOT in the file
if [ $RC -ne 0 ]
then
RESOLVER_NOT_IN_ETC_RESOLVCONF="${RESOLVER_NOT_IN_ETC_RESOLVCONF} ${resolver}"
echo -e "${RED}${resolver} is NOT in /etc/resolv.conf : check KO${NC}\n"
# Resolver is in the file
else
echo -e "${GREEN}${resolver} is in /etc/resolv.conf : check OK${NC}\n"
fi
done
# Check if IP recorded in DNS
for ip in ${LOCALES_IP_WITHOUT_LOOPBACK[@]}
do
echo -e "Check if IP is recorded in DNS : ${BLUE}${ip}${NC}"
# Check /etc/resolv.conf
nslookup ${ip} &>/dev/null
# Return Code
RC=$?
# IP NOT recorded in DNS
if [ $RC -ne 0 ]
then
IP_NOT_RECORDED_IN_DNS="${IP_NOT_RECORDED_IN_DNS} ${ip}"
echo -e "${RED}${ip} is NOT recorded in /DNS : check KO${NC}\n"
# IP recorded in DNS
else
echo -e "${GREEN}${ip} is recorded in DNS : check OK${NC}\n"
fi
done