How to Configure Networking in Linux With Netplan

It's out with the old configuration steps and in with the new

What to Know

  • Get the network interface name, then edit the 01-netcfg.yaml file. Set dhcp4 to false.
  • Add entries for addresses, gateway, and DNS nameservers. Save the file using the keyboard combination Ctrl+X.
  •  Be consistent with your indenting, otherwise, Netplan will error when reading the file.

When Ubuntu Server 18.04 arrived, it has made changes to how admins work with the platform. One important change—one that might trip up experienced users—is how networking is configured. Gone is the old method of configuring networking in /etc/network/interfaces. To configure networking in the latest iteration, say hello to Netplan.

Configuring a Static IP Address With Netplan

Since we’re talking about a server installation, we want to configure the server for a static IP address. There is one thing you need to know about the Netplan YAML file. You must adhere to proper code indent for each line of the block. That doesn’t mean you must indent specific lines to a specific point. What it means is if you indent the first line of a block three spaces, you must indent the rest of the block three spaces. If you do not adhere to this, Netplan will error out.

Locating your network interface name with the ip a command

With that said, let’s configure.

  1. Before you make any changes, you need to know the name of the network interface. To do that, issue the command:

    ip a

    You should see the name of the network interface listed (such as ens5 or ens3). With that interface name in hand, you’re ready to configure.

  2. Out of the box, you’ll probably find a single YAML file in /etc/netplan. That file will be named either 01-netcfg.yaml or 50-cloud-init.yaml. You want to edit the 01-netcfg.yaml file. If it doesn’t exist, create it with the command:

    sudo touch 01-netcfg.yaml

    If the file does exist, edit it with the command:

    sudo nano 01-netcfg.yaml
  3. Your default file may look like this:

    version: 2
    renderer: networkd
    dhcp4: true

    The above configuration is set for DHCP. Because this is a server, you want to make use of a static IP address, so it never changes. You must edit everything below the ens5 line. The first thing to do is set dhcp4 to false, like so:

    dhcp4: false
    A Netplan YAML file to configure a static IP address
  4. Next, add entries for addresses, gateway, and DNS nameservers. For example, set the server to IP address, with a gateway of, and DNS servers of and Those entries are added below the dhcp4 entry and look like so:

    addresses: []
    addresses: [,]
  5. Remember, you must be consistent with your indenting, otherwise, Netplan will error when reading the file. Also, note that you do not set the netmask in the same fashion as was done via the interfaces file. Instead of an address and netmask being set like so:

    address =
    netmask =

    Both configurations are handled with the single line:

    addresses: []
  6. Save and close that file with the keyboard combination of Ctrl+x.

  7. After you save that file, you must make Netplan aware of the changes. To have Netplan reread and apply the configuration files, issue the command:

    sudo netplan apply
    Debugging the netplan command output
  8. You shouldn’t see any errors or output at all. If you do see errors, add the debug option, which gives you output as Netplan attempts to apply the configuration file like so:

    sudo netplan --debug apply

    Using the --debug option should give you enough information to help you troubleshoot your YAML file. If you receive no output, issue the command:

    ip a

    The output of the above command should reflect the changes you just made. Your server now has a static IP address, thanks to Netplan.

What Is Netplan?

Netplan is a utility for configuring networking on a Linux system, which uses YAML descriptions for each network interface found on a server or desktop.

How Does Netplan Work?

Netplan reads the YAML description files found within /etc/netplan. During the early booting stages of the operating system, Netplan will then generate (from the user-created YAML files) the necessary configuration files in the /run directory, so that control of each networking device is handed off to a particular networking daemon. In other words, you create a YAML description file for a network interface that Netplan can read and use to make that particular interface work.

Is It Complicated?

Don’t panic. Although network configuration on a Netplan-enabled server is vastly different than what it was in previous iterations, it’s not all that challenging. It is, however, specific. Let’s take a look at how to configure networking, via Netplan, on a Ubuntu Server 18.04 installation. As you might expect, configuring networking on a Linux server is typically done via the command line, so get ready to do a bit of typing.

Was this page helpful?