Network restart linux centos

CentOS 7 Restart Network Command

CentOS 7 introduces many changes in the way users handle and manage general Linux services. The same happened with Red Hat Enterprise Linux 7. And the big question here is: How to restart network service on CentOS? And how can I stop and start networking on CentOS or RHEL systems?

Today we will explore CentOS 7 Restart Network procedure, as well as stop and start networking service commands.

CentOS 7 and RHEL 7, the two most popular RedHat based distros in the web hosting industry, are using the new systemd. Systemd is a service manager, a new way to restart, stop and start services.

systemd replaces upstart as the default init system, and a few old-school sysadmins, webmasters and devs are a little bit confused about this new technology, however, don’t get mad… systemd is cool and is in fact a great init replacement.

Let’s see how to stop, start and restart networking on centos and RHEL linux.

The old Init system

In older versions of RHEL and CentOS, the init script were located at /etc/rc.d/init.d/ directory. This were simple scripts written in bash language, this scripts could be easily modified by the system adminstrator, as well as managed to start, stop or restart services on demand.

On the old init system to restart network on centos you only needed to run:

The new systemd model

systemd uses service units to manage the linux services, and scripts are no longer located at /etc/rc.d/init.d/ directory. And the old ‘service network restart’ is no longer valid.

CentOS 7 / RHEL 7 Restart Network.Service

In order to restart network on CentOS 7 and RHEL 7, you will need to use the systemd service called ‘network.service’ or just ‘network’ for the short version.

Источник

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.

Читайте также:  Apache сервер установить linux

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.

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

Читайте также:  Astra linux уровни доступа

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

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

Читайте также:  Dallas lock linux сертификат фстэк

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 Services in CentOS/RHEL?

In CentOS, the “Network Services” refer to the network-related processes and daemons that run on the system to provide network connectivity and communication. These services include protocols like “TCP/IP”, “DHCP”, “DNS”, and others that are essential for connecting to the internet and other networks.

This article will explain the various methods to restart the network services in CentOS/RHEL.

Method 1: Using the systemctl Command

It is the recommended method for systems running on CentOS 7 and later versions. To restart the network service, the “systemctl” command is utilized with the “restart” option below:

# systemctl restart network

The output takes some seconds to restart the services on the operating system.

Method 2: Using the service Command

This method can be used for systems running CentOS 6 and earlier versions (it also works on later versions). To restart the network service, utilize the “service” command in the following command:

The outcome of the above executions shows that the network services have been restarted.

Method 3: Using the nmcli command

This “nmcli” command is utilized to restart the network service by specifying the connection name. For instance, the network state of the “ens33” interface is set to down first and then up:

# nmcli con down ens33 && nmcli con up ens33

The output shows that first “ens33” is deactivated and then activated in the system.

Method 4: Using the nmtui Command (TUI-based)

This is a TUI-based method (Terminal User Interface) that can be utilized to restart the network service in CentOS. You can open the Network Manager TUI by running the below command:

Once you are in the Network Manager TUI, navigate to “Activate a connection” and hit “Enter”:

Select the active connection name as “ens33”, then press “Enter” to deactivate first. Then, again press “Enter” to activate the network services:

In this way, the network services will be restarted in the system.

Conclusion

CentOS offers the “systemctl”, “service”, “nmcli”, and “nmtui” commands to restart the network services. These commands can also be utilized to manage the network interfaces, assign IP addresses, resolve hostnames, route network traffic, and many more. This article has explained all possible methods to restart the network services in CentOS/RHEL.

Источник

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