I really wanted to avoid using Netplan, but it worked for me.
I have Linux as my operating system, the Ubuntu Server distribution (it doesn’t have a graphical interface like Ubuntu Desktop which has GNOME as its desktop environment, it’s just a terminal and has no desktop interface).
I base this on the following post, read it to understand this:
You provide a simple blueprint of what you want (a YAML file), and Netplan translates that blueprint into instructions that a network engine (the builder) can understand. This prevents errors and makes network configuration easier to manage.
The renderer is the engine that executes the instructions Netplan gives it. If Netplan is the architect, the renderer is the builder who actually builds the walls and connects the cables.
You must use the renderer in the configuration file. The two most common are:
- systemd-networkd: This is the default renderer in Ubuntu Server installations. It’s ideal for stable, fixed network configurations, such as on servers, where the connection doesn’t change.
- NetworkManager: This is the default renderer in Ubuntu Desktop installations. It’s designed to manage dynamic network connections, such as Wi-Fi or mobile networks, where you need to change networks frequently.
Netplan allows you to configure your network simply with a single file, delegating the heavy lifting of connection and configuration to your chosen renderer.
The relationship between the Netplan configuration file and the systemd-networkd renderer is one of abstraction and translation. Netplan is the upper layer that simplifies configuration, and systemd-networkd is the lower-level engine that actually executes the instructions.
The Netplan .yaml file is a declarative plan. You simply declare what you want the final state of your network to be, without specifying any commands or low-level syntax.
When you run the sudo netplan apply command, Netplan takes your .yaml file and translates it into the configuration files that systemd-networkd needs to work.
- Netplan does not edit any systemd-networkd configuration files you may have in /etc/systemd/network/.
- Instead, it generates new files with the systemd-networkd syntax and places them in the temporary directory /run/systemd/network/.
Once Netplan has generated these files, systemd-networkd takes action. The systemd-networkd.service service wakes up and reads the Netplan-generated files from /run/systemd/network/.
- Netplan is the high-level configuration front-end.
- systemd-networkd is the low-level back-end.
- The sudo netplan apply command is the bridge that translates the high-level configuration into the instructions the low-level engine needs.
- Files generated by Netplan in /run/ take precedence over any manual configuration you may have in /etc/. This ensures that your Netplan configuration is always applied without conflict.
you must create a .yaml file located in /etc/netplan/
sintaxis: priority-name.yaml
example:
/etc/netplan/01-netcfg.yaml
content:
network:
version: 2
renderer: networkd
ethernets:
enp2:
dhcp4: true
wifis:
wlxbcec2304ec:
dhcp4: true
access-points:
"WIFI_NAME":
password: "PASS_WIFI"
- network: This is the primary key for the file. It indicates that everything after it is the network configuration. It’s the starting point for defining network interfaces (Ethernet and Wi-Fi) and their properties.
- version: 2 Specifies the version of the Netplan configuration format being used. In this case, version: 2 is the current and recommended version. This is important because it ensures that the software interpreting the file (the “renderer,” such as networkd or NetworkManager) reads and interprets it correctly. If the syntax changes in future versions, the system will know which rules to apply to this specific file.
- enp2 is the Ethernet cable network interface and wlxbcec2304ec is the Wi-Fi network interface.
- wifis: This section tells Netplan that you are going to configure one or more wireless interfaces.
- wlxbcec2304ec: This is the name of your Wi-Fi interface.
- dhcp4:true: Tells the interface to obtain its IP, gateway, and DNS address automatically via DHCP.
- access-points: This is where you define the list of networks you want to connect to.
- “WIFI_NAME”: This is the name of your network (SSID)(Service Set Identifier). It is enclosed in quotation marks.
- password: “PASS_WIFI”: This is your network password.
- The file tells the system to activate the Ethernet and Wi-Fi network interfaces, to use DHCP to obtain their network settings, and for Wi-Fi, to connect to the network called “WIFI_NAME” using the password “PASS_WIFI”
When you finish you must apply the changes without any warning:
sudo netplan apply
You will create the necessary link between systemd-networkd and wpa_supplicant, allowing your system to authenticate and connect successfully to the Wi-Fi network.
This causes Netplan to read your file, generate the low-level configuration files, and configure the network according to your instructions.
This will cause Netplan to generate the necessary configuration files for systemd-networkd and connect to your Wi-Fi network.
Check the systemd-networkd configuration: Although Netplan is the top layer, it is useful to check if the problem is with Netplan or the “engine” it uses.
Make sure the Netplan renderer is systemd-networkd, as you’re assuming that’s what’s being used for the configuration. If the renderer were NetworkManager, the Wi-Fi configuration would be slightly different.
networkctl
This command will show you the status of all your network interfaces. Check if the Wi-Fi interface is in the “routable” state or if it has an assigned IP address (DHCP4.Address).
Make sure the Netplan renderer is systemd-networkd, as you’re assuming that’s what’s being used for the configuration. If the renderer were NetworkManager, the Wi-Fi configuration would be slightly different.
The hierarchy is clear:
Netplan > systemd-networkd > wpa_supplicant
- If Netplan has a configuration file for an interface, it will always take precedence.
- If Netplan doesn’t have a file for that interface, then systemd-networkd will look for its own configuration files.
- For Wi-Fi, systemd-networkd can’t do it alone; that’s why it invokes and uses wpa_supplicant.
The correct way to connect to the internet on Ubuntu Server is through Netplan,
which then passes the work to systemd-networkd. For Wi-Fi, systemd-networkd outsources the work to the specialist wpa_supplicant.
if it says permissions for /etc/netplan/01-netcfg.yaml are too open
Make sure the file has the correct permissions
This is a security warning.
It indicates that your network configuration file, 01-netcfg.yaml, can be read or modified by non-root users.
sudo chmod 600 /etc/netplan/01-netcfg.yaml
If your internet doesn’t work, here are some alternatives:
You must do this before using Netplan
There may be a network interface that does not exist, in the cache yes, i.e. in the temporary files. (a network interface that was connected to the PC in the past and is now not).
if there is something in persistent memory or a low-level configuration file that has not been removed.
This stops the network managers so you can clean up the configuration files without conflicts.
sudo systemctl stop systemd-networkd.service
sudo systemctl stop wpa_supplicant.service
Find and delete any .network files that use the wrong name
sudo rm /etc/systemd/network/*.network
sudo rm /run/netplan/*
sudo rm -rf /etc/netplan/*
sudo rm -rf /run/netplan/*
sudo rm -rf /etc/systemd/network/*wlx*
sudo rm -rf /var/lib/systemd/network/*
stop services
sudo systemctl stop systemd-networkd.service
sudo systemctl stop systemd-resolved.service
sudo systemctl stop wpa_supplicant.service