-
1Download and install Raspbian Stretch image.
Download the image from: https://www.raspberrypi.org/downloads/.
Use whichever method you are more comfortable with - NOOBS or RASPBIAN - to install and load the image onto a MicroSD card.
In my case I am using Raspbian Stretch Lite. Downloaded and unzipped the image, and then used the Disks utility in Ubuntu Linux to restore the image onto the SD card.
-
2Enable Ethernet over USB emulation (Pi Zero W only).
This step is only applicable to Raspberry Pi Zero W, as Pi 3 does not have a USB OTG port.
Additionally, if you have a monitor and keyboard connected to your Pi Zero W, you can also skip this step.
Otherwise, with your SD card plugged into the PC, modify/create the following files:
a) Go to the boot partition, open the config.txt file and add the following at the very end:
dtoverlay=dwc2
b) Next, open the cmdline.txt file and add the following at the end of the line:
modules-load=dwc2,g_ether
c) Create an empty file called ssh.
-
3Log into the Raspberry Pi.
If you have a monitor and keyboard connected, simply log into the Pi with username pi and password raspberry.
Otherwise, if using Ethernet over USB emulation (Pi Zero W only), do the following:
a) Make sure Avahi/Bonjour service is running. If you are on Mac or Linux, it most likely is. On Windows, download and install iTunes - it comes bundled with Bonjour.
b) Connect the Pi to your PC via USB cable. Use the USB port labelled "USB" on the Pi (not the "PWR IN" one).
c) Open a terminal application in your PC and log into the Pi using ssh (use PuTTY or similar on Windows):
ssh pi@raspberrypi.local
Password is the same as above.
-
4Configure basic settings.
Execute raspi-config:
sudo raspi-config
a) Select option 1 and change your password.
b) Select option 4 and set your locale (I1), timezone (I2) and country (I4).
c) Reboot:
sudo reboot
d) Log back in (see step 3).
-
5Remove non-systemd networking packages.
To rid your system of "obsolete" :P networking packages, execute the following commands:
sudo apt remove --purge --auto-remove dhcpcd5 fake-hwclock ifupdown isc-dhcp-client isc-dhcp-common openresolv sudo killall wpa_supplicant sudo killall dhcpcd
-
6Configure systemd networking.
a) Use your editor of choice (nano or vi) to create config file for the usb0 interface, e.g.:
sudo nano /etc/systemd/network/10-usb0.network
and enter the following in it:
[Match] Name=usb0 [Network] LinkLocalAddressing=ipv4
This will enable Link Local Address, aka APIPA (Automatic Private IP Addressing) on usb0.
b) Create config file for the wlan0 interface, e.g.:
sudo nano /etc/systemd/network/10-wlan0.network
with the following contents:
[Match] Name=wlan0 [Network] DHCP=ipv4
This will enable DHCP on wlan0.
c) Create config file for the eth0 interface:
sudo nano /etc/systemd/network/10-eth0.network
with the following contents:
[Match] Name=eth0 [Network] DHCP=ipv4
This will enable DHCP address on eth0. If you want to use a static IP address instead, replace the last line with:
Address=192.168.1.100/24 Gateway=192.168.1.1
or whatever your address, netmask and gateway are.
-
7Enable systemd networking.
a) Enable network management service:
sudo systemctl enable systemd-networkd
b) Enable network name resolution (DNS) service:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf sudo systemctl enable systemd-resolved
c) Enable network time synchronization (NTP) service:
sudo systemctl enable systemd-timesyncd
d) Reboot:
sudo reboot
e) Log back in (see step 3)
f) Check if everything is working:
systemctl status systemd-networkd systemctl status systemd-resolved systemctl status systemd-timesyncd
-
8Connect your Raspberry Pi to the Internet.
If you've made it thus far... well done. :)
a) Create config file to connect to your wireless network with Internet access:
sudo nano /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
and enter the following in it:
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev update_config=0 country=US network={ ssid="name" psk="password" }
Replace the country code with the same one you've chosen in step 4.
Replace the name and the password with the name and password of your wireless network.
You can enter several network={ ... } sections with different SSIDs one after another. wpa_supplicant will automatically connect to the network that's currently in range. Who needs NetworkManager, right? o.O
b) Secure your wireless config file:
sudo chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
c) Enable and start wpa_supplicant on wlan0:
sudo systemctl enable wpa_supplicant@wlan0 sudo systemctl start wpa_supplicant@wlan0
d) Wait for it...
e) Wait for it...
f) OK, now check the status:
networkctl status wlan0
The wlan0 interface should be in configured state and have an IP address.
g) Try pinging something or someone, e.g.:
ping google.com
Ref: https://www.freebsd.org/cgi/man.cgi?wpa_supplicant.conf
-
9Update.
sudo apt update sudo apt dist-upgrade
-
10Switch to ssh.socket.
One of the cool things about systemd is socket-based activation of services, wherein services are started and stopped on demand.
sudo systemctl enable ssh.socket sudo systemctl start ssh.socket sudo systemctl disable ssh.service sudo systemctl stop ssh.service
If you are logged in via ssh, log out and back in:
exit ssh pi@raspberrypi.local
Ref: http://0pointer.de/blog/projects/socket-activation.html
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
why using hostapd when networkd can host an ap by itself ?
Are you sure? yes | no
In buster, hostapd does support systemctl natively... just name the config file `/etc/hostapd/ap0.conf`
Also make sure to set the locale in iw reg set and crda.
I got everything working... except the default route seems to be a dead end, maybe I need masquerade.
Got it fixed... ip forwarding was not enabled. Also used netfilter-persistent to make a masquerade rule `sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE`. For some reason the DNS server is not exposed or being given in DHCP. The routing is fine now... will bork this and start over.
Are you sure? yes | no
@simonlock sorry for the delay (I didn't get notified). Make sure you've created udev rule in step 12.a. I've just tried it on a fresh RPi4 and it works fine.
Are you sure? yes | no
A nice concise write up. Thanks. I've recently taken up systemd-networkd on my pi4 and your instructions nicely summarised how to set this up. However, regarding your setup of a virtual ap (step d) for hostapd failed for me.
networkctl status ap0
returns:
Failed to request link: No such device
Perhaps you possibly suggest what might have since changed or what I might have done wrong? Thanks in advance.
Are you sure? yes | no