Skip to main content
Simplified Systemd-Networkd setup
Source Link
Milliways
  • 61.4k
  • 32
  • 108
  • 212

SystemdNetworkd

SystemdNetworkd

Ethernet Networking

Ethernet Networking

Wireless Networking

Wireless Networking

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

Simplified Systemd-Networkd setup

Configuring networking using systemd-networkd requires multiple steps, and it is easy to get things wrong. The following 3 scripts simplify the process and enable swapping between systemd-networkd and dhcpcd.

The setup below is more general than that described above and should work with multiple interfaces (although if you have reason to have multiples you will probably want to customise the setup).

This should offer similar functionality to the dhcpcd setup (except this will disable the Networking tool on the Desktop Panel).

Step1 installs necessary files, and only needs to be run once. The other scripts activate/deactivate systemd-networkdbut do not delete anything merely changing which services are running - Reboot REQUIRED!
All script MUST be run by root or with sudo.

SetupSystemdNetworkd.sh

#! /bin/sh
# Script to install files for basic networking using systemd-networkd
# NOTE this does NOT swap networking systems - see separate scripts to activate
# 2022-06-24

# Assumes a working wpa_supplicant.conf file /etc/wpa_supplicant/wpa_supplicant.conf
# This script MUST be run by root or with sudo

# Create a network configuration for Ethernet
# Supports default eth0 or Predictable Network Interface Name en…
cat > /etc/systemd/network/02-eth.network <<EOF
[Match]
Name=e*

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201
EOF

# Create a network configuration for WiFi
# Supports default wlan0 or Predictable Network Interface Name wl…r
cat > /etc/systemd/network/03-wlan.network <<EOF
[Match]
Name=wl*

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301
EOF

# Copy existing wpa_supplicant.conf
cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

ActivateSystemdNetworkd.sh

#! /bin/sh
# Script to Activate networking using systemd-networkd
# This DeActivates dhcpcd and Debian networking
# 2022-06-24

# Assumes network configuration files and wpa_supplicant.conf file have been setup
# This script MUST be run by root or with sudo
# Reboot REQUIRED!

# Copy existing wpa_supplicant.conf
cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
systemctl enable systemd-networkd
systemctl disable dhcpcd
systemctl disable networking

systemctl enable systemd-resolved.service
systemctl disable wpa_supplicant.service
systemctl enable [email protected]

DeactivateSystemdNetworkd.sh

#! /bin/sh
# Script to DeActivates networking using systemd-networkd
# This Activates dhcpcd
# 2022-06-24

# This script MUST be run by root or with sudo
# Reboot REQUIRED!

# Copy existing wpa_supplicant.conf
cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
systemctl enable dhcpcd
systemctl disable systemd-networkd

systemctl enable wpa_supplicant.service
systemctl disable systemd-resolved.service
systemctl disable wpa_supplicant@wlan0.service

SystemdNetworkd

Ethernet Networking

Wireless Networking

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

SystemdNetworkd

Ethernet Networking

Wireless Networking

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

Simplified Systemd-Networkd setup

Configuring networking using systemd-networkd requires multiple steps, and it is easy to get things wrong. The following 3 scripts simplify the process and enable swapping between systemd-networkd and dhcpcd.

The setup below is more general than that described above and should work with multiple interfaces (although if you have reason to have multiples you will probably want to customise the setup).

This should offer similar functionality to the dhcpcd setup (except this will disable the Networking tool on the Desktop Panel).

Step1 installs necessary files, and only needs to be run once. The other scripts activate/deactivate systemd-networkdbut do not delete anything merely changing which services are running - Reboot REQUIRED!
All script MUST be run by root or with sudo.

SetupSystemdNetworkd.sh

#! /bin/sh
# Script to install files for basic networking using systemd-networkd
# NOTE this does NOT swap networking systems - see separate scripts to activate
# 2022-06-24

# Assumes a working wpa_supplicant.conf file /etc/wpa_supplicant/wpa_supplicant.conf
# This script MUST be run by root or with sudo

# Create a network configuration for Ethernet
# Supports default eth0 or Predictable Network Interface Name en…
cat > /etc/systemd/network/02-eth.network <<EOF
[Match]
Name=e*

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201
EOF

# Create a network configuration for WiFi
# Supports default wlan0 or Predictable Network Interface Name wl…r
cat > /etc/systemd/network/03-wlan.network <<EOF
[Match]
Name=wl*

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301
EOF

# Copy existing wpa_supplicant.conf
cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

ActivateSystemdNetworkd.sh

#! /bin/sh
# Script to Activate networking using systemd-networkd
# This DeActivates dhcpcd and Debian networking
# 2022-06-24

# Assumes network configuration files and wpa_supplicant.conf file have been setup
# This script MUST be run by root or with sudo
# Reboot REQUIRED!

# Copy existing wpa_supplicant.conf
cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
systemctl enable systemd-networkd
systemctl disable dhcpcd
systemctl disable networking

systemctl enable systemd-resolved.service
systemctl disable wpa_supplicant.service
systemctl enable [email protected]

DeactivateSystemdNetworkd.sh

#! /bin/sh
# Script to DeActivates networking using systemd-networkd
# This Activates dhcpcd
# 2022-06-24

# This script MUST be run by root or with sudo
# Reboot REQUIRED!

# Copy existing wpa_supplicant.conf
cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
systemctl enable dhcpcd
systemctl disable systemd-networkd

systemctl enable wpa_supplicant.service
systemctl disable systemd-resolved.service
systemctl disable wpa_supplicant@wlan0.service
added 4 characters in body
Source Link
Milliways
  • 61.4k
  • 32
  • 108
  • 212

SystemdNetworkd

Raspbian/Raspberry Pi OS initially used Debian Networking which was replaced by dhcpcd in 2015.
dhcpcd is the current default networking system.

Raspbian is now based on systemd which includes systemd-networkd, a system service that manages networks.
It detects and configures network devices as they appear, as well as creating virtual network devices.

This tutorial describes how to setup basic networking using systemd-networkd.
NOTE only basic networking using the in-built interfaces eth0 and wlan0 is described.

It is assumed you are familiar with networking and reasonably competent configuring Linux.It is assumed you are familiar with networking and reasonably competent configuring Linux.
It is NOT a method recommended for beginners; it is more complex to setup.
Each interface needs to be explicitly configured.

WARNING this will disable the Networking tool on the Desktop Panel.

Ethernet Networking

You need to define a network by creating a file in /etc/systemd/network. This can be given any name with the extension .network

The following example tells systemd-networkd to use eth0 (which is set up by udev) and assign it an address using DHCP.

[Match]
Name=eth0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201

An alternative using static IP Addresses

[Match]
Name=eth0

[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=192.168.1.1

[DHCP]
RouteMetric=201

Wireless Networking

In order to connect to a wireless network with systemd-networkd, a wireless adapter configured with another application such as WPA supplicant is required.
To use wlan0 You should create a suitable /etc/wpa_supplicant/wpa_supplicant-wlan0.conf e.g.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<2 letter ISO 3166-1 country code>

network={
    ssid="ESSID"
    psk="Your_wifi_password"
}

(If you have existing WiFi setup you can copy the file /etc/wpa_supplicant/wpa_supplicant.conf.)

Create a .network file in /etc/systemd/network.

[Match]
Name=wlan0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301

Having created the appropriate configuration files you NEED to disable existing networking and enable systemd-networkdservices.
NOTE there is NO NEED to purge existing network services. If disabled they will not interfere, and can be easily re-enabled if required.

sudo systemctl enable systemd-networkd
sudo systemctl disable dhcpcd
sudo systemctl disable networking

sudo systemctl enable systemd-resolved.service
sudo systemctl disable wpa_supplicant.service
sudo systemctl enable [email protected]

You can check the status using the following:-

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

References

  1. Debian Wiki
  2. The ArchLinux Wiki provides a comprehensive set of documentation.

SystemdNetworkd

Raspbian/Raspberry Pi OS initially used Debian Networking which was replaced by dhcpcd in 2015.
dhcpcd is the current default networking system.

Raspbian is now based on systemd which includes systemd-networkd, a system service that manages networks.
It detects and configures network devices as they appear, as well as creating virtual network devices.

This tutorial describes how to setup basic networking using systemd-networkd.
NOTE only basic networking using the in-built interfaces eth0 and wlan0 is described.

It is assumed you are familiar with networking and reasonably competent configuring Linux.
It is NOT a method recommended for beginners; it is more complex to setup.
Each interface needs to be explicitly configured.

WARNING this will disable the Networking tool on the Desktop Panel.

Ethernet Networking

You need to define a network by creating a file in /etc/systemd/network. This can be given any name with the extension .network

The following example tells systemd-networkd to use eth0 (which is set up by udev) and assign it an address using DHCP.

[Match]
Name=eth0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201

An alternative using static IP Addresses

[Match]
Name=eth0

[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=192.168.1.1

[DHCP]
RouteMetric=201

Wireless Networking

In order to connect to a wireless network with systemd-networkd, a wireless adapter configured with another application such as WPA supplicant is required.
To use wlan0 You should create a suitable /etc/wpa_supplicant/wpa_supplicant-wlan0.conf e.g.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<2 letter ISO 3166-1 country code>

network={
    ssid="ESSID"
    psk="Your_wifi_password"
}

(If you have existing WiFi setup you can copy the file /etc/wpa_supplicant/wpa_supplicant.conf.)

Create a .network file in /etc/systemd/network.

[Match]
Name=wlan0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301

Having created the appropriate configuration files you NEED to disable existing networking and enable systemd-networkdservices.
NOTE there is NO NEED to purge existing network services. If disabled they will not interfere, and can be easily re-enabled if required.

sudo systemctl enable systemd-networkd
sudo systemctl disable dhcpcd
sudo systemctl disable networking

sudo systemctl enable systemd-resolved.service
sudo systemctl disable wpa_supplicant.service
sudo systemctl enable [email protected]

You can check the status using the following:-

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

References

  1. Debian Wiki
  2. The ArchLinux Wiki provides a comprehensive set of documentation.

SystemdNetworkd

Raspbian/Raspberry Pi OS initially used Debian Networking which was replaced by dhcpcd in 2015.
dhcpcd is the current default networking system.

Raspbian is now based on systemd which includes systemd-networkd, a system service that manages networks.
It detects and configures network devices as they appear, as well as creating virtual network devices.

This tutorial describes how to setup basic networking using systemd-networkd.
NOTE only basic networking using the in-built interfaces eth0 and wlan0 is described.

It is assumed you are familiar with networking and reasonably competent configuring Linux.
It is NOT a method recommended for beginners; it is more complex to setup.
Each interface needs to be explicitly configured.

WARNING this will disable the Networking tool on the Desktop Panel.

Ethernet Networking

You need to define a network by creating a file in /etc/systemd/network. This can be given any name with the extension .network

The following example tells systemd-networkd to use eth0 (which is set up by udev) and assign it an address using DHCP.

[Match]
Name=eth0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201

An alternative using static IP Addresses

[Match]
Name=eth0

[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=192.168.1.1

[DHCP]
RouteMetric=201

Wireless Networking

In order to connect to a wireless network with systemd-networkd, a wireless adapter configured with another application such as WPA supplicant is required.
To use wlan0 You should create a suitable /etc/wpa_supplicant/wpa_supplicant-wlan0.conf e.g.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<2 letter ISO 3166-1 country code>

network={
    ssid="ESSID"
    psk="Your_wifi_password"
}

(If you have existing WiFi setup you can copy the file /etc/wpa_supplicant/wpa_supplicant.conf.)

Create a .network file in /etc/systemd/network.

[Match]
Name=wlan0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301

Having created the appropriate configuration files you NEED to disable existing networking and enable systemd-networkdservices.
NOTE there is NO NEED to purge existing network services. If disabled they will not interfere, and can be easily re-enabled if required.

sudo systemctl enable systemd-networkd
sudo systemctl disable dhcpcd
sudo systemctl disable networking

sudo systemctl enable systemd-resolved.service
sudo systemctl disable wpa_supplicant.service
sudo systemctl enable [email protected]

You can check the status using the following:-

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

References

  1. Debian Wiki
  2. The ArchLinux Wiki provides a comprehensive set of documentation.
drop dupe "enable networkd service" line (maybe it was supposed some other systemd service e.g. time-service?)
Source Link

SystemdNetworkd

Raspbian/Raspberry Pi OS initially used Debian Networking which was replaced by dhcpcd in 2015.
dhcpcd is the current default networking system.

Raspbian is now based on systemd which includes systemd-networkd, a system service that manages networks.
It detects and configures network devices as they appear, as well as creating virtual network devices.

This tutorial describes how to setup basic networking using systemd-networkd.
NOTE only basic networking using the in-built interfaces eth0 and wlan0 is described.

It is assumed you are familiar with networking and reasonably competent configuring Linux.
It is NOT a method recommended for beginners; it is more complex to setup.
Each interface needs to be explicitly configured.

WARNING this will disable the Networking tool on the Desktop Panel.

Ethernet Networking

You need to define a network by creating a file in /etc/systemd/network. This can be given any name with the extension .network

The following example tells systemd-networkd to use eth0 (which is set up by udev) and assign it an address using DHCP.

[Match]
Name=eth0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201

An alternative using static IP Addresses

[Match]
Name=eth0

[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=192.168.1.1

[DHCP]
RouteMetric=201

Wireless Networking

In order to connect to a wireless network with systemd-networkd, a wireless adapter configured with another application such as WPA supplicant is required.
To use wlan0 You should create a suitable /etc/wpa_supplicant/wpa_supplicant-wlan0.conf e.g.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<2 letter ISO 3166-1 country code>

network={
    ssid="ESSID"
    psk="Your_wifi_password"
}

(If you have existing WiFi setup you can copy the file /etc/wpa_supplicant/wpa_supplicant.conf.)

Create a .network file in /etc/systemd/network.

[Match]
Name=wlan0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301

Having created the appropriate configuration files you NEED to disable existing networking and enable systemd-networkdservices.
NOTE there is NO NEED to purge existing network services. If disabled they will not interfere, and can be easily re-enabled if required.

sudo systemctl enable systemd-networkd
sudo systemctl disable dhcpcd
sudo systemctl disable networking

sudo systemctl enable systemd-resolved.service
sudo systemctl enable systemd-resolved.service
sudo systemctl disable wpa_supplicant.service
sudo systemctl enable [email protected]

You can check the status using the following:-

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

References

  1. Debian Wiki
  2. The ArchLinux Wiki provides a comprehensive set of documentation.

SystemdNetworkd

Raspbian/Raspberry Pi OS initially used Debian Networking which was replaced by dhcpcd in 2015.
dhcpcd is the current default networking system.

Raspbian is now based on systemd which includes systemd-networkd, a system service that manages networks.
It detects and configures network devices as they appear, as well as creating virtual network devices.

This tutorial describes how to setup basic networking using systemd-networkd.
NOTE only basic networking using the in-built interfaces eth0 and wlan0 is described.

It is assumed you are familiar with networking and reasonably competent configuring Linux.
It is NOT a method recommended for beginners; it is more complex to setup.
Each interface needs to be explicitly configured.

WARNING this will disable the Networking tool on the Desktop Panel.

Ethernet Networking

You need to define a network by creating a file in /etc/systemd/network. This can be given any name with the extension .network

The following example tells systemd-networkd to use eth0 (which is set up by udev) and assign it an address using DHCP.

[Match]
Name=eth0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201

An alternative using static IP Addresses

[Match]
Name=eth0

[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=192.168.1.1

[DHCP]
RouteMetric=201

Wireless Networking

In order to connect to a wireless network with systemd-networkd, a wireless adapter configured with another application such as WPA supplicant is required.
To use wlan0 You should create a suitable /etc/wpa_supplicant/wpa_supplicant-wlan0.conf e.g.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<2 letter ISO 3166-1 country code>

network={
    ssid="ESSID"
    psk="Your_wifi_password"
}

(If you have existing WiFi setup you can copy the file /etc/wpa_supplicant/wpa_supplicant.conf.)

Create a .network file in /etc/systemd/network.

[Match]
Name=wlan0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301

Having created the appropriate configuration files you NEED to disable existing networking and enable systemd-networkdservices.
NOTE there is NO NEED to purge existing network services. If disabled they will not interfere, and can be easily re-enabled if required.

sudo systemctl enable systemd-networkd
sudo systemctl disable dhcpcd
sudo systemctl disable networking

sudo systemctl enable systemd-resolved.service
sudo systemctl enable systemd-resolved.service
sudo systemctl disable wpa_supplicant.service
sudo systemctl enable [email protected]

You can check the status using the following:-

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

References

  1. Debian Wiki
  2. The ArchLinux Wiki provides a comprehensive set of documentation.

SystemdNetworkd

Raspbian/Raspberry Pi OS initially used Debian Networking which was replaced by dhcpcd in 2015.
dhcpcd is the current default networking system.

Raspbian is now based on systemd which includes systemd-networkd, a system service that manages networks.
It detects and configures network devices as they appear, as well as creating virtual network devices.

This tutorial describes how to setup basic networking using systemd-networkd.
NOTE only basic networking using the in-built interfaces eth0 and wlan0 is described.

It is assumed you are familiar with networking and reasonably competent configuring Linux.
It is NOT a method recommended for beginners; it is more complex to setup.
Each interface needs to be explicitly configured.

WARNING this will disable the Networking tool on the Desktop Panel.

Ethernet Networking

You need to define a network by creating a file in /etc/systemd/network. This can be given any name with the extension .network

The following example tells systemd-networkd to use eth0 (which is set up by udev) and assign it an address using DHCP.

[Match]
Name=eth0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=201

An alternative using static IP Addresses

[Match]
Name=eth0

[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=192.168.1.1

[DHCP]
RouteMetric=201

Wireless Networking

In order to connect to a wireless network with systemd-networkd, a wireless adapter configured with another application such as WPA supplicant is required.
To use wlan0 You should create a suitable /etc/wpa_supplicant/wpa_supplicant-wlan0.conf e.g.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<2 letter ISO 3166-1 country code>

network={
    ssid="ESSID"
    psk="Your_wifi_password"
}

(If you have existing WiFi setup you can copy the file /etc/wpa_supplicant/wpa_supplicant.conf.)

Create a .network file in /etc/systemd/network.

[Match]
Name=wlan0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=301

Having created the appropriate configuration files you NEED to disable existing networking and enable systemd-networkdservices.
NOTE there is NO NEED to purge existing network services. If disabled they will not interfere, and can be easily re-enabled if required.

sudo systemctl enable systemd-networkd
sudo systemctl disable dhcpcd
sudo systemctl disable networking

sudo systemctl enable systemd-resolved.service
sudo systemctl disable wpa_supplicant.service
sudo systemctl enable [email protected]

You can check the status using the following:-

systemctl status systemd-networkd
systemctl status systemd-resolved.service
systemctl status wpa_supplicant.service
systemctl status [email protected]
systemctl status dbus.service

References

  1. Debian Wiki
  2. The ArchLinux Wiki provides a comprehensive set of documentation.
deleted 10 characters in body
Source Link
Milliways
  • 61.4k
  • 32
  • 108
  • 212
Loading
added 2 characters in body
Source Link
Milliways
  • 61.4k
  • 32
  • 108
  • 212
Loading
Source Link
Milliways
  • 61.4k
  • 32
  • 108
  • 212
Loading