Rasperry
Posts: 20
Joined: Sun Jan 26, 2020 5:25 pm

2x RaspberryPi 4 connected over switch ... finding IP?

Fri Feb 21, 2020 11:42 am

I have one RPI4 connected to the monitor, with keyboard and mouse ....
There is also the second RaspberryPi4 (with SSH enabled) which is connected to the first via ethernet switch.

Is there a way to find IP of the second RPI via switch so i could connect from one to the other with ssh command?

There is a lot of info of how to find IP if RPIs are connected over local router ... but i cant find info about finding ip if two are connected only locally over switch.

Thank you!

epoch1970
Posts: 4475
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Fri Feb 21, 2020 12:05 pm

With Raspbian, "ping <machine_name>.local" or "ssh <machine_user>@<machine_name>.local" will work as long as the 2 Pis are on the same network (ethernet or wifi).

The .local domain is the one dedicated to mDNS/zeroconf. As the name implies the contraption is designed to allow machines relate with each other over a local network automatically, and in absence of any networking service like DHCP or DNS.
In the world of zeroconf, IP addresses are volatile, but .local names are always up-to-date. In other words, use .local names and forget about IP addresses.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Rasperry
Posts: 20
Joined: Sun Jan 26, 2020 5:25 pm

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Fri Feb 21, 2020 12:53 pm

What exactly is

"ping <machine_name>.local"

"ssh <machine_user>@<machine_name>.local"


Can you give example of what to type, sorry for n00b questions ...

epoch1970
Posts: 4475
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Fri Feb 21, 2020 1:14 pm

"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Rasperry
Posts: 20
Joined: Sun Jan 26, 2020 5:25 pm

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Fri Feb 21, 2020 1:58 pm

Ok thank you, i understand now and it works! :)

Rasperry
Posts: 20
Joined: Sun Jan 26, 2020 5:25 pm

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Fri Feb 21, 2020 2:19 pm

One more question ... i can get back IP address if i know the name of the specific RPI (default is: raspberrypi) with command:

"ping raspberrypi.local"


But to get ip's for all RPIs that are connected via switch (for instance i have 4), this command isnt working for me:
"nmap -sn 192.168.1.0/24"

For instance,
IP addresses of each RPI are (if i obtain them with previous method):

1. RPI
eth0:
inet 169.254.201.28

2. RPI
eth0:
inet 169.254.28.94


How could i get both ip's with one command (or maybe all 4 ips if i have them connected all via switch) in that case?

epoch1970
Posts: 4475
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Fri Feb 21, 2020 3:21 pm

It is a bit complicated. You're "holding it wrong", try to stop thinking about the IP addresses.

Here is the thing. With mDNS, all machines decide upon their own IP address, and publish it along with their host name. The only link/agreement between the machines is the use of a common multicast network address, 224.0.0.251 (for IPv4) and port, 5353/udp.
That multicast address is like a stream, carrying messages of various kinds over the local network. A question doesn't elicit a direct answer; after a question, there will be an answer coming in, in time (or never).
To speed up things a little, all machines keep a local cache of the information they've seen recently. But the cache cannot be too long-lived otherwise it might hold obsolete information, e.g. still resolving a machine when in fact that wireless client has left the network.

On linux, you can see the information stream by using the "avahi-browse" command, e.g. "avahi-browse --all --ignore-local --resolve". You'll see a flow of service records, and machines names and IP addresses. You'll need to interrupt browsing by hitting control-C, or by adding option "--terminate".
IIRC "terminate" just drops on your lap the current contents of the local cache, before exiting. You may, or may not, see the info you wanted to see before browsing terminates.

Avahi has various other user commands, like "avahi-resolve", "avahi-resolve-host-name", "avahi-resolve-address" that you might want to use. Fundamentally these work like avahi-browse: send a message in a bottle and hope for the best.

In addition, since with zeroconf the IP address is selected by each machine on its own, there is no guarantee the address is valid for any length of time. Machines come and go, generating a more or less random address for themselves each time; IP conflicts might happen, causing machines to generate new IP addresses.

Now. I hope you're confused enough... Rely only on .local names ;)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Rasperry
Posts: 20
Joined: Sun Jan 26, 2020 5:25 pm

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Wed Feb 26, 2020 7:26 am

"avahi-browse" or any other command doesnt work.

But nevermind, i got now what i was searching for so thank you again and for long explanation :)

epoch1970
Posts: 4475
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: 2x RaspberryPi 4 connected over switch ... finding IP?

Wed Feb 26, 2020 12:03 pm

Sorry I forgot: you need to “apt install avahi-utils” to get the binaries I mentioned above...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Networking and servers”