Linux – Restarting networking on Debian Jessie

debian-jessielinuxnetworking

I would like to know which is the right method to restart networking service in Debian Jessie.
I know that I can use:

service networking restart

or

/etc/init.d/networking restart

that anyway gave me problems on ssh connection, or

invoke-rc.d networking restart

and other two methods with systemctl and with ifup/ifdown.

But which is the right way to do it?

Best Answer

I would use the service command because it is more consistent across different distributions. So of the commands you mentioned, the variant I would go for is:

service networking restart

And I would definitely run it inside a screen session or by other means ensure that it won't fail to complete in case you lost connection with the shell in which you typed it. (I have tried losing connectivity to a machine by logging in with ssh and then restarting the network only to have the ssh connection terminate while the network was down and send a HUP to service such that it would not bring up the network again.)

In the past there have been systems where service was a simple wrapper around the scripts in /etc/init.d and the first two of your commands would do the exact same thing. But nowadays there are systems where service will sometimes do something different, and in general service knows better what to do on your particular distribution. And invoke-rc.d is also distribution dependent.

Though service is the most similar across distributions, it is still possible for the service names to be different. For example there are distributions where the service is named network and others where it is named networking. And in some configurations it may be more appropriate to restart network-manager rather than networking.