Network Configuration
Table of contents
- Introduction
- Default configuration
- Connecting to a Wi-Fi network
- Using a static IPv4
- Enabling IPv6 support
- References
Introduction
Network configuration in BerryOS is handle by cloud-init
with the help of netplan
inside the /boot/firmware/network-config
file.
We decided to use the version 2 networking config format as it is capable of configuring both the eth0
and wlan0
interface on the Raspberry Pi easily thanks to netplan
’s ability to configure systemd-networkd
renderer.
Default configuration
By default, BerryOS is configured to configure the eth0
interface using DHCP for IPv4 assignation by using the following configuration:
version: 2
ethernets:
eth0:
dhcp4: true
Connecting to a Wi-Fi network
To connect to a Wi-Fi network, we will need to update our network-config
file to include the necessary directive to enable the wlan0
interface.
version: 2
ethernets:
eth0:
dhcp4: true
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"My Access Point":
password: "AP Password"
From there you can specify the access point you want to by replacing "My Acess Point"
with the SSID of your Wi-Fi network. Be careful, the SSID must be enclosed in quotation marks. You should also replace "AP Password"
with the password of your network.
Password do not need to be set in plain text, they can also be set directly as WPA PSK. The PSK form of a password can be generated using the wpa_passphrase
utility on any system with wpa_supplicant
installed. This would look like this:
version: 2
ethernets:
eth0:
dhcp4: true
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"My Access Point":
password: 046ea35be8d6bd70480d233602146ff58aded1c2892d3aa67c5f6be635e8163f
Using a static IPv4
To use a static IPv4 instead of using DHCP for an interface, we need to disable the dhcp4
parameter and add the static network configuration we want using addresses
to set up the IP / netmask combo and routes
to set up the default route:
version: 2
ethernets:
eth0:
dhcp4: false
addresses:
- 192.168.1.128/24
routes:
- to: 0.0.0.0/0
via: 192.168.1.1
Enabling IPv6 support
In order to enable IPv6 support via DHCP for an interface, the dhcp6
parameter of said interface should be added and set to true. For example, to enable it for the eth0
interface, your configuration should look like:
version: 2
ethernets:
eth0:
dhcp4: true
dhcp6: true
Manual configuration can also be done by using the addresses
& routes
parameters:
version: 2
ethernets:
eth0:
dhcp4: false
dhcp6: false
addresses:
- 192.168.1.128/24
- 2001:cafe:face:beef::dead:dead/64
routes:
- to: 0.0.0.0/0
via: 192.168.1.1
- to: ::/0
via: 2001:cafe:face::1
References
Note
The
netplan
documentation shows that a default route can be configured with thedefault
alias as theto
target inroutes
. This does not work on BerryOS as it is not currently supported by thenetworkd
renderer, you must use the0.0.0.0/0
or::/0
form instead.