Configure Netplan in Linux

12 February 2025

Linux, CLI, Networking

Netplan is a network configuration utility commonly used in Debian-based distros such as Ubuntu.

It uses the YAML syntax for managing network configurations.

Our Desired Configuration

How to Apply it

  1. cd /etc/netplan
  2. sudo nano 01-netcfg.yaml
    • The 01 specifies the priority i.e. the default 50-cloud-init will be ignored when we create 01-netcfg.yaml
  3. sudo netplan apply

Contents of 01-netcfg.yaml:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: false
      dhcp6: false
      addresses:
      - 192.168.1.10/24
      routes:
      - to: default
        via: 192.168.1.1
      nameservers:
       addresses: [1.1.1.1, 1.0.0.1]

Be sure to change the interface from ens33 if yours is different.

You can check your interface and also see if your Netplan has been applied successfully by running the ifconfig or ip a command.