Setup wifi on RPI based on linux systemd distribution

Posted by Pierre Verkest on September 24, 2016

last update: 2020-07-18

You can find a documentation to setup wifi on raspberrypi.org however I much prefer the one from debian wiki

note (2019-07-18): A flash script is available to be able to install hypriot on your sd card and setup your wifi with cloud-init file.

First connect to a freshly installed RPI linux console I’m writting this blog post right after setup Hypriot on my RPI 3 I expect that works on systemd linux based operating system.

Note: You can also setting up this configuration while the sdcard is on your computer, detect your operating system mount point using lsblk:

pverkest@petrus-v:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 953,9G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 797,1G  0 part /
└─sda3   8:3    0 156,3G  0 part [SWAP]
sdb      8:16   1  14,9G  0 disk
├─sdb1   8:17   1    64M  0 part /media/usb0
└─sdb2   8:18   1  14,8G  0 part /media/usb1

WARNING: In that case the following explanation you should edit the file in /media/usb1/etc/network/interfaces.d/wlan0 instead /etc/network/interfaces.d/wlan0 otherwise you will change setting on your computer instead setting up the OS on the sdcard!

  • Generate encrypted wpa configuration
$ wpa_passphrase myssid Your_wifi_password

You should get something that looks like that:

network={
    ssid="myssid"
    #psk="Your_wifi_password"
    psk=encrypted_Your_wifi_password
}
  • Setup the wlan0 interface adding or editing this file /etc/network/interfaces.d/wlan0:
auto wlan0
iface wlan0 inet dhcp
    wpa-ssid The_ESSID
    wpa-psk encrypted_Your_wifi_password
  • auto: start the interface at startup
  • iface wlan0 inet dhcp: tell that the wlan0 interface should use dhcp
  • wpa-ssid: SSID of your box
  • wpa-psk: encrypted password generated by wpa_passphrase

if you want to manage a static address this should looks like:

auto wlan0

iface wlan0 inet static
    address 192.168.1.28
    netmask 255.255.255.0
    gateway 192.168.1.1
    wpa-ssid The_ESSID
    wpa-psk encrypted_Your_wifi_password
  • Then start the interface or reboot:
$ sudo ifup wlan0
# or reboot
$ sudo reboot
  • You can check the current configuratoin:
$ ip a s wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:ee:13:cb brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.28/24 brd 192.168.1.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:feee:13cb/64 scope link
       valid_lft forever preferred_lft forever

Note: If you manage to get multiple RPI on the same network you may want to change RPI hostname. HypriotOS (>1.7, before v1.7 it was using device-init project) set the hostname at boot time using /boot/user-data config file (more info on cloud-init project).

#cloud-config

# Set your hostname here, the manage_etc_hosts will update the hosts file entries as well
hostname: black-pearl
manage_etc_hosts: true