Easy Steps To Restart Network on Ubuntu 24/22/20 – OrcaCore

Posted on

Easy Steps To Restart Network on Ubuntu 24/22/20 – OrcaCore

This guide demonstrates How To Restart Network on Ubuntu server from the CLI. It’s applicable for Ubuntu 20.04, Ubuntu 22.04, and Ubuntu 24.04. Understanding how to restart network on Ubuntu systems is crucial for any system administrator.

Every computer, regardless of size or complexity, relies on network connections to exchange information. These networks can range from small home setups to massive, intricate infrastructures like those found in universities or the Internet itself. Effective network management is essential for maintaining system stability and performance. When network issues arise, a common and often effective solution is to restart the network services. Follow the steps below to restart network on Ubuntu using the command line.

To proceed, you’ll need to log in to your Ubuntu server as a root user or a non-root user with sudo privileges. Then, you can proceed to the methods outlined below using Linux commands to restart network on Ubuntu.

There are several ways to restart your network, leveraging tools like NetworkManager, systemd, and nmcli. Let’s explore each of these methods.

1. Restart Network with NetworkManager

NetworkManager is a dynamic network control and configuration system. It simplifies network management by automatically detecting and configuring network connections.

To restart the network using NetworkManager, execute the following command:

sudo service network-manager restart

2. Restart Network with systemd

systemd serves as a Linux initialization system and service manager. Its functionalities encompass on-demand daemon starting, mount and automount point maintenance, snapshot support, and process tracking through Linux control groups. systemd also provides a logging daemon and other utilities that streamline common system administration tasks.

To restart the network service using systemd, use the following command:

sudo systemctl restart NetworkManager.service

3. Restart Network with Nmcli Command

nmcli (NetworkManager Command Line Interface) is a command-line tool designed for controlling NetworkManager and reporting network status. It provides a powerful and flexible way to manage network connections from the terminal.

To restart the network using nmcli, you need to first turn off the network and then turn it back on:

# sudo nmcli networking off
# sudo nmcli networking on

You can also use other commands, but these are the basic commands for restarting the network using nmcli.

4. Restart Network with ifup and ifdown Commands

ifup activates a network interface, enabling it to transmit and receive data. Conversely, the ifdown command disables a network interface, preventing it from sending or receiving data. These commands provide direct control over individual network interfaces.

To use these commands, you may need to install the ifupdown package first:

sudo apt update && sudo apt install ifupdown -y

After installation, you can disable and re-enable all network interfaces with the following commands:

sudo ifdown -a && sudo ifup -a

5. Restart Network with IP Command

The ip command is a versatile Linux networking tool used by system and network administrators for configuring and managing network interfaces, routing tables, and other network parameters.

To restart a network interface using the ip command, first identify the target network interface using the following command:

ip link show

This command will output a list of network interfaces and their current status.

Restart Network on Ubuntu with ip command

In this example, eth0 is the target interface. To restart this network interface, use the following commands:

# sudo ip link set eth0 down
# sudo ip link set eth0 up

That completes the process of restarting the network using the ip command.

Conclusion

Restarting the network on Ubuntu is a common task performed to apply changes to network settings, refresh connections, troubleshoot connectivity issues, or reset network services following modifications such as IP address changes or DNS updates. You have now learned how to restart network on Ubuntu server from the CLI.

Hope you enjoy it. Please follow us on Facebook, Instagram, and YouTube.

You may also like these articles:

Manage Networking with Netplan on Debian / Ubuntu

Disable NetworkManager on AlmaLinux 8

Monitor Linux Network Bandwidth Usage with nload Command

Set up Ntopng on Ubuntu 24.04

Alternative Solutions to Restart Network on Ubuntu

While the methods described above are common and effective, there are other ways to achieve a similar result. Here are two alternative approaches to restarting the network on an Ubuntu server:

1. Using Netplan (for network configuration applied through Netplan)

Netplan is a network configuration abstraction renderer introduced in Ubuntu 17.10. It allows you to easily configure network interfaces using YAML configuration files, which are then interpreted by a backend renderer like NetworkManager or systemd-networkd. If your Ubuntu system uses Netplan for network configuration, the recommended approach to restart the network is to apply the Netplan configuration.

Explanation:

Netplan works by reading configuration files (typically located in /etc/netplan/) and generating the necessary configurations for the chosen renderer (NetworkManager or systemd-networkd). Applying the Netplan configuration effectively reloads the network settings, ensuring that any changes are applied and the network interfaces are brought up to date. This is especially useful after modifying the network configuration files.

Code Example:

To apply the Netplan configuration, use the following command:

sudo netplan apply

This command will parse the Netplan configuration files and apply the specified network settings. If there are any syntax errors in the configuration files, the command will report them, allowing you to correct them before applying the changes. In some cases, you may need to use the --debug flag to get more detailed output:

sudo netplan --debug apply

This can help troubleshoot any issues that may arise during the application of the Netplan configuration.

2. Restarting individual interfaces using ifreload

The ifreload command provides a more graceful way to restart a network interface compared to directly using ifdown and ifup. It’s designed to minimize disruption to network services by attempting to maintain existing connections while reconfiguring the interface.

Explanation:

Unlike ifdown which abruptly disconnects the interface, ifreload tries to renegotiate the connection with minimal interruption. This is especially important for services that rely on stable network connections, as it can prevent them from being unexpectedly terminated. This command is often used in scripts or automated tasks where minimizing downtime is critical.

Code Example:

To use ifreload, you first need to identify the interface you want to restart. You can use ip link show as before. Then, use ifreload with the interface name:

sudo ifreload eth0

This command will attempt to reload the configuration for eth0 without completely taking it down. If the interface isn’t managed by ifupdown, it might not work as expected. Ensure that the interface configuration is properly set up in /etc/network/interfaces for ifreload to function correctly. This alternative approach offers a smoother restart for network interfaces, minimizing disruption to running services.

These alternative methods offer different ways to restart network on Ubuntu, providing flexibility based on your network configuration and needs.