Introduction:
What is Netplan?
Netplan is a YAML-based network configuration utility that is used to configure network interfaces on Ubuntu systems. It is also a network configuration abstraction for various backends. It is designed to be more user-friendly and easier to configure than the traditional ifupdown method. Netplan was introduced in Ubuntu 17.10 as a replacement for ifupdown.
Netplan uses a YAML-based configuration file to define network interfaces, IP addresses, and routes. It is designed to be simple, easy to use, and flexible, allowing administrators to configure their network settings with ease.
Netplan vs. Debian Linux:
Netplan is very similar to Debian Linux, Debian Linux uses the traditional ifupdown method to configure network interfaces, which is under /etc/network/interfaces, and Ubuntu Netplan is under /etc/netplan/*, compare the Debian Linux, and Ubuntu it has a couple of fewer commands to do.
Netplan, on the other hand, uses a YAML-based configuration file that is easy to read and understand. It also has a lot of built-in features, such as support for multiple network interfaces, VLANs, and bridges, which makes it a more powerful tool for network administrators.
Configuring Netplan:
To configure Netplan on Ubuntu Server 22.04, follow these steps:
Step 1: Install Netplan
Netplan is pre-installed on Ubuntu Server 22.04. However, if it is not installed, you can install it using the following command:
sudo apt-get install netplan.io
Step 2: Create a Netplan configuration file
Netplan configuration files are stored in the /etc/netplan directory. The default should be:
sudo nano /etc/netplan/00-installer-config.yaml
To create a new Netplan configuration file, eg: static IP address configuration, run the following command:
sudo nano /etc/netplan/01-static_cfg.yaml
Step 3: Configure network interfaces
In the Netplan configuration file, you can define network interfaces, IP addresses, and routes. For example, to configure a network interface with a static IP address, you can use the following configuration:
Note: If you use the gateway4 will get you a couple of warning such as WARNING **: 10:34:11.815: gateway4 has been deprecated, use default routes instead. The routes isn’t new, in fact, you could use this same method back in Ubuntu 20.04 version.
network:
version: 2
renderer: networkd
ethernets:
# interface name
eth0:
dhcp4: false
# IP address/subnet mask
addresses:
- 192.168.1.100/24
nameservers:
# DNS search base
search: [mydomain, otherdomain]
# name server
addresses: [1.1.1.1, 1.0.0.1]
# default gateway
# [metric] : set priority (specify it if multiple NICs are set)
# lower value is higher priority
routes:
- to: default
via: 192.168.1.1
In this example, we have defined a network interface called eth0 with a static IP address of 192.168.1.100 and a netmask of 24. We have also defined a default gateway and DNS servers.
Step 4: Apply the Netplan configuration
Once you have configured the Netplan configuration file, you need to apply the changes using the following command:
sudo netplan apply
Configure Netplan to Use the Network Manager as Renderer:
Step 1: Install Network Manager and Configuration:
If Network Manager is not installed, you can install it using the following command:
#network-manager: before Ubuntu V21.10
#NetworkManager: after Ubuntu V21.10 and Arch Linux
sudo apt-get install network-manager
Note: If you connect to SSH make sure you configure the NetworkManager IP address and everything else as the same before proceeding, the SSH connection will continue working without interruption.
To configure the address, we need to tell the Network manager to manage all the devices:
sudo touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
If you want, add the following content:
[keyfile]
unmanaged-devices=none
Or:
And or modify /etc/NetworkManager/NetworkManager.conf contains:
[main]
plugins=ifupdown,keyfile
[ifupdown]
managed=true
Restart NetworkManager:
sudo systemctl restart networkmanager
Check your interface is now being managed by NetworkManager with nmcli device status command, otherwise, use nmtui command to configure your IP address or static IP address.
Step 2: Change the Netplan configuration file:
Github user M00NL16H7 created a script that you can run
Invalid GitHub repository path: /M00NL16H7/randomScripts
#!/usr/bin/env bash
# netplan2NM.sh
# Ubuntu server 20.04 Change from netplan to NetworkManager for all interfaces
# it was orignally for that anyways. I updated this so that it can *hopefully* be used in 22.04 LTS
# works as of 2/22/23 (nice)
echo 'Changing netplan to NetowrkManager on all interfaces'
# backup existing yaml file
cd /etc/netplan
cp 00-installer-config.yaml 00-installer-config.yaml.BAK
# re-write the yaml file
cat << EOF >> /etc/netplan/00-installer-config.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: NetworkManager
EOF
# setup netplan for NM
netplan generate
netplan apply
# make sure NM is running
systemctl enable NetworkManager.service
systemctl restart NetworkManager.service
echo 'Done!'
Once you specify the renderer as NetworkManager you're done with all .yaml files and all normal NetworkManager commands can be used.
Next, you may want to disable the systemd-networkd service:
sudo systemctl stop systemd-networkd.service
sudo systemctl disable systemd-networkd.service
sudo systemctl mask systemd-networkd.service
If you want the using systemd-networkd again, simply reverse the operation:
sudo systemctl unmask systemd-networkd.service
sudo systemctl enable systemd-networkd.service
sudo systemctl start systemd-networkd.service
Configuring NetworkManager to ignore certain devices (Optional)
If you prefer to use Network Manager to configure some devices and still want to use Netplan to manage some other devices, you can do so by following these steps:
Note: This configuration assumes you do not follow the "Netplan to Use the Network Manager as Renderer" above configuration, but you have installed networkmanager and Netplan renderer is networkd
Step 1: Configure Network Manager
To configure Network Manager and Netplan to work, you need to edit the configuration file in the /etc/NetworkManager/NetworkManager.conf file or create a file under conf.d directory.
For example, create a file called 10-globally-managed-devices.conf with the following content:
[keyfile]
unmanaged-devices=interface-name:eth*
This configuration tells Network Manager to manage all network devices except for those with interface names starting with "eth", or specify the device name such as eth0, enp0s25, etc.
Verification:
nmcli device status
Step 2: Restart Network Manager
Once you have configured Network Manager, you need to restart it using the following command:
sudo systemctl restart Network-Manager
Confirmation:
After the above all configuration is complete, to confirm the settings, run the following command:
ip addr show eth0
To do this, open the Network Manager GUI by clicking on the network icon in the system tray and selecting "Network Settings". From here, you can add, edit, and remove network interfaces.
Conclusion:
When using Ubuntu is recommended just use Netplan to do the configuration, unless you have some special requirements that need to use the network manager.
Netplan is a powerful tool for configuring network interfaces on Ubuntu systems. It is designed to be user-friendly and easy to configure, making it a great choice for both new and experienced users.
With Netplan and Network Manager, network administrators, and system administrators have the tools they need to manage and configure their network settings with ease.
Reference:
https://ubuntu.com/core/docs/networkmanager/networkmanager-and-netplan


Comments 4 comments
Hi, please use this command: sudo apt-get install network-manager
@Zach Fixed, thanks!
Also, dhcp4-overrides is good option to use sometime! 😊
Network Configuration
And the command with
resolvectl status