| by Arround The Web | No comments

Restart Network Service using systemctl Command

In many situations, it becomes necessary to restart the network service on Linux. Such as changing the network hardware component, modifying the network configuration files, and when the network becomes unstable.

On Linux, the NetworkManager is a service that manages and configures the system network. The NetworkManager.service automatically configures the network on boot, however, to manually manage it the systemctl tool is used.

In this guide, I explore how to restart the network using the systemctl command, and I will also go through other methods to restart the network on Linux.

How to Restart Network Service on Linux

Restarting the network is one of the key steps to troubleshoot the network on Linux. It is also used to apply any configuration changes and refresh the network resources.

There exist multiple approaches for restarting the network on Linux. Since most of the Linux distributions have shifted to systemd service manager, it has become easier and less complex to manage the network on them.

Systemd has a command called systemctl that restarts network services. In the following sections, I will cover various methods to restart the network services on Linux.

Restart Network Service Using systemctl

The systemctl command comes with various options to manage the systemd services, including the network.

To restart network service on all the latest versions of Ubuntu, Debian, CentOS, Arch, Fedora, SUSE, RHEL, Rocky, and Alma Linux systemctl with restart command will be used.

sudo systemctl restart NetworkManager.service

Upon executing the command, all the network and associated services will be restarted.

To further analyze the activity of the NetworkManager, see the log messages using journalctl command.

journalctl -u NetworkManager.service

Other Methods to Restart the Network Service

Linux is an open-source operating and hence offers multiple tools to accomplish a single task. Similarly, in the case of restarting the network, multiple utilities can be used, such as nmcli, nmtui, and ip commands.

Using nmcli Command

The nmcli command line is used to configure the NetworkManager service on Linux that uses the systemd init system. To use it to restart the network, simply, run the nmcli con command and set it up and down with the interface name.

sudo nmcli con down [interface-name] && nmcli con up [interface-name]

Replace the interface name with the actual interface name of your network. To find the interface name nmcli con command with show option.

nmcli con show

Here, the network interface name is Sam’s Network.

Similarly, this utility provides another option called networking, which can also be used to reset the network.

sudo nmcli networking off && nmcli networking on

The above commands temporarily disable the network and enable it. Ultimately, restarting the network to fix any issue with the connection.

Using nmtui Command

The nmtui is similar to nmcli, but the nmtui provides a terminal-based user interface, making it easy to use. To launch the TUI, use the nmtui command.

nmtui

To restart a connection, navigate to Activate a connection option, select the interface, and deactivate it.

Next, again select the connected interface, deactivate it, and then activate it to accomplish the restart process.

Now, get back to the main menu by navigating to the <back> option and then Quit the interface.

Using ip Command

Another method to restart the network is using the ip command with the interface name.

The name of the interface can be found by using the ip command, with the link (Network device) and show options.

ip link show

Note the interface name, it is interface number 5 (wlx74ea3) which is active at the moment. Now, replace the [interface-name] and run the commands given below to restart the network.

sudo ip link set [interface-name] down

sudo ip link set [interface-name] up

Ensure to run these commands separately to have a proper network reset.

Using network-scripts

The network-scripts are scripts to manage the network and can be used alongside NetworkManager. The network-scripts can also be used in distributions that do not come with NetworkManager. It is used in the legacy versions of RHEL and CentOS and is no longer in use. However, if you still want to use ifdown and ifup commands, then you can install it.

To install it on RHEL, Cent OS, and Linux distributions based on these operating systems.

yum install network-scripts

To install it on Ubuntu or Debian-based distributions, use.

apt install netscript-2.4

Now, the ifup and ifdown commands will be available to restart the network.

sudo ifdown [interface-name] && ifup [interface-name]

Keep in mind that the netscript or network-scripts are designed for older Linux kernel versions and have been deprecated.

Conclusion

Restarting the network is one of the key methods to diagnose the faulty network. Most Linux distributions have a built-in command line utility called systemctl to restart the network services. But you can also use nmcli, ip, and ifdown/ifup commands to restart the network. All of these methods are discussed in this guide, however, it is recommended to use systemctl as it is the default and less complex.

Share Button

Source: linuxhint.com

Leave a Reply