Configuring Network Interfaces in Ubuntu with Netplan

Configuring network interfaces in Ubuntu is essential for connecting to networks and accessing the internet. With the introduction of Netplan, managing network configurations has become more streamlined and efficient. In this blog post, we'll explore how to set up and configure network interfaces using Netplan on Ubuntu.


What is Netplan?

Netplan is a utility for configuring networking on Linux systems, particularly on Ubuntu. It provides a YAML-based configuration format that allows users to define network interfaces, addresses, routes, and other networking parameters in a simple and structured manner.


Getting Started:

Before diving into Netplan configurations, it's essential to understand the basic concepts involved:


1. YAML Syntax: Netplan configurations are written in YAML (YAML Ain't Markup Language), which is a human-readable data serialization format. YAML uses indentation to represent hierarchical data structures, making it easy to read and write.


2. Networkd Renderer: Netplan uses the networkd renderer to apply network configurations. Networkd is a systemd service responsible for network configuration and management. It provides a reliable and efficient way to handle networking tasks.


Configuration Example:

Let's walk through an example of configuring a network interface with a static IP address using Netplan.


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


network:

  version: 2

  renderer: networkd

  ethernets:

    eth0:

      addresses:

        - 192.168.1.10/24

      routes:

        - to: 0.0.0.0/0

          via: 192.168.1.1

      nameservers:

        addresses: [8.8.8.8, 8.8.4.4]


Explanation:

→ version : Specifies the Netplan configuration version.

→ renderer : Specifies the renderer to use (networkd in this case).

→ ethernets : Defines network interface configurations.

→ eth0 : Interface name.

→ addresses : Assigns the IP address and subnet mask to the interface.

→ gateway4 : Specifies the default gateway.

→ nameservers : Sets the DNS server addresses.


Applying the Configuration:

Once the Netplan configuration is defined, you can apply it using the `netplan apply` command. This command applies the configuration changes and activates the network interfaces accordingly.


Conclusion:

Configuring network interfaces in Ubuntu using Netplan offers a straightforward and efficient way to manage networking settings. By utilizing YAML-based configurations and the networkd renderer, users can define network parameters with ease and ensure reliable connectivity. Whether setting up static IP addresses, configuring routes, or defining DNS servers, Netplan simplifies the process while providing flexibility and scalability.


With Netplan, managing network configurations on Ubuntu has never been easier, empowering users to efficiently connect to networks and access the internet with confidence.


In summary, Netplan streamlines the network configuration process on Ubuntu, offering a robust solution for managing networking settings effectively.