3

According to Get the Hostname From an IP Address on the LAN, I can get the hostname of an IP address of a local server either using the nmblookup or nbtscan. However, these commands are not getting a reply (see below). I can ping 192.168.1.50 and ssh into it as it is a Ubuntu 24.04 Server. Why am I not getting the hostname and how to fix this issue?

$ nmblookup -A 192.168.1.50
Looking up status of 192.168.1.50
No reply from 192.168.1.50
$
$ nbtscan 192.168.1.50
Doing NBT name scan for addresses from 192.168.1.50

IP address NetBIOS Name Server User MAC address

$ $ ping 192.168.1.50 PING 192.168.1.50 (192.168.1.50) 56(84) bytes of data. 64 bytes from 192.168.1.50: icmp_seq=1 ttl=64 time=6.87 ms 64 bytes from 192.168.1.50: icmp_seq=2 ttl=64 time=4.34 ms 64 bytes from 192.168.1.50: icmp_seq=3 ttl=64 time=3.91 ms 64 bytes from 192.168.1.50: icmp_seq=4 ttl=64 time=3.39 ms 64 bytes from 192.168.1.50: icmp_seq=5 ttl=64 time=3.37 ms 64 bytes from 192.168.1.50: icmp_seq=6 ttl=64 time=1.78 ms ^C --- 192.168.1.50 ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5008ms rtt min/avg/max/mdev = 1.778/3.942/6.869/1.529 ms $ $ avahi-resolve -a 192.168.1.50 Failed to resolve address '192.168.1.50': Timeout reached

PS. I am aware of How to find a computer name in a LAN from the IP address? but the answers there do not address my query.

I wonder if the setting in this file is causing the issue, hmm?

$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd: files systemd sss group: files systemd sss shadow: files sss gshadow: files

hosts: files mdns4_minimal [NOTFOUND=return] dns mymachines networks: files

protocols: db files services: db files sss ethers: db files rpc: db files

netgroup: nis sss automount: sss

The ubuntu 22.04 desktop client IP is 192.168.1.170 and it is connected via wifi to the router 192.168.1.1. The Ubuntu 24.04 server is connected to the router via ethernet and its IP is 192.168.1.50. Its stub resolver is running on port 53. Also, I am setting it up as a local DNS on port 3000.

Sun Bear
  • 3,014

2 Answers2

1

host and nslookup

Typically, when looking up a hostname, you'll use either the host or nslookup command, such as the following:

host 192.168.1.50
nslookup 192.168.1.50

But for these to work, the hostname for these hosts need to be registered with a DNS server or entered into your /etc/hosts file. If you have a local DNS server on your network, then you can register the hosts there. Otherwise, your router may be configured as a DNS resolver and can be configured there.

nmblookup and nbtscan

You indicated nmblookup and nbtscan are not replying. This is because both of these commands use the NetBIOS over TCP/IP protocol to lookup NetBIOS names, which are not necessarily the same as the hostname. Basically, NetBIOS provides a naming service in a Windows environment. In order to work with Ubuntu hosts, you'll need to configure Samba and windbind on each host.

nmap

You state that the answers here did not give you what you want. But the nmap command should work and return information with the hostname. For example, I can enter the following command with results that include the hostname:

$ nmap -sn 192.168.10.20
Starting Nmap 7.80 ( https://nmap.org ) at 2024-10-28 23:14 PDT
Nmap scan report for gamekeeper.localdomain (192.168.10.20)
Host is up.
Nmap done: 1 IP address (1 host up) scanned in 0.00 seconds

To extract the hostname out of this, I can run the following command:

$ nmap -sn 192.168.10.20 | grep 192.168.10.20 | awk '{print $5}'
gamekeeper.localdomain

If nmap isn't installed on your computer, you can install it with sudo apt install nmap.

Avahi

Another option is to use Avahi, which facilitates service discovery on a local network via the mDNS/DNS-SD protocol suite. Similarly, you may be familiar with Bonjour, which is Apple's technology known as zero-configuration networking to allow discovery of devices and services on a local network using standard IP protocols.

You've indicated in your original post that the output of avahi-resolve -a 192.168.1.50 times out. This can be caused by the host not being reachable on the network. However, you say you can ping and ssh into it, so I suspect that the problem is because you don't have avahi-daemon installed on the host you're querying.

By default, avahi-daemon is installed on Ubuntu Destktop 22.04 and 24.04, but it's not installed on Ubuntu Server 22.04 and 24.04. Your post says you're trying to lookup the hostname of a "server" and you're querying from a "desktop". So, first things first, install avahi-daemon on your server with the following commands:

sudo apt update
sudo apt install avahi-daemon

Afterwards, lookup the status and you'll see the service running:

$ systemctl status avahi-daemon
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack
     Loaded: loaded (/lib/systemd/system/avahi-daemon.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-09-18 22:10:08 PDT; 1 month 9 days ago
TriggeredBy: ● avahi-daemon.socket
   Main PID: 538 (avahi-daemon)
     Status: "avahi-daemon 0.8 starting up."
      Tasks: 2 (limit: 19106)
     Memory: 2.2M
        CPU: 1min 30.056s
     CGroup: /system.slice/avahi-daemon.service
             ├─538 "avahi-daemon: running [gamekeeper.local]"
             └─566 "avahi-daemon: chroot helper"

Finally, from your Desktop client, you can resolve the hostname with:

avahi-resolve -a 192.168.1.50

As an example:

avahi-resolve -a 192.168.10.20
192.168.10.20   gamekeeper.local

You've updated your question indicating that your Desktop is connected via WiFi and your server is connected via Ethernet. The reason mDNS is not working is probably due to your router either blocking mDNS over WiFi or packets are being dropped.

See this Superuser question/answer for more info:

Why do some WiFi routers block multicast packets going from wired to wireless?

Therefore, as a test, try connecting the Desktop computer to your router via Ethernet and try resolving your hostname again.


As a side note, your /etc/nsswitch.conf file is configured correctly.

If you check this answer that I wrote for someone asking about resolving local hostnames, I outline and explain what the hosts line means in the /etc/nsswitch.conf file.


For more information about Avahi, visit avahi.org and see this AskUbuntu answer. Also, this answer has some great info on mDNS.

mpboden
  • 3,046
0

If you have nmap installed, try:

nmap -sL 192.168.1.50

Starting Nmap 7.95 ( https://nmap.org ) at 2024-10-29 06:06 GMT Nmap scan report for examplehost.examplefqdn.com (192.168.1.50) Nmap done: 1 IP address (0 hosts up) scanned in 0.02 seconds

Reverse lookup relies on your local DNS server (which may be on your router) knowing the hostnames for IP addresses on your network. There are several reasons why the DNS may not know the hostname of an IP. If DNS correctly configured to resolve this host, restarting the networking on your server (or rebooting) will refresh DHCP on the server and give the DNS server a chance to update.

You could try:

nmap -sL 192.168.1.0/24

Look for correctly identified hostnames in the list: this will tell you if any host on your network can resolve an IP to a hostname using DNS.

moo
  • 966