I use a raspberry Pi 2. I have already installed raspbian and configured to a network using a usb-wifi a while back. Now I've moved to another place and I don't have an ethernet cable/ hdmi connectivity to a display. How can I connect it to a VNC without knowing its IP and without Pi being connected to any network.
4 Answers
Your Raspberry Pi must at least associated to a wifi network. Otherwise
it is not possible to connect to it. It is the same as if you haven't
plugged in an ethernet cable. You can the SD Card put into to a card
reader on a pc, mount its fat boot partition (the first partition) and
create a file called wpa_supplicant.conf with necessary information
for the new network in it. On first boot, this file is copied to
/etc/wpa_supplicant/wpa_supplicant.conf, overwriting any existing file
with the same name. When the raspi is associated to the network, then
you can scan for its ip address (given that there is a dhcp server) with
a network scanner from your pc also connected to the wifi. For example
with linux you can use nmap (don't know what scanners are available on
other operating systems):
pc ~$ sudo nmap -sn 192.168.1.0/24
Of course you have to know the ip address range of your network and use that. With the ip address of the raspi you can connect with VNC.
If you have access to the dhcp server you can look there, what ip address it has given to the raspi.
I have updated the answer with suggestion from the comment by @Jaromanda X.
- 42,961
- 20
- 87
- 207
It sounds like you're on your way to solving part of your problem by making the appropriate changes to /etc/wpa_supplicant/wpa_supplicant.conf. If you still need to know the IP address, you really don't need nmap at all. You can take advantage of the fact that all RPis have the same first three octets of their MAC address (the first 3 octets are known as the organizationally unique identifier (OUI), in this case the Raspberry Pi "organization"). Anyway... the value of these octets are: b8:27:eb. A compact shell script can ferret out the IP addresses you need:
#!/bin/sh
: ${1?"Usage: $0 ip subnet to scan. eg '192.168.1.'"}
subnet=$1
for addr in
seq 0 1 255; do ( ping -c 3 -t 5 $subnet$addr > /dev/null ) &done
arp -a | grep b8:27:eb
Copy this to a file (e.g. findpi.sh), make it executable (chmod 744 findpi.sh), and run it (./findpi.sh 192.168.1. - or whatever your network addr is)
EDIT (Jan 4, 2020): Due to the new OUI used for the Raspberry Pi 4B, the
arp command above could be changed to find any known (as of today) version of RPi:
arp -a | grep -E --ignore-case 'b8:27:eb|dc:a6:32'
- 23,558
- 5
- 42
- 83
If you have it actually connecting to wifi, and it is a local wifi network (not a large corporate one), Raspberry Pi's actually advertise via bonjero/zeroconf network as raspberrypi.local (or hostname.local if you've changed it).
This means that if you install a client for bonjour on your computer, you should be able to attempt (ssh, ping, network services) at raspberrypi.local without needing to know the IP address that this Pi has taken.
- 246
- 2
- 11
My hacking instincts tell me it might be possible to connect to the PI without taking out the SD card. If you know the network name and password that the PI usually connects to then you can setup a WiFi hotspot on your smartphone (or another PC if you have access to one) with these credentials to fool the PI to connect to your phone.
- 914
- 5
- 12