I tried to do the same thing - and failed. But I solved the problem well enough for myself, so I didn't go further down the rabbit hole. As you said, "not a biggie".
... is there a way to use ssh pi@raspberry instead of pi@XXX.XXX.XXX.XXX regardless of whether it's connected to my local network via eth0 or wlan0?
Yes, I can give you two quick fixes.
Quick fix 1: Edit your hosts file. Specifically, if you are using a common distro like Ubuntu, the file you are looking for is
/etc/hosts. Add the following line:
I don't know where the hosts file is on Windows, but I vaguely remember changing it, so it should be similar for Windows as well.
Quick fix 2: Even simpler: CTRL+R - backwards search in command history (reverse-i-search). I use this quick fix. Assuming you use bash, I recommend this solution.
Step 1 is connecting to my Rpi by using this command:
ssh pi@XXX.XXX.XXX.XXX # raspberry
After having executed this command, whenever I want to ssh into my Rpi: I open a terminal > press CTRL+R > type
raspberry > press Enter.
These quick fixes will work for one computer only. One might be motivated to find a more general solution.
Further down the rabbit hole: Now we are very close to where my knowledge ends. I'll try to give you the general idea that I have.
Here's a different way to look at it: The world is not just SSH. If there's a web server running on your RPi, and if you type your RPi's IP address into a browser, sure enough, you will get a web page from your RPi. Hypothetically, if you solved your problem, you could type in
raspberry into the browser and get the same page. What happens if you name your RPi
google.com instead of
raspberry? (It's easy, just change
/etc/hostname.) Anybody (within your network) trying to speak to Google would end up at your RPi. There are (and should be) mechanisms preventing that. I believe these are ultimately responsible for your problem.
There are mechanisms for translating* human-readable names to IP addresses. DNS is one of them. In case of DNS, there are servers which give you the IP address for a given human-readable name. And then there are servers which give you IP addresses for other servers which might give you the IP address you are looking for.
So you have to register the name
raspberry with at least one of these servers. There's probably one running on your computer as well. Probably another one running on your WiFi router (some sort of cache). Your router/ethernet switch might have adopted a more secure approach for wireless connections compared to wired connections. So maybe this "registration" happens automatically for cabled connections on your specific device. I don't know. Unlike you, I cannot connect to my RPi using
ssh pi@raspberry even though both my RPi and my computer are connected via ethernet cables to the same switch. And about a year back, I tried out my RPi at a friend's house. I remember being able to connect by using
ssh pi@raspberry, over Wi-Fi.
A similar question is asked here, in cased you are interested in a detailed answer: https://superuser.com/questions/185678/connect-to-linux-by-name-rather-than-ip