Linux перезапуск службы сети

6 different commands to restart network in RHEL/CentOS 7/8

In this tutorial I will share different methods you can use to restart your network with RHEL/CentOS environment. I will cover both RHEL/CentOS 7 and 8 releases as with RHEL/CentOS 8 there are some major changes in terms of how networking is handled. Now Red Hat is completely moving towards Network Manager and is trying to ditch the legacy initscripts.

Some Background and Changes with RHEL/CentOS 8

If you are coming from RHEL/CentOS 5 or 6 then you will be familiar with SysV scripts to restart any service i.e.

With RHEL/CentOS 7 the SysV scripts are deprecated (although you may still use these commands but they can be removed any time and shouldn’t be used). Now all the system services, partitions, sockets are handled by systemd. But that is a different topic altogether, now with RHEL/CentOS 7 we used

# systemctl restart network

But with RHEL/CentOS 8 we get below error for this command

# systemctl restart network Failed to restart network.service: Unit network.service not found.

This is because with RHEL/CentOS 7, the network scripts were part of initscripts rpm, which is removed as part of RHEL/CentOS 8 and is migrated to network-scripts rpm
I have already written a detailed guide on this topic and the steps to use legacy network restart commands.

Now considering all these changes, we have multiple methods which we can use to restart network in RHEL/CentOS release. But before we jump there, let us understand if our interface is managed by NetworkManager or not as your command and steps to restart network would vary accordingly.

How to check if interface is configured with NetworkManager

There are couple of methods to verify if your Ethernet is configured via NetworkManager or manually using ip command or some other method:

Use nmcli con show to list the active connections

# nmcli con show NAME UUID TYPE DEVICE eth0 31e959d2-1c5f-46ea-a122-1f4c0f74d938 ethernet eth0

If you can see your interface in the output then it means that the interface is configured with NetworkManager

Alternatively grep for NM_CONTOLLED in /etc/sysconfig/network-scripts/ifcfg-ethXX

# grep NM_CONTROLLED /etc/sysconfig/network-scripts/ifcfg-eth1 NM_CONTROLLED=no

It is also possible you get a blank output, in such case you can use nmcli to verify but most likely the interface was configured with NetworkManager which is why you don’t see any entry for NM_CONTROLLED .

So now you know if your interface is configured via NetworkManager or not.

Читайте также:  Extended acl in linux

Since I have disabled consistent network device naming, the interface is shown as ethXX , in your case the interface name may vary.

Method 1: Using systemctl restart NetworkManager

You can use nmcli or nmtui to configure your network. Once the network configuration is done, you can use systemctl to restart the NetworkManager service

# systemctl restart NetworkManager

This should update your network changes. But if your network is not managed by NetworkManager , this command will do no change to your interface configuration.

Method 2: Using ifup and ifdown

Use this command with precaution as this can bring down your active interface which you may be using for SSH connections locking you out of the system. The only way to recover the network access by connecting to your server via console.

On RHEL/CentOS 8 with NetworkManager

With RHEL/CentOS 8, the ifup and ifdown commands are part of NetworkManager rpm unlike older releases where these were part of initscripts rpm.

# rpm -qf `which ifup` NetworkManager-1.20.0-3.el8.x86_64

So since you are using NetworkManager , you can also use ifup and ifdown to refresh the network configuration of any interface. For example you did some changes for eth1 , so to refresh the changes first bring down the interface and then bring it up

It is important that you execute the command in this format as if you try to execute separately then your server may become unreachable.

This should update your network configuration.

On RHEL/CentOS 8 without NetworkManager

On RHEL/CentOS 8 if your network interface is not managed by NetworkManager then you must install network-scripts to be able to use ifup and ifdown command.

On RHEL system you must have an active subscription to RHN or you can configure a local offline repository using which «yum» package manager can install the provided rpm and it’s dependencies.

# dnf -y install network-scripts

Next you can check the rpm ownership for ifup

# rpm -qf `which ifup` NetworkManager-1.20.0-3.el8.x86_64 network-scripts-10.00.4-1.el8.x86_64

Now ifup is part of both NetworkManager and network-scripts rpm. Next you can use ifdown eth1 && ifup eth1

# ifdown eth1 && ifup eth1 WARN : [ifdown] You are using 'ifdown' script provided by 'network-scripts', which are now deprecated. WARN : [ifdown] 'network-scripts' will be removed in one of the next major releases of RHEL. WARN : [ifdown] It is advised to switch to 'NetworkManager' instead - it provides 'ifup/ifdown' scripts as well.

Similar WARN is visible for ifup action.

ifup and ifdown interface

Since network-scripts is added just to support fallback behaviour, it throws WARNING every time you use ifup or ifdown without NetworkManager .

Method 3: Using nmcli networking

We can also use the command-line tool » nmcli networking » for controlling NetworkManager to restart network and update network configuration.

# nmcli networking off && nmcli networking on

This command will bring down all the NetworkManager interfaces and then will bring them up.
IMPORTANT: It is important that you execute the command in this format as if you try to execute separately then your server may become unreachable as the first command will bring down all the NetworkManager managed interfaces

Method 4: using nmcli con up and down

With nmcli we can also use nmcli con up or con down similar to traditional ifup and ifdown to de-activate and activate individual network interface instead of restarting all the networking interfaces on the server.

# nmcli con down eth1 && nmcli con up eth1 Connection 'eth1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14) Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/15)

IMPORTANT: It is important that you execute the command in this format as if you try to execute separately then your server may become unreachable as the first command will bring down all the NetworkManager managed interfaces

Читайте также:  Linux узнать день недели

Method 5: Using nmtui

We also have NetworkManager TUI which is an alternative to nmcli command. Users who are not comfortable with nmcli command line, they can use nmtui to manage their network
To de-activate or activate a network interface using nmtui , execute nmtui as root user on the Linux server terminal

This should open a window, next select «Activate a Connection» to update the network configuration

centos restart network

Select the interface which you would wish to deactivate and re-activate.

If you deactivate your active interface then your SSH connection will be lost. If you intend to restart network for primary interface then you must use nmtui from graphical console independent of SSH or network connection.

centos restart network

Next Activate the respective interface

centos restart network

Once your interface is active, you can come back and exit the nmtui session.

Источник

How to restart network on Ubuntu 20.04 LTS Focal Fossa

There exist various ways of restarting network on Ubuntu 20.04. Possibly the simplest way would be to restart network from GUI such as GNOME. Other ways would include the use of the command line and commands netplan and ip . Finally, the NetworkManager command line tool nmcli or the System V init scripts can be used to successfully restart network on Ubuntu 20.04 Focal Fossa.

In this tutorial the reader will be provided with comprehensive information on:

  • How to restart network from GUI
  • How to restart network using the netplan command
  • How to restart network using the ip command
  • How to restart network using System V init scripts
  • How to restart network by using the NetworkManager command line tool nmcli

System networking managed by networkd deamon on Ubuntu 20.04 Focal Fossa

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Restarting network on Ubuntu 20.04 LTS Focal Fossa step by step instructions

Restarting network from GUI desktop on Ubuntu 20.04

In case you are running the default GNOME GUI on your Ubuntu 20.04 the simplest way to restart the network is to click on the top-right network icon:

From there simply select network interface you wish to restart and click on the Turn Off menu option.

From there simply select network interface you wish to restart and click on the Turn Off menu option.

Once the network interface is turned off you can now turn it on by clicking on the connect menu option.

Once the network interface is turned off you can now turn it on by clicking on the Connect menu option. Completing both steps will effectively restart your network.

Restarting network from command line on Ubuntu 20.04

The first step is to check how the system networking is managed. There are few options how your networking may be managed:by the NetworkManager or by the networkd daemon. The commands you choose from the below list will be only effective when selected for the appropriate network management configuration.

 check your network management configuration check the content of the /etc/netplan/01-netcfg.yaml or /etc/netplan/50-cloud-init.yaml configuration file.

To check your network management configuration check the content of the /etc/netplan/01-netcfg.yaml or /etc/netplan/50-cloud-init.yaml configuration file. The configuration we are looking for is Renderer . From there you can see whether your system networking is managed by networkd deamon or NetworkManager . If no Renderer is defined your system is most likely managed by networkd daemon.

The first and recommended command to restart your network is:

The above command will restart your network regardless network management configuration settings.

Network restart for networkd managed systems

The following commands will restart network interface enp0s3

$ sudo ip link set enp0s3 down $ sudo ip link set enp0s3 up

Using ip command to restart network on the Ubuntu 20.04 Focal Fossa

Network restart for NetworkManager managed systems

$ sudo nmcli networking off $ sudo nmcli networking on

Restart the network on the Ubuntu system by using the nmcli command line tool.

Alternatively you can try to restart your network with System V init script:

$ sudo /etc/init.d/network-manager restart

Network restart for interfaces listed in /etc/network/interfaces

For all devices listed in the /etc/network/interfaces the following command can be used to restart the listed network interfaces. Please note that if the ifdown or ifup command is missing you need to install the ifupdown package first.

$ sudo ifdown -a $ sudo ifup -a

Источник

Перезапуск сети в Ubuntu

В Ubuntu и Debian инициализацией сетевых интерфейсов и настройкой сети занимается специальная сетевая служба — networking. Информация о конфигурации сетевых интерфейсов хранится в файле /etc/network/interfaces.

Если вы что-либо измените в этом файле, нужно будет перезапустить сеть, чтобы применить изменения. В этой статье мы рассмотрим как выполнить перезапуск сети Ubuntu 16.04.

Перезагрузка сети в Ubuntu

Можно, конечно, выполнить полную перезагрузку компьютера, но это не совсем удобно если можно просто перезапустить сеть Ubuntu. Для перезапуска сети используйте следующую команду:

sudo service networking restart

В современных дистрибутивах уже давным давно используется система инициализации Systemd, поэтому можно использовать команду systemctl вместо команды service:

sudo systemctl restart networking.service

Кроме того, можно перезапустить NetworkManager, это тоже помогает, если сеть настроена через него:

sudo systemctl restart NetworkManager

Перезапуск сети в NetworkManager

Чаще всего, для управления сетью в современных дистрибутивах используется программа Network Manager. Можно сразу же использовать ещё для наших целей. Просто отключите, а затем включите сеть обратно следующими командами:

sudo nmcli networking off

После отключения сети значок NetworkManager пропадёт с панели, а потом снова появится после включения. Аналогично, вы можете использовать NetworkManager в графическом интерфейсе. Кликните по его иконке, выберите нужное сетевое подключение и нажмите Выключить:

Затем включите его обратно.

Команды ifup и ifdown

Эти команды работают на более низком уровне, они управляют непосредственно самими сетевым интерфейсами. Для перезапуска сети мы можем отключить все интерфейсы, а затем включить обратно:

Вы не увидите никаких изменений в графическом интерфейсе, но когда сетевой интерфейс будет отключён, вы не будете иметь доступа к интернету.

Выводы

Как видите, не всегда обязательно перезагружать компьютер после изменений настроек, в большинстве случаев достаточно перезапустить только нужный сервис. Надеюсь, эта информация была вам полезной.

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

Оцените статью
Adblock
detector