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 pi@raspberrypi.local . 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 pi@raspberrypi.local 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.

2 Answers2

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.

Jon Musselwhite
  • 794
  • 5
  • 17
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
bstipe
  • 574
  • 4
  • 6