How to Enable and Disable Network Interfaces in Ubuntu 20.04

Whenever we operate as an Ubuntu admin, we are responsible for managing the system's network settings. When you make modifications to the Network card on some kind of Linux system, the connection goes down. The network interfaces seem to be either practically or virtually existent, and you may simply activate them using one of the ways. In this tutorial, we'll go through how to activate, and deactivate network interfaces within Ubuntu using several techniques. All instructions were run on Ubuntu 20.04 LTS, the most recent Ubuntu release. Let's get started with the specifics!

First, of very all, you need to install the network tools in your Ubuntu 20/04 Linux system, if not already been installed. Hence, try the below apt install query in the shell and hit Enter key to execute it. Add the user password to carry on the installation process.

$ sudo apt install net-tools

Install net-tools in Ubuntu

Control network interfaces using ifconfig command

Now the Network tools have been installed, we have to get information regarding our existing network interfaces that are built-in in our system. For this purpose, we have an “ip” command that can show the data regarding the network interface. Therefore, execute the “ip” command in the shell followed by variable “a” and press Enter.

$ ip a

ip a

You can have a look at the interface shown in the above image e.g. enp0s3. The interface is up and active right now. To disable it, we will use the “ifconfig” command in the shell followed by the interface name and state to be applied. Hence, we have mentioned the state as “down” in the below command.

$ sudo ifconfig enp0s3 down

Disable network interface

Now when you check the state of interfaces, the state of an interface “enp0s3” has been changed to “down”.

$ ip a

NW Interface is down

You can also check the state of an interface “enp0s3” separately using the below “grep” flag in the command as below.

$ ip a | grep -A 1 "enp0s3"

Check network interface state

Now, if we want to change the state to up again, we will use the same earlier mentioned command in the shell stating its state as “up” shown below.

$ sudo ifconfig enp0s3 up

Enable network interface

Now, when you check the state of interface “enp0s3” once again, you will find it's up again.

enp0s interface is up again

Control network interfaces through Systemctl command

Another way to disable Network Service within Ubuntu 20.04 Linux system is via the “systemctl” repository or tool. Hence, first of all, we need to check the network service status from the systemctl command followed by the keyword “status” as below. The output displays that the service is active and running properly.

$ sudo systemctl status NetworkManager.service

Network manager

To disable the service, we need to first stop it. So that it cannot get access to system resources. Hence, we have to use the systemctl command two times. The first time we will be using it with the “stop” keyword to stop it. And the second time we will use it with the “disable” keyword as shown in the below image as well.

$ sudo systemctl stop NetworkManager.service
$ sudo systemctl disable NetworkManager.service

Stop and disable network service using systemd

When you again check the status, you get that the service has been disabled.

$ sudo systemctl status NetworkManager.service

Check network status with systemctl command

Let’s again activate the Network service in our Ubuntu 20.04 system using the below restart and enable keyword command as below. You can see, the system has enabled this service by providing it a resource path.

$ sudo systemctl restart NetworkManager.service
$ sudo systemctl enable NetworkManager.service

Enable network service using systemd

Again checking the Network service using the status command, we found out that it's activated and enabled successfully.

$ sudo systemctl enable NetworkManager.service

Network service enabled

Conclusion

We have discussed and implemented two simple methods to disable, and then enable the network interfaces in Ubuntu 20.04 Linux System. Make sure to not miss any step while implementing these methods on your Ubuntu 20.04 Linux system for best results.