Configuring Network with Netplan on Ubuntu

Configuring your network settings can be a daunting task, but using the Netplan tool makes it much easier. In this article, we will go through the steps to configure your network settings using Netplan on Ubuntu.

Before starting, let’s identify all the interfaces on your system. We’ll use the following command:

sudo lshw -class network | grep name

This command will show you a list of all the network interfaces available on your system. Take note of the interface names, as we will be using them in our configuration file.

Next, let’s edit the Netplan configuration file. We’ll use the nano editor:

nano /etc/netplan/00-installer-config.yaml

In this file, we need to add a configuration section for each interface. Let’s say we’re configuring the ethernets interface with the name enp0s3.

Here’s an example configuration file that we’ll use as a starting point:

network:
  ethernets:
    enp0s3:
      dhcp4: false
      addresses: [192.168.1.2/24]
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4,192.168.1.1]
  version: 2

In this example, we’re:

  • Configuring the enp0s3 interface to use a fixed IP address of 192.168.1.2/24.
  • Disabling DHCP on this interface by setting dhcp4 to false.
  • Setting up the default route to use the gateway at IP address 192.168.1.1.
  • Configuring the DNS servers to use Google’s public DNS (8.8.8.8 and 8.8.4.4) and then the router’s IP.

You can adjust these settings according to your needs. Make sure you understand what each option does before making changes.

After editing the configuration file, we need to save it using nano:

Ctrl + O (save)
Ctrl + X (exit)

If you exit without saving the file, nano will prompt you to confirm whether you want to save the changes. In this case, simply press Y and then enter a filename for your configuration file.

Finally, we need to apply the new configuration using the following command:

sudo netplan apply

This will update your network settings with the new configuration.

If there are any errors during the application process, you can use the --debug option to see more detailed output:

sudo netplan --debug apply

That’s it! If everything goes smoothly, you should now have a configured network using Netplan.