1

My impression is that Ubuntu 22.04 comes with avahi preinstalled. How do I most easily check whether the machine I'm using has a .local address, and if so, what that address is? I'm asking under the assumption that the common case is a single .local address for a machine, which is the case I'm interested in.

In macOS, for instance, I would open system settings and look at the Network Settings panel which would tell me the address, which by default is automatically derived from the device's name. I can also customize it there.

The closest I've found in Ubuntu is About in Settings which tells me the Device Name, but not any potentially derived .local address.


Update

Requested information:

libnss-mdns is installed.

$ resolvectl status
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (enp3s0f2)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 3 (wlp2s0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: [...]
       DNS Servers: [...]
        DNS Domain: domain.name
Andreas
  • 891
  • 1
  • 6
  • 20
  • Your "local" address is .local where computer name is the name you assigned to the computer when you installed Ubuntu. You can see it as the past of the command prompt when you open a terminal. This is you device name. – user68186 Jun 03 '22 at 21:14
  • 1
    To add to what user68186 said, you can run `avahi-browse -a` and this should return local services and the name in the format of `+ (network device) (IPV type) (name) . . .` etc. Your address would be `.local` In this example, "device name" refers to the network device (e.g, wlp1s0, eth0, etc) and "name" refers to the name of your computer or machine. It looks like this is the same default format as MacOS if I understand correctly. – mchid Jun 03 '22 at 21:26
  • Also see [this blog post](https://phoenixnap.com/kb/ubuntu-20-04-change-hostname) for how to change hostname. – user68186 Jun 03 '22 at 21:31
  • However, I think it also may depend on if you are using the `systemd-resolved` service. – mchid Jun 03 '22 at 21:32
  • There is [more information here](https://unix.stackexchange.com/questions/459991/how-to-configure-systemd-resolved-for-mdns-multicast-dns-on-local-network) about the systemd version. This is only if you need to get it up and running and it's not up and running as it might not be necessary if avahi is doing the job for you. – mchid Jun 03 '22 at 21:37
  • One question, is `libnss-mdns` installed? I think this may be needed if you are using the avahi method. Also, you can install `mdns-scan` although, running this command will typically show just about the same information (or less) as `avahi-browse -a` – mchid Jun 03 '22 at 21:42
  • There are also other `avahi` commands. If you simply need your local hostname, you can run `avahi-resolve-host-name -a` followed by your local IP address. For example: if your IP is 192.168.1.99, `avahi-resolve-host-name -a 192.168.1.99` – mchid Jun 03 '22 at 21:44
  • To view the other commands, type `avahi` and then press TAB twice – mchid Jun 03 '22 at 21:44
  • @mchid what is the command to get the avahi hostname for the computer I am currently using (without knowing the IP address)? – user68186 Jun 03 '22 at 21:47
  • 1
    @user68186 if you don't know the IP address, you could always "guess" the mDNS name and verify using `avahi-resolve -n` ex. `avahi-resolve -n "$(hostname).local"` – steeldriver Jun 03 '22 at 22:06
  • @user68186 I'm not sure if they're using `systemd-resolve` or not. Would need to run `systemd-resolve --status` to find out. [This answer](https://unix.stackexchange.com/questions/459991/how-to-configure-systemd-resolved-for-mdns-multicast-dns-on-local-network) has more info on that. Without using systemd, you would need to install `libnss-mdns` in addition to avahi and then make sure `files mdns4_minimal [NOTFOUND=return] dns myhostname` is listed after `hosts` in `/etc/nsswitch.conf` similar to [this description](https://wiki.archlinux.org/title/avahi). – mchid Jun 04 '22 at 03:13
  • Also, [this related question](https://askubuntu.com/questions/972630/what-is-mdns-is-it-possible-to-make-mdns-query-without-mdns-service-running). – mchid Jun 04 '22 at 03:14
  • Thanks for the suggestions. Unfortunately I can't mention multiple people so I'll mention @steeldriver that offered a self-contained command. I get the impression from reading the comments that the .local address is guaranteed to be in sync with the hostname. Did I understand that correctly? I'm unfamiliar with the constraints or guidelines that govern mDNS addresses. – Andreas Jun 06 '22 at 21:30
  • 1
    *"...the .local address is guaranteed to be in sync with the hostname."* There is no guarantee, but this is generally correct. In all my years of working with UbuntuI have never seen it deviate from the `hostname.local` format. Only once I have seen a deviation in a Raspberry Pi OS where avahi somehow (wrongly) determined the hostname raspberrypi was already taken and assigned `raspberrypiNNN.local`, where NNN was a number. The problem fixed itself on reboot of the Pi. This happened when I was switching between two versions of the OS in two SD cards where both OS had the same hostname. – user68186 Jun 06 '22 at 21:49
  • 1
    @user68186 I'll add that I too have now experienced this on Raspberry Pi, but on Ubuntu and not Raspberry Pi OS. It seems to be caused by having active IPv4 and IPv6 on the same interface, and is spontaneous. It's discussed here: https://github.com/lathiat/avahi/issues/117 – Andreas May 24 '23 at 20:19

1 Answers1

0

The easiest way I've discovered so far is to enter the Share settings in the Settings app and select Remote Desktop. If there's a .local address it will be listed in the Remote Desktop Address field, e.g: ms-rd://k55a.local. I believe this should work out of the box, without having to install anything.

Or, if you have ssh installed, you can select Remote Login instead and it'll underline the ssh command for connecting to the machine using its .local address, e.g: ssh k55a.local

Andreas
  • 891
  • 1
  • 6
  • 20
  • As said by @steeldriver in the comments, the command `avahi-resolve -n "$(hostname).local"` in the terminal works out of the box, without having to install anything. – user68186 Jun 06 '22 at 21:11
  • @user68186 I don't doubt it – Andreas Jun 06 '22 at 21:13
  • If you add this information in your answer it will be more complete and help others looking for a command line solution. – user68186 Jun 06 '22 at 21:40
  • @user68186 Oh, I see, but I don't want to proactively rob any of the other commenters the opportunity to add their solutions as answers while they were waiting for me to provide additional info, and it seems natural to split answers between GUI and CLI anyway. – Andreas Jun 06 '22 at 21:47