Restart network in Ubuntu command line
How To

Restart Network in Ubuntu Command Line

Sagar Sharma
Sagar Sharma

Table of Contents

After making some changes to the network config file, or if the network is not working as expected, restarting the network is the first choice of every Linux user.

So how do you restart the network in Ubuntu?

Well, there are multiple ways to do it and in this tutorial, I will be covering the following:

Ubuntu 18.04 Review of New Features
Ubuntu 18.04 Review of New Features
  • Using the systemctl command (easiest and recommended way)
  • Using the nmcli command
  • Using the ip command
  • Using the ifconfig command

So let's start with the first one.

🚧
Be careful when you are doing it on a remote server via SSH.

Restart the network in Ubuntu using systemctl

Using the systemctl command is by far the most convenient way to configure services in Ubuntu.

And to restart the network using the systemctl command, all you have to do is execute the following command:

sudo systemctl restart NetworkManager

That's it!

Restart the network in Ubuntu using nmcli

The nmcli comes with various features and the syntax is quite simple.

But there is no option to restart the network so you'll have to execute the command to turn off and turn on the network manually.

So here, I have combined the two commands using the && operator so you can use the single command that will restart the network:

sudo nmcli networking off && sudo nmcli networking on

Restart the network in Ubuntu using ip command

As previously, you will need the network interface name to restart the network.

So first, use the following command to find the name of the active network interface:

ip route get 8.8.8.8 | awk 'NR==1 {print $5}'

And it will return the active network interface.

Now, use the ip command by entering the name of the network interface name as shown:

sudo ip link set <interface-name> down && sudo ip link set <interface-name> up

In my case, the interface is wlo1, so my command to restart the network would look like this:

sudo ip link set wlo1 down && sudo ip link set wlo1 up

That's it!!

Restart the network in Ubuntu using ifconfig

You need to install ifconfig command first and then to use the ifconfig; you will have to enter the network interface name.

And you may have multiple network interfaces, so to find the interface with an active internet connection, you can use the ip command as shown:

ip route get 8.8.8.8 | awk 'NR==1 {print $5}'
find the interface with active internet connection in ubuntu

In my case, it was wlo1.

Once done, enter the interface name in the following command:

sudo ifconfig <interface-name> down && sudo ifconfig <interface-name> up

In case, the interface is wlo1, so, the command would look like this:

sudo ifconfig wlo1 down && sudo ifconfig wlo1 up

Just getting started with networking? Let me speed up things!

If you are just getting started with networking, here's a detailed guide on basic networking commands with examples so you can speed up the journey:

21 Basic Linux Networking Commands You Should Know
A list of basic Linux networking commands that will help you troubleshoot network issues, monitor packets, connect devices, and much more.

I hope you will find this guide helpful. And if you have any queries, feel free to ask in the comments.



Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.