I’m making this post again since the other one I made was long and confusing.

I have Ubuntu Server as a Linux distribution.

The Netplan approach is the official and recommended approach by Ubuntu, but Netplan doesn’t manage networking directly. Instead, it acts as a layer that reads your YAML configuration and then generates the necessary files for the networking backend of your choice. By default, on Ubuntu, that backend is systemd-networkd.

I had a bad experience with Netplan, it misconfigured my router.

Direct configuration in /etc/systemd/network/ is a perfectly valid alternative and is what many system administrators prefer for more precise control.

Both methods achieve the same goal, but the path to get there is different.

Both systemd-networkd and wpa_supplicant need to be restarted or reloaded to apply any changes you’ve made to their configuration files.

In order for it to recognize the new settings, you must instruct it to read the settings again.

restart systemd-networkd

sudo systemctl restart systemd-networkd
sudo systemctl reload systemd-networkd

restart service:

sudo systemctl restart wpa_supplicant

Here I will explain how to configure Wi-Fi with systemd-networkd (instead of Netplan)

With Netplan you will only configure a single file that has the Wi-Fi credentials, that is, all in one.

Otherwise you will configure 2 files, the network interface (systemd-networkd) and the wifi credentials (WPA_supplicant).

You won’t find any information about the Netplan method on this website, since it deconfigured my router.

Configuring Wi-Fi with systemd-networkd (instead of Netplan)

This method also requires two files:

  • One for the network interface
  • for the Wi-Fi credentials.

File for the Interface (.network)

This file tells systemd-networkd how to manage your adapter.

You should create a file with a descriptive name ending in .network.

example:

sudo vi /etc/systemd/network/25-wireless.network

number 25 is the order of priority

systemd-networkd loads configuration files from the /etc/systemd/network/ directory in alphabetical order. A lower number will be processed first.

content:

[Match]
Name=wlx68b9d3103445

[Network]
DHCP=yes
WPA_Supplicant=yes
# The WPA_Supplicant option tells systemd-networkd# that uses wpa_supplicant for connections
WPA_Supplicant=yes

wlx68b9d3103445 is the wifi network interface, you should know yours

To know which ones they are, you have the following command

ip a

or

ip address
  • The UP state means the interface is powered up and ready for use.
  • The NO-CARRIER state means the interface does not detect a physical or wireless connection.

Configure Wi-Fi credentials (in wpa_supplicant.conf)

location:

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

content:

ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YOUR NETWORK_NAME"
    psk="YOUR_PASSWORD"
}

replace YOUR NETWORK_NAME and YOUR_PASSWORD with your Wi-Fi credentials

What each file does

1)

/etc/wpa_supplicant/wpa_supplicant.conf

This file is like a list of passwords.

Its sole function is to store the credentials of the Wi-Fi networks you want to connect to, i.e., the network name (SSID) and the password (PSK).

The wpa_supplicant program reads this file to know which credentials to use to authenticate to the wireless access point.

2)

/etc/systemd/network/nn-xxxx.network

This file is the instruction manual for your network interface.

It tells the systemd-networkd service how your Wi-Fi adapter should behave.

Its purpose is not to store passwords, but rather to define the interface configuration itself.

Within this file, you tell the system:

Which interface to control:

  • The [Match] line tells it to apply to your adapter (Name=wlx…).
  • How to obtain an IP address: The line DHCP=yes tells you to obtain your IP address automatically.
  • How to authenticate: The line WPA_Supplicant=yes tells you that, for this interface, you should use the wpa_supplicant program to handle the wireless connection.

analogy:

  • The wpa_supplicant.conf file is your address book. It contains your friends’ phone numbers (their Wi-Fi SSIDs and passwords).
  • The 25-wireless.network file is your phone. It has the ability to make calls (configuring the network), and you’ve told it to look up the number in the address book (wpa_supplicant) when it needs to call a friend.
  • The systemd-networkd (the phone) doesn’t need to know the passwords, it just needs to know to query wpa_supplicant (the person who knows the passwords).