0

I can ssh into my Rpi connected via Ethernet by just typing ssh pi@raspberry or the STATIC ip address I assigned to eth0 Now, when it's on WiFi, with a different STATIC IP address assigned to wlan0, with Ethernet disconnected, I have to use the explicit static ip address to access it, which is rather cumbersome. Not a biggie, really, but is there a way to use ssh pi@raspberry instead of [email protected] regardless of whether it's connected to my local network via eth0 or wlan0? I am on Stretch and avahi is running (if that's important, the little I've learnt thus far)

PS Can anyone also point me to some resource so I better understand the .local variation to the above?

1
  • Try writing questions using paragraphs and sentences. You are more likely to get an answer if you put an effort in your question. See How to set up networking/WiFi which discusses the issue.
    – Milliways
    Commented Oct 18, 2018 at 1:07

2 Answers 2

1

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 [email protected] 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: XXX.XXX.XXX.XXX raspberry

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 [email protected] # 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

0

A resource to this issue is RFC3927. It specifies the use of link-local ip addresses and its addressing with the reserved top level DNS domain local, for example to address raspberrypi.local. An important part of this RFC in section 1.9.3 is:

If a host finds that an interface no longer has an operable routable addr available, the host MAY identify a usable IPv4 Link-Local addr (section 2) and assign that addr to the interface. Ways in which an operable routable addr might cease to be available on an interface include: * Removal of the addr from the interface through manual configuration * Expiration of the lease on the addr assigned through DHCP * Roaming of the host to a new network on which the addr is no longer operable.

That means in short, link-local addresses from the range 169.254.0.0/16 and its naming with DNS domain local are only used if nothing else is used for addressing. If there is a DHCP server on the subnet or if the device has a static ip address then link-local isn't used. Check your device and subnet setting against this condition and things will get clearer. Another discussion to this issue you can find at Can't SSH by name on stretch; can on jessie.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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