Software & AppsOperating SystemLinux

How To Enable Netplan on Ubuntu Server 18.04

Ubuntu 4

In this article, we will guide you through the process of enabling Netplan on your Ubuntu Server 18.04. Netplan is a utility for easily configuring networking on a Linux system. It allows you to configure your network interfaces using YAML files, which are more human-friendly and less error-prone than the traditional /etc/network/interfaces method.

Quick Answer

To enable Netplan on Ubuntu Server 18.04, you need to first check if it is already installed using the command sudo apt list --installed | grep netplan.io. If not installed, you can install it with sudo apt install netplan.io. Then, create a Netplan YAML configuration file in /etc/netplan/ and apply it using sudo netplan apply. Finally, remove the old network configuration files and verify the new configuration.

Preparations

Before we start, it is crucial to ensure that you have a way to access your server if the network goes down. Making changes to the network configuration can potentially disrupt your network connectivity. Therefore, having a backup access method, like a console access, is a good precaution.

Checking for Netplan Installation

Netplan should already be installed on Ubuntu 18.04, but we can verify it by running the following command:

sudo apt list --installed | grep netplan.io

This command lists all installed packages and filters the results for netplan.io. If it is not installed, you can install it using the following command:

sudo apt install netplan.io

Creating a Netplan Configuration File

The next step is to create a Netplan YAML configuration file according to your desired network setup. For this example, we will create a simple configuration that uses DHCP to automatically receive an IP address.

Create a new file using your preferred text editor, such as nano or vi:

sudo nano /etc/netplan/01-netcfg.yaml

Then, add the following content:

network:
 version: 2
 renderer: networkd
 ethernets:
 enp4s0:
 dhcp4: yes
 dhcp6: yes

In this configuration:

  • version: 2 specifies the version of the Netplan configuration syntax.
  • renderer: networkd tells Netplan to use the networkd backend. Networkd is a system service that manages networks. It detects and configures network devices as they appear.
  • ethernets: is a section that describes Ethernet devices.
  • enp4s0: is the name of the network interface that we want to configure. Replace this with the name of your network interface.
  • dhcp4: yes and dhcp6: yes enable DHCP for IPv4 and IPv6, respectively.

After you have entered the configuration, save and close the file.

Applying the Netplan Configuration

You can apply the new Netplan configuration by running the following command:

sudo netplan apply

This command will activate the new network configuration. If there are any syntax errors in the configuration file, Netplan will report them.

Removing the Old Network Configuration

After successfully applying the new Netplan configuration, you can remove the old network configuration files that are no longer needed. In Ubuntu 18.04, these are located in /etc/network/interfaces and /etc/network/interfaces.d/. You can remove them with the following commands:

sudo rm /etc/network/interfaces
sudo rm -r /etc/network/interfaces.d

Verifying the Network Configuration

To ensure that the new network configuration is working correctly, you can reboot your server:

sudo reboot

After the reboot, your network should be configured according to the Netplan YAML file you created. You can verify the network status using commands like networkctl, ip addr, or ifconfig.

Conclusion

Netplan offers a simple and flexible way to configure your network on Ubuntu Server 18.04. It uses human-friendly YAML files, which are easier to understand and less error-prone than the traditional method. With Netplan, you can easily manage your network configuration and adapt it to your needs.

For more information about Netplan, you can refer to the official Netplan documentation. If you encounter any issues or unexpected behavior, the Netplan FAQ provides further troubleshooting steps.

Can I use Netplan to configure wireless networks?

Yes, Netplan supports configuring wireless networks. You can specify the wireless network interface in the ethernets section of the Netplan YAML file and configure it accordingly. For example, you can set the SSID and password for a wireless network using the ssid and password options.

How can I configure a static IP address using Netplan?

To configure a static IP address, you can modify the Netplan YAML file by replacing the dhcp4: yes line with the following lines:

 addresses: [192.168.1.100/24]
 gateway4: 192.168.1.1
 nameservers:
 addresses: [8.8.8.8, 8.8.4.4]

Replace 192.168.1.100 with your desired static IP address, 192.168.1.1 with your gateway IP address, and 8.8.8.8 and 8.8.4.4 with your preferred DNS server addresses.

Can I configure multiple network interfaces using Netplan?

Yes, Netplan supports configuring multiple network interfaces. In the Netplan YAML file, you can add multiple sections under the ethernets section, each describing a different network interface. Make sure to give each interface a unique name (e.g., enp4s0 and enp5s0) and configure them accordingly.

How can I disable IPv6 using Netplan?

To disable IPv6, you can add the following line under the desired network interface in the Netplan YAML file:

 dhcp6: no

This will disable IPv6 for that specific interface. If you want to disable IPv6 globally, you can add the following line under the network section:

 renderer: networkd
 ethernets:
 # ...
 version: 2
 # Add the following line to disable IPv6 globally
 ethernets:
 version: 2
 renderer: networkd
 ethernets:
 enp4s0:
 # ...
 dhcp6: no
Can I configure VLANs using Netplan?

Yes, you can configure VLANs using Netplan. To configure a VLAN, you need to create a separate network interface for the VLAN and specify the parent interface it should be associated with. For example, to configure a VLAN with ID 10 on the enp4s0 interface, you can add the following lines to the Netplan YAML file:

 ethernets:
 enp4s0:
 # ...
 enp4s0.10:
 dhcp4: yes
 dhcp6: yes
 vlan-raw-device: enp4s0

This will create a VLAN interface named enp4s0.10 associated with the enp4s0 interface. Replace 10 with your desired VLAN ID.

How can I revert back to the traditional `/etc/network/interfaces` method?

If you want to revert back to the traditional method of configuring network interfaces using /etc/network/interfaces, you can uninstall Netplan by running the following command:

sudo apt purge netplan.io

After uninstalling Netplan, you can manually configure your network interfaces using the /etc/network/interfaces file. Remember to restart the networking service after making changes.

Leave a Comment

Your email address will not be published. Required fields are marked *