How to use onboard wifi on Raspberry Pi 3 with Ubuntu Server 16.04?

For the image with apt installed

OS: Ubuntu 16.04.1 LTS  OS 
image: ubuntu-16.04-preinstalled-server-armhf+raspi3.img
HW: RASPBERRY PI 3 MODEL B

Step1:

sudo apt-get install wireless-tools

Step2:

sudo apt-get install wpasupplicant

Step3: add to /etc/network/interfaces:

auto wlan0 
iface wlan0 inet dhcp
wpa-ssid WIRELESSSSID 
wpa-psk WIRELESSPASSWORD

Step4: comment from /etc/network/interfaces the line:

#source /etc/network/interfaces.d/*.cfg

the commented interfaces.d/*.cfg file contains settings for the eth0.

I do not understand why but leaving this line active and adding the wlan0 config would crash the system at boot.

Step5: reboot

For the core image without apt installed:

OS: Ubuntu Core 16 
image: (GNU/Linux 4.4.0-1030-raspi2 armv7l)
HW: RASPBERRY PI 3 MODEL B

Step1:

ifconfig wlan0 down
ifconfig wlan0 up

Step2: create wireless config file:

sudo vi /etc/network/interfaces.d/wlan0

Note: I tried without sudo but it would not let me save the changes

Step3: add the following content

auto wlan0 
iface wlan0 inet dhcp
wpa-ssid WIRELESSSSID 
wpa-psk WIRELESSPASSWORD

Step4: reboot


This is my config (slightly different to the others as I use wpa_supplicant.conf)

In /etc/network/interfaces I have:

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

where the file /etc/wpa_supplicant/wpa_supplicant.conf contains the following:

country=GB

network={
    ssid="MyWifiNetwork"
    psk="myP4ssw0rd"
}

I did iwconfig command and from there the messages came that dependicies needed to be updated and after that I could install the wireless-tools.

sudo apt-get -f install
sudo apt-get -f install wireless-tools

after these commands I was able to iwconfig.

Hope this helps!