How to Resolve Hostnames from IP Addresses in Windows and Linux Networks


2 views

In a Windows network environment, you might need to find the hostname associated with a specific IP address. This is common when managing multiple machines in a LAN or when troubleshooting network issues. Similarly, you might need to perform this operation from a Linux machine in a mixed environment.

Windows provides several built-in commands to resolve hostnames from IP addresses:

nbtstat -A 192.168.1.100

This command will display the NetBIOS name table for the specified IP address, including the hostname. For example:

Local Area Connection:
Node IpAddress: [192.168.1.100] Scope Id: []

           NetBIOS Remote Machine Name Table

       Name               Type         Status
    ---------------------------------------------
    WORKSTATION1      <00>  UNIQUE      Registered
    WORKGROUP        <00>  GROUP       Registered

Another useful command is:

ping -a 192.168.1.100

This will attempt to resolve the hostname through DNS and display it if successful.

For more advanced scenarios, PowerShell provides better options:

[System.Net.Dns]::GetHostEntry("192.168.1.100").HostName

This will return the fully qualified domain name (FQDN) if available in DNS.

When you need to resolve a Windows hostname from a Linux machine, you can use nmblookup (part of samba-common package):

sudo apt-get install samba-common
nmblookup -A 192.168.1.100

Example output:

Looking up status of 192.168.1.100
    WORKSTATION1    <00> -         B <ACTIVE>
    WORKGROUP       <00> - <GROUP> B <ACTIVE>

If these methods don't work, you might need to check:

  • DNS server records
  • WINS server (in older Windows networks)
  • Local hosts files (/etc/hosts on Linux or C:\Windows\System32\drivers\etc\hosts on Windows)

If you're having trouble resolving names:

  1. Verify network connectivity
  2. Check firewall settings (NetBIOS ports might be blocked)
  3. Ensure NetBIOS over TCP/IP is enabled on Windows machines
  4. Verify DNS and WINS settings

When working in a Windows network environment, you can use these methods to map IP addresses to hostnames:

nbtstat -A [IP_ADDRESS]
# Example:
nbtstat -A 192.168.1.15
# Shows NetBIOS name table including hostname

Alternatively, use PowerShell for more modern systems:

Test-Connection -ComputerName [IP_ADDRESS] -Count 1 | Select-Object PSComputerName
# Or using .NET methods:
[System.Net.Dns]::GetHostEntry("192.168.1.15").HostName

For standard DNS resolution across platforms:

nslookup [IP_ADDRESS]
# Example output:
# Name:    ws-accounting.example.com
# Address:  192.168.1.15

When querying Windows hosts from a Linux machine, these commands are most effective:

nmblookup -A [IP_ADDRESS]
# For NetBIOS name resolution (works with Windows workgroups)

avahi-resolve-address [IP_ADDRESS]
# For mDNS/Bonjour resolution

dig -x [IP_ADDRESS] +short
# Standard DNS reverse lookup

For comprehensive discovery across all 50 hosts:

# Bash script to scan subnet and resolve names
for ip in $(seq 1 254); do 
  host=$(nslookup 192.168.1.$ip | grep "name =" | cut -d= -f2)
  [ -n "$host" ] && echo "192.168.1.$ip => $host"
done

If resolution fails, consider these factors:

  • NetBIOS over TCP/IP must be enabled on Windows hosts
  • Check firewall settings for UDP ports 137/138 and TCP 139
  • Verify DNS reverse lookup zones are properly configured
  • For Linux-Windows communication, install Samba utilities

For application-level integration in Python:

import socket
try:
    hostname = socket.gethostbyaddr("192.168.1.15")[0]
    print(f"Resolved hostname: {hostname}")
except socket.herror:
    print("Resolution failed")