17

I'm setting up a Raspberry Pi for the first time, and have been SSHing into it on a Mac on the same network like so:

ssh pi@raspberrypi.local

However on my Windows 10 box (also on the same network) this hostname does not resolve. I've tried ipconfig /flushdns, nslookup raspberrypi.local and similar commands to get my Windows machine to see the Raspberry Pi but to no avail. Since it's working on my Mac it doesn't seem like a router issue.

What can I do to connect to my Pi by hostname on Windows?

1
23

How To Geek has a good article that covers this issue. In a nutshell .local domains are self-reported by each host (via Multicast DNS), and other machines on the network have to listen for them. Windows comes with such a service (LLMNR) however it's non-standard and therefore doesn't work terribly well. Instead you should install Apple's Bonjour service (install link). Once Bonjour is installed you'll be able to connect to your Pi on Windows via .local hostnames.


Modern Raspbian versions should come with Avahi to provide mDNS. If it's not working make sure avahi-daemon is installed and running on your Pi; if it's not run the following to install it:

sudo apt-get install avahi-daemon
5
  • Wouldn't changing the .local part into .int or .home work around this issue? Apr 4 '16 at 8:30
  • 1
    @ismael - no, the tld is not the issue, it is Windows 10 not knowing about the device...the .local is setup to work with the local network, a different tld is going to work worse/need more setup in my experience.
    – DrCord
    Apr 5 '16 at 19:21
  • In my experience, editing the hosts file will work. I use that for a badly setup server. (I've set it up like that due to time constraints and because it is simply to test some code before deploying). So far, always worked for me. Apr 5 '16 at 19:35
  • 2
    @IsmaelMiguel editing the hosts file works, but it's not a very robust solution. Every time a machine is allocated a new IP you need to edit the file, and if you have multiple machines you try to connect from you need to keep multiple host files in sync. mDNS does all that for you.
    – dimo414
    Apr 5 '16 at 21:43
  • 1
    With mDNS/Bonjour/Avahi, you should never change the TLD..local is the official one specified in the RFCs, and many devices (such as many printers) cannot even be reconfigured for another TLD. Also, .local is guaranteed to never be assigned as an official TLD (although it was already widely used for Active Directory domains when mDNS was codified). .home is virtually guaranteed to cause conflicts.
    – user87363
    Jun 10 '18 at 4:26
-1

I should confess and tell you that I use git for windows to access my pi, so git-bash gives me a minimal bash environment on Windows. You may prefer Putty or WSL etc. This method will work with Mac, Linux and WSL, and it answers the OPs question of "How do I".

  1. Assign the pi a static ip address
  2. use ~/.ssh/config to create your ssh "address book"
nano ~/.ssh/config

Host raspberrypi.local
     User pi
     Hostname 192.168.0.22
     Port 22

Host rpi
     User pi
     Hostname pi.duckdns.org
     Port 22222
     IdentityFile /home/ron/.ssh/id_ed25519.pub


### Default settings for all Hosts if not declared above
Host *
      ForwardAgent yes
      ForwardX11 yes
      ForwardX11Trusted yes
      User ron
      Port 22
      Protocol 2
      ServerAliveInterval 60
#     ServerAliveCountMax 30

Now save the file. From the command line you can easily ssh onto your target server:

 ssh raspberrypi.local

But you could just as easily change the Host field to something very convenient such as "pi" so you could use:

 ssh pi

See also: https://linuxize.com/post/using-the-ssh-config-file/

3
  • You shouldn't need to do all this manual bookkeeping and configuration. Your router probably supports mDNS and with that .local addresses should "just work", no need to configure IP addresses in every client. Even if you can't use mDNS you can set up DDNS on your pi and connect to it via that address.
    – dimo414
    Feb 23 at 7:46
  • The OP wants to connect to the pi "ssh raspberrypi.local" I gave him a fully functional workaround that does not include a malfunctioning mDNS client on a system that was not designed to support it. By all means, carry on troubleshooting mDNS with him. I'd like to learn why my avahi/bonjour setup failed as well. Cheers!
    – Ron K.
    Feb 24 at 17:52
  • I am the OP :) I have been using the above setup without issue for the past four years, despite multiple moves, IP address changes, and added/removed devices. Much simpler than manually configuring each client.
    – dimo414
    Feb 24 at 17:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.