Get FQDN Based On IP

I'm trying to get the FQDN of the VPS I am using based on it's private IP. This is for the same VPS that I am logged into.

I'm able to find it by typing host 10.10.10.20 and it returns 20.10.10.10.in-addr.arpa domain name pointer vps.fqdn.name. but I'm wondering if there's an easier way to get just the vps.fqdn.name part?

Reason is I need this name to use as part of my script and I'm not sure how to get only the relevant portion. Is there maybe a different command that returns only the name?
 
I don't think there's a "+short" option for host as there is for dig (not for drill, strangely). If all else fails, you can just do host 10.10.10.20 | awk '{print $NF}'
 
Thanks DutchDaemon! Unfortunately that command still includes the pesky period at the end ( it prints vps.fqdn.name. instead of just vps.fqdn.name )

It's okay, maybe I just won't automate this part of the deployment :p
 
Thanks DutchDaemon! Unfortunately that command still includes the pesky period at the end ( it prints vps.fqdn.name. instead of just vps.fqdn.name )

It's okay, maybe I just won't automate this part of the deployment :p
The pesky period at the end is a legitimate part of the FQDN. Sometimes it is omitted but every DNS capable program should be able to understand the trailing dot. It stands for the root zone: "."
 
The pesky period at the end is a legitimate part of the FQDN. Sometimes it is omitted but every DNS capable program should be able to understand the trailing dot. It stands for the root zone: "."

Thanks rocco, but this is not being piped into a DNS capable program. If my use case allowed for it obviously I would have left it in there.
 
Last edited:
I can't resist polishing that a bit to get the exit status right:
host 10.10.10.20 | grep "domain name pointer" | awk '{print $NF}' | sed -r 's=\.$=='
 
Back
Top