Populating reverse DNS zones

So still working on getting all my data transferred into Identity Management. I have my host data in the base DNS configuration. But we never set up the reverse DNS zones until yesterday. The issue is that I have nearly 1600 entries that I need to populate into their respective reverse DNS zones and I do not want to have to do this manually. I have script that I used to initially import the hosts into IPA, but I need to modify this somehow to run again only this time also populate the reverse DNS zones.

[root@kdc1 LDAP]# more nis-hosts.sh 
#!/bin/sh

IFS=$'\n'
for line in $(cat /root/LDAP/nis-map.hosts); do
	IFS=' '
	ipaddress=$(echo $line | awk '{print $1}')
	hostname=$(echo $line | awk '{print $2}')
	master=$(ipa env xmlrpc_uri | tr -d '[:space:]' | cut -f3 -d: | cut -f3 -d/)
	domain=$(ipa env domain | tr -d '[:space:]' | cut -f2 -d:)
	if [ $(echo $hostname | grep "\." |wc -l) -eq 0 ] ; then
		hostname=$(echo $hostname.$domain)
	fi
	zone=$(echo $hostname | cut -f2- -d.)
	if [ $(ipa dnszone-show $zone 2>/dev/null | wc -l) -eq 0 ] ; then
		ipa dnszone-add --name-server=$master --admin-email=root.$master
	fi
	ptrzone=$(echo $ipaddress | awk -F. '{print $3 "." $2 "." $1 ".in-addr.arpa."}')
	if [ $(ipa dnszone-show $ptrzone 2>/dev/null | wc -l) -eq 0 ] ; then
		ipa dnszone-add  $ptrzone --name-server=$master --admin-email=root.$master
	fi
	# Now create this entry
	ipa host-add $hostname --ip-address=$ipaddress --force
	ipa host-show $hostname
done

My problem is that this throws an error “Nameserver for reverse zone cannot be a relative DNS name.” Everything on my IPA server looks correct, so I don’t know if this script is trying to do something hinky or what. Could use some extra eyes to help me sort this out.

I do see some of the issue. It’s not recognizing that my IP range is xxx.xxx.xxx.0/23, so the reverse DNS zone isn’t found on the host add.

ipa: ERROR: 114.250.132.in-addr.arpa.: DNS zone not found

It should be using 250.132.in-addr.arpa zone. So I suspect this is going to be messy. I just need to figure out how to parse it all into something that I can use to populate the correct reverse DNS zones.

Forgive me if I feel like I’m doing my own troubleshooting in the thread. But the more I type things out the more I see what I need to check.

I think I have a script to do this now. Going per DNS zone for the moment, only because with so many entries I wanted to test and make sure I’m not blowing up my system. Seems that typing out my question did help me figure out my DNS issue and a way to script the primary data entry. Going to take a while to parse through everything, but it will get there soon.