I suggest you set up /etc/network/interfaces something like:
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid <your_router>
wpa-psk <your_wpa_key>
dns-nameservers 8.8.8.8 192.168.1.1
Be sure to select a static address outside the range used by the DHCP server in the router, switch or other access point. Of course, substitute your details here.
Get the system to read and use the changes:
sudo ifdown wlan0 && sudo ifup -v wlan0
Did you connect?
ping -c3 192.168.1.1
ping -c3 www.google.com
The steps below were found to provide a persistent WiFi setup using netplan
with Ubuntu Server 18.04 ubuntu-18.04.2-preinstalled-server-arm64+raspi3.img.xz
image on a Raspberry Pi 3 B+.
Update system:
sudo apt update
sudo apt full-upgrade
sudo reboot
Determine interface names:
ip link show
# 1: lo: <LOOPBACK,UP,LOWER_UP> …
# 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> … state UP …
# 3: wlan0: <BROADCAST,MULTICAST> … state DOWN
Determine your-cloud-init.yaml and open for editing.
cd /etc/netplan/
ls -l
# -rw-r--r-- 1 root root 666 May 15 22:00 50-cloud-init.yaml
### note your *cloud-init.yaml file name
### backup *cloud-init.yaml file
cp 50-cloud-init.yaml 50-cloud-init.yaml.bak
### restrict read access
sudo chmod 640 /etc/netplan/50-cloud-init.yaml
### edit *cloud-init.yaml
sudo nano 50-cloud-init.yaml
Add WiFi access information to your-cloud-init.yaml file.
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
eth0:
optional: true
dhcp4: true
# add wifi setup information here ...
wifis:
wlan0:
optional: true
access-points:
"YOUR-SSID-NAME":
password: "YOUR-NETWORK-PASSWORD"
dhcp4: true
Test, generate and apply the changed your-cloud-init.yaml config:
- Testing:
sudo netplan --debug try
(continue even if successful)
- Generate:
sudo netplan --debug generate
(provides more details in case of issues with the previous command)
- Apply:
sudo netplan --debug apply
(if no issues during the previous commands)
Confirmation Test:
sudo reboot
### wait, then without the wired ethernet connected ...
ssh ubuntu@wifi-ip-address
The above sequence was distilled from the "Raspberry Pi 3B/B+ Wireless Bridge using Ubuntu Server 18.04 ARM Image and Netplan" gist link mentioned by Larnu. The gist goes well beyond just enabling WiFi since its turns the Pi into a Bridge.
Some additional useful WiFi setup steps.
Set hostname.
sudo hostnamectl set-hostname my-server-name
sudo nano /etc/hosts
127.0.0.1 localhost
# add host name
127.0.0.1 my-server-name
sudo nano /etc/cloud/cloud.cfg
# Set preserve_hostname to true for persistance after reboot
preserve_hostname: true
Verify from local Raspberry Pi commandline.
hostnamectl
# Static hostname: my-server-name
# Icon name: computer
# Machine ID: …
# Boot ID: …
# Operating System: Ubuntu 18.04.2 LTS
# Kernel: Linux 4.15.0-1036-raspi2
# Architecture: arm64
Enable mDNS.
If desired, enable Multicast DNS by installing Avahi. Avahi supports the mDNS/DNS-SD/RFC 3927/Zeroconf/Bonjour specification.
sudo apt install avahi-daemon
Remotely check mDNS resolution from another computer.
ping my-server-name.local
ssh ubuntu@my-server-name.local
Best Answer
For the image with apt installed
For the core image without apt installed: