12

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?

9

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.

  • Thanks for the explanation, very clear! Next time I'll use screen along with the service command mentioned prior. – cloud81 Apr 3 '16 at 17:34
  • 3
    isnt it deprecated to use service on systemd systems at all? – greenone83 Oct 29 '16 at 11:56
  • @greenone83 There is no indication in the man page about the command being deprecated. On all systems where I have seen it, it has been a convenient wrapper script around whatever init system that distribution was using. And it has been updated as init has been redesigned. Which means you can use the same service command now as you could 10 years ago, and it will do the right thing even though the underlying init scripts behave totally different. – kasperd Oct 29 '16 at 12:24
  • @kasperd this pretty much explains my point... unix.stackexchange.com/questions/240528/… you can do it... but then you might disturb systemd – greenone83 Oct 29 '16 at 20:02
  • 1
    I swapped out my LAN cables, which killed the network connection. systemctl restart networking did nothing, but service networking restart worked a charm. I'm running Debian Jessie. – aSystemOverload Oct 21 '17 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.