0

So I want to connect ssh to my RPi 3 through an ethernet port on my Macbook pro.

My RPi is on jessie.

I am not able to find the local IP address of the RPi through my computer. I can find the ethernet port's address but shh into that address does nothing. The only way I can shh to the RPi is by using $ ssh [email protected] . After doing this ssh, doing $ arp -a resolves the ipv4 ipv6 and host name. Maybe even sometimes, closing the terminal session and then starting a new one and running $ arp -a displays the RPi info directly.(probably because its info is cached)

What I want is to be able to resolve the IP address of the RPi without having to run $ ssh [email protected] first. So I could open terminal do some other command (I guess) and then run $ arp -a and it would display it.

Something else I have noticed; the RPi sometimes as an IPv6 instead of IPv4, which is strange because the RPi is design to express IPv4 locally.

I don't want to do the internet sharing thing because it is really not necessary.

3
  • Why do you want to know the IP address? I never bother, I always use hostname.local (OK it doesn't work with rsync). No one can "resolve" your problem (if you have one) because you have not described your network topography.
    – Milliways
    Commented Apr 26, 2017 at 0:49
  • Okay i'll describe my network. I want to find the IP address because what if I didn't remember the hostname. My network is a Macbook pro (OSX 10.11.6) and a RPi connected to the ethernet port of my mac. That port is using DHCP with a manual address (I rather have this than a static protocol because its more flexible for applications). Commented Apr 26, 2017 at 13:41
  • First you should paste additional detail into your question not comments. "That port is using DHCP with a manual address" makes no sense! Are you running a DHCP server on the Mac? From your comment on another answer, it appears you are using 169.254 which is a Link-local address i.e. NO address has been allocated (this is to be expected with a direct connection). As for "didn't remember the hostname" what do you expect?
    – Milliways
    Commented Apr 27, 2017 at 5:52

2 Answers 2

1

Ideally, you could set a static IP address for your Raspberry Pi either through DHCP assignment in your router or by changing your Raspberry Pi's configuration.

Having said that, would ping work to answer your immediate question?

ping -c 1 raspberrypi.local

That will attempt to contact your Pi using it's local name. The -c 1 option limits it to a single ping attempt since it should have located your Pi's IP address by then.

I just want to reiterate that there are better solutions out there. This is kind of a hack.

1
  • Yeah this is just another hack. You were using raspberry.local to find the IP, similar to what I do. Commented Apr 25, 2017 at 16:56
0

I am not much on networks, but could you use a ping script to locate it? This is what I tried for my network address. Depending on you network, 20 is enough for me, you could also use a shell script to loop through the ip addresses get hostnames, ssh 192.168.0.3 hostname.

pi@RPi3:~ $ time for x in $(seq 2 20); do ping -rc1 -W1 192.168.0.$x | grep 'from'; done
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=1.31 ms
64 bytes from 192.168.0.3: icmp_seq=1 ttl=64 time=6.20 ms
64 bytes from 192.168.0.4: icmp_seq=1 ttl=64 time=1.53 ms
64 bytes from 192.168.0.5: icmp_seq=1 ttl=64 time=0.104 ms
64 bytes from 192.168.0.6: icmp_seq=1 ttl=64 time=5.69 ms
64 bytes from 192.168.0.7: icmp_seq=1 ttl=64 time=5.36 ms
64 bytes from 192.168.0.8: icmp_seq=1 ttl=64 time=1.20 ms
64 bytes from 192.168.0.9: icmp_seq=1 ttl=64 time=2.38 ms
64 bytes from 192.168.0.12: icmp_seq=1 ttl=128 time=4.57 ms
64 bytes from 192.168.0.13: icmp_seq=1 ttl=64 time=54.7 ms
64 bytes from 192.168.0.15: icmp_seq=1 ttl=64 time=6.31 ms
64 bytes from 192.168.0.16: icmp_seq=1 ttl=128 time=1.41 ms

real    0m7.292s

Run arp -a -n | grep -v 'incomplete' to get the MAC address.

...
? (192.168.0.3) at 00:21:2f:38:9a:9f [ether] on wlan0
...

Now you can ssh pi@$(arp -a -n | grep '00:21:2f:38:9a:9f' | awk '{print $2}' | tr -d '()'). Reference https://askubuntu.com/questions/643928/is-it-possible-to-connect-remote-machine-using-mac-address.

On a Class B network the following script will find the IP addresses. It runs in background and takes about 5 to 10 minutes to run, you have to press [Enter] to get prompt back.

for x in $(seq 1 255); do
    (for y in $(seq 1 254); do
        ping -c1 -W1 -I eth0 169.254.$y.$x 2> /dev/null |\
            grep 'bytes from'
        done &)
    done
4
  • This is so strange. I run $ time for x in $(seq 90 96); do ping -rc1 -W1 169.254.63.$x | grep 'from'; done on my mac (My RPi ip is 169.254.63.94) and I get network not reached on the RPi ip. The RPi is connected to my mac by LAN cable and yours is connected by wlan, maybe this is why the ping is not working? Commented Apr 26, 2017 at 14:01
  • Wow! The 169.254 network has 255 * 255 possible addersses. time for x in $(seq 1 255); do for y in $(seq 1 254); do ping -rc1 -W1 169.254.$x.$y | grep 'from' ; done; done would take over 18 hours to find. If you can get the MAC address, try ssh pi@$(arp -a -n | grep '00:21:2f:38:9a:9f' | awk '{print $2}' | tr -d '()') with your MAC address. It should work if in the arp table.
    – bstipe
    Commented Apr 26, 2017 at 15:28
  • The 169.254 network is Class B and the above script will not work.
    – bstipe
    Commented Apr 26, 2017 at 17:13
  • This works for me, I already know the IP addresses, pi@RPi5:~ $ for x in 123 93 19; do for y in $(seq 110 165); do ping -c1 -W1 -I eth0 169.254.$x.$y | grep 'bytes from'; done; done 64 bytes from 169.254.123.117: icmp_seq=1 ttl=64 time=1.20 ms 64 bytes from 169.254.93.152: icmp_seq=1 ttl=64 time=0.655 ms 64 bytes from 169.254.19.160: icmp_seq=1 ttl=64 time=0.111 ms time, 3min. So with a little modification it would be possible to find the IP address. Example: time for x in $(seq 1 255); do for y in $(seq 1 254); do ping -c1 -W1 -I eth0 169.254.$x.$y | grep 'bytes from'; done; done
    – bstipe
    Commented Apr 26, 2017 at 19:04

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.