The Ubuntu 17.10 and later systems use the Netplan as a new command-line utility for managing network interfaces. It works with the Systemd-networkd or NetworkManager renderes. Netplan configuration files are written in YAML format, allowing you simple-to-complex networking configurations. Which work from the Desktop to the server and from the cloud to IoT devices.

This article will help you to configure static IPv4 addresses on Ubuntu systems using the Netplan command-line tool.

Check the Network Interface Name

First of all, you need to identify the network interface name. It can differ based on the installation type and system environment.

  • To find the interface name type:
    sudo nmcli device status 
    

    Output:

    DEVICE TYPE STATE CONNECTION eth0 ethernet connected Wired connection 1 lo loopback unmanaged --
  • You can also check the interface name using the ip command:
    sudo ip a 
    

    Configuring the Static IPv4 Address on Ubuntu using Netplan ip address Netplan Networking
    Checking the network interface name

The above output shows that the system is configured with the network interface name eth0. This can be different on your system. So please verify the system network interface name with the ip a command as shown above.

Configuring the Static IP Address using Netplan

Netplan stores all the configuration files under /etc/netplan directory. As you already have the network interface name found in the above commands. Now, we will configure the static IP address to that interface using the NetPlan utility.

Let’s, create a configuration file and edit in your favoite text editor:

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

Add the network configuration in YAML format. The below configuration uses 4 spaces due to strict indentation followed by the YAML.

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            addresses:
                - 192.168.0.210/24
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
            routes:
                - to: default
                  via: 192.168.0.254

In the above configuration:

  • eth0 – is the network interface name
  • 192.168.0.210/24 – is the IPv4 address to set on interface. Make sure to define CIDR. You can add multiple IP address as well.
  • routes via 192.168.0.254 – Set the gateway IP address of the network
  • 8.8.8.8, 8.8.4.4 – is the IP address of the Google DNS servers.

Make sure the IPv4 address belongs to the system network and has the correct gateway Ip address.

Once confirmed, press ESC and :wq to save file content and close it.

Now, execute the following command to apply the changes:

sudo netplan apply 

This will configure the static IPv4 address on the network interface. Now the system will be accessible with the new IP address you configured above.

Conclusion

In this tutorial, you have learned to configure the network interface on Ubuntu systems.