Legacy post. This article was written between 2016 and 2018. Software versions, commands and services mentioned here may be outdated. Check the official documentation before running anything.
The goal of this tutorial is to set up a Raspberry PI 3 from scratch.
- Prerequisites
- Installation
- Retrieve Raspberry PI 3
- Connect via SSH
- Set a static IP Address
- Enable Wifi
Prerequisites
- Components < 60 EUR:
| Component | Site | Price |
|---|---|---|
| Raspberry PI 3 | Farnell | 37.69 EUR |
| Power supply Micro USB 5V 2500mA | Amazon | 8.99 EUR |
| Micro SD Card (16 Go class 10) | Amazon | 9.99 EUR |
| Total: | 56.67 EUR |
Note: This is only an example. You can buy the components from other sites, and maybe at better prices.
Installation
- Download the latest version of Raspbian image
- Write the image to the SD card
Follow this guide according to your OS or follow this tutorial. Here are my commands on my Mac.
a. Retrieve the SD card mount point
diskutil list
Output:
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *500.1 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 499.2 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *15.9 GB disk2
1: Windows_FAT_32 NO NAME 15.9 GB disk2s1
Note: The SD card is mounted on “/dev/disk2 (external, physical)”
b. Format the SD Card
sudo diskutil eraseDisk FAT32 RASPBIAN MBRFormat /dev/disk2
Template:
diskutil eraseDisk {filesystem} {Name} MBRFormat /dev/{disk identifier}
Output:
Password:
Started erase on disk2
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk2s1 as MS-DOS (FAT32) with name RASPBIAN
512 bytes per physical sector
/dev/rdisk2s1: 31085888 sectors in 1942868 FAT32 clusters (8192 bytes/cluster)
bps=512 spc=16 res=32 nft=2 mid=0xf8 spt=32 hds=255 hid=2 drv=0x80 bsec=31116286 bspf=15179 rdcl=2 infs=1 bkbs=6
Mounting disk
Finished erase on disk2
c. Unmount the SD Card
diskutil unmountDisk /dev/disk2
Output:
Unmount of all volumes on disk2 was successful
d. Write image into the SD Card
sudo dd bs=1m if=/Users/<user>/Downloads/2017-03-02-raspbian-jessie.img of=/dev/disk2
template:
sudo dd bs=1m if={raspbian image path} of=/dev/{disk identifier}
Output:
4190+0 records in
4190+0 records out
4393533440 bytes transferred in 437.696112 secs (10037863 bytes/sec)
e. Enable SSH
To enable SSH, you only need to create a file called ssh in the /boot/ directory.
cd /Volumes/boot
touch ssh
See more here
f. Eject the SD Card
cd ..
diskutil eject /dev/disk2
Output:
Disk /dev/disk2 ejected
The SD card is now ready to use.
g. Plug an ethernet cable and switch on the power supply.
See more here
Now your Raspberry PI is ready! But how do I find it on my LAN?
Note: If you use a monitor, keyboard and mouse with your Raspberry, you can skip this part and go to “Set a static IP Address” section.
See more here
Retrieve Raspberry PI 3
1) Unplug the ethernet cable and run the nmap command
Follow this tutorial Example:
nmap -sn 192.168.0.0/24
Output
tarting Nmap 7.12 ( https://nmap.org ) at 2017-04-07 13:24 CEST
Nmap scan report for 192.168.0.10
Host is up (0.016s latency).
Nmap scan report for 192.168.0.12
Host is up (0.019s latency).
Nmap scan report for 192.168.0.14
Host is up (0.0040s latency).
Nmap scan report for 192.168.0.18
Host is up (0.0017s latency).
Nmap scan report for 192.168.0.20
Host is up (0.077s latency).
Nmap scan report for 192.168.0.254
Host is up (0.0075s latency).
Nmap done: 256 IP addresses (7 hosts up) scanned in 3.04 seconds
2) Plug in the ethernet cable and run the nmap command again Example:
nmap -sn 192.168.0.0/24
Output
tarting Nmap 7.12 ( https://nmap.org ) at 2017-04-07 13:24 CEST
Nmap scan report for 192.168.0.10
Host is up (0.016s latency).
Nmap scan report for 192.168.0.12
Host is up (0.019s latency).
Nmap scan report for 192.168.0.14
Host is up (0.0040s latency).
Nmap scan report for 192.168.0.18
Host is up (0.0025s latency).
Nmap scan report for 192.168.0.19
Host is up (0.0017s latency).
Nmap scan report for 192.168.0.20
Host is up (0.077s latency).
Nmap scan report for 192.168.0.254
Host is up (0.0075s latency).
Nmap done: 256 IP addresses (7 hosts up) scanned in 3.04 seconds
As we can see, a new IP address, 192.168.0.19, has appeared. It is your Raspberry PI.
Host is up (0.0025s latency).
Nmap scan report for 192.168.0.19
Connect via SSH
ssh pi@192.168.0.19
if you want to use X11
ssh -Y pi@192.168.0.19
Note:
Default username: pi
Default password: raspberry
Note: first, change your password with this command
passwd
output
Changing password for pi.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
See this post for Raspbian basic administration here
Update the Raspbian
sudo apt-get update && sudo apt-get upgrade
Set a static IP Address
sudo apt-get install vim
sudo vim /etc/network/interfaces
systemctl (start|stop) vncserver-x11-serviced.service
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.13
netmask 255.255.255.0
gateway 192.168.0.254
or set a permanent DHCP IP on your router
In my opinion, this is best practice.
Enable WIFI
a. Edit
sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
b. Adapt it to your security protocol
See specification wpa_supplicant.conf
Generate key
sudo wpa_passphrase "testing" "testingPassword" >> /etc/wpa_supplicant/wpa_supplicant.conf
Note: don’t forget to remove the comment with your clear password
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=FR
network={
ssid="<your-ssid>"
psk=<your-wpa-passphrase>
}
c. Edit
sudo vim /etc/network/interfaces
d. Set static IP and wpa-conf to wlan0
auto wlan0
iface wlan0 inet static
address 192.168.0.13
netmask 255.255.255.0
gateway 192.168.0.254
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Final config
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
# The loopback network interface
auto lo
iface lo inet loopback
# Ethernet
iface eth0 inet dhcp
# Wi-Fi
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.13
netmask 255.255.255.0
gateway 192.168.0.254
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
f. Check config
iw dev
phy#0
Interface wlan0
ifindex 3
wdev 0x1
addr xx:xx:xx:xx:xx:xx
ssid YOUR_NETWORK_SSID
type managed
g. Connection
ip link show wlan0
As we can see, wlan0 is currently DOWN
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state DOWN mode DORMANT group default qlen 1000
link/ether b8:27:eb:62:22:ca brd ff:ff:ff:ff:ff:ff
Start the interface
sudo ip link set wlan0 up
Check
ip link show wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DORMANT group default qlen 1000
link/ether b8:27:eb:62:22:ca brd ff:ff:ff:ff:ff:ff
h. Wait for network
sudo raspi-config
i. Reboot
You can now unplug the ethernet cable and reboot
sudo reboot
Great! Now you can access your Raspberry PI from anywhere on your LAN, with a static IP address over Wi-Fi or Ethernet.
Note: if you want to access your Raspberry from outside your LAN, you must forward a port on your router.
Useful links: