For those of you using Ubuntu 18.04 & above, you might have noticed that the way we used to add the static IP address in Ubuntu does not work. Or how do I add multiple IP addresses to single interface or to configure another network interface on Ubuntu? So how do I manage network in Ubuntu ???

That’s what we will discuss in this article, we can manage network in Ubuntu using the new tool, NETPLAN command. Netplan is used together with renderers i.e. Networkd & with NetworkManager. Netplan uses YAML files to configure the network on Ubuntu.

So netplan reads network files from ‘/etc/netplan/’ folder, I have seen different files names under this folder. Most of the time, it’s ‘01-netcfg.yaml’ but in one of my systems, its ‘50-cloud-init.yaml’ or it can also be ‘config.yaml’. We can update the file to make changes to the network. But if you don’t find any file inside this folder then you can run the following command to create a new config file,

$ sudo netplan generate

Recommended Read: Managing network connections using IFCONFIG & NMCLI commands

Also Read: Surf anonymously: Learn to install TOR network on Linux

Now let’s discuss some other examples to help us manage the network in Ubuntu 18.04 & above.


1- Assign IP address using DHCP

Open the configuration file & make the following changes,

$ sudo vi /etc/netplan/config.yaml

network:

   version: 2

    renderer: networkd

    ethernets:

       enp3s0:

         dhcp4: true

Here, we can change the renderer to NetworkManager instead of networkd as well,

network:

   version: 2

   renderer: NetworkManager

   ethernets:

      enp3s0:

         dhcp4: true

Now save the file & to apply the changes, run the following command,

$ sudo netplan apply

Now, we can check the IP address, it will be now assigned using DHCP.


2- Assign a static IP address in Ubuntu

To assign a static IP address, open the file & make the following changes,

$ sudo vi /etc/netplan/config.yaml

network:

   version: 2

   renderer: networkd

   ethernets:

      enp3s0:

         addresses:

            - 10.10.1.2/24

         gateway4: 10.10.1.1

         nameservers:

            addresses: [8.8.8.8, 1.1.1.1]

Save & apply changes using the following command,

$ sudo netplan apply


3- Assign multiple IP addresses to a single interface

Open the file & make the following changes,

$ vi /etc/netplan/config.yaml

network:

   version: 2

   renderer: networkd

   ethernets:

      enp3s0:

         addresses:

            - 10.10.1.2/24

            - 10.10.1.3/24

         gateway4: 10.10.1.1

         nameservers:

            addresses: [8.8.8.8, 1.1.1.1]


4- Configuring multiple Interfaces with DHCP address

We need not create a 2nd file for another interface, we can add the configuration for the new interface in the same configuration file. To configure 2 network interfaces with DHCP, add the following configuration,

network:

   version: 2

   renderer: networkd

   ethernets:

      enp3s0:

         dhcp4: true

 

      enp3s8:

         dhcp4: true

Save the file & apply the changes using the below-mentioned command,

$ sudo netplan apply

Now we have 2 network interfaces, both with DHCP configured.


5- Configuring multiple interfaces with static IP addresses

To add more than one network interfaces with static IP addresses, add the following configuration,

$ sudo vi /etc/netplan/config.yaml

network:

   version: 2

   renderer: networkd

   ethernets:

      enp3s0:

         addresses:

            - 10.10.1.2/24

         gateway4: 10.10.1.1

         nameservers:

            addresses: [8.8.8.8, 1.1.1.1]

      enp3s8:

         addresses:

            - 10.10.1.3/24

         gateway4: 10.10.1.1

         nameservers:

            addresses: [8.8.8.8, 1.1.1.1]

Now save the file & exit. Apply changes with the following command,

$ sudo netplan apply

These were only some of the commands to manage network in Ubuntu. We can not only assign static IP address in Ubuntu using netplan but we can perform other advanced operations as well using netplan. To get the complete idea of what netplan can do, you can refer to the official documentation as well HERE.

This complete our tutorial, please send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.