To find a hostname in your local network by IP address you can use nmblookup from the samba suite:
nmblookup -A <ip>
To find a hostname on the internet you could use the host program:
host <ip>
Or you can install nbtscan by running:
sudo apt-get install nbtscan
And use:
nbtscan <ip>
*Adapted from https://askubuntu.com/questions/205063/command-to-get-the-hostname-of-remote-server-using-ip-address/205067#205067
Update 2018-05-13
You can query a name server with nslookup. It works both ways!
nslookup <IP>
nslookup <hostname>