37

When I restart the network using:

/etc/init.d/networking restart

I get this warning:

 Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces

So what's the best way to restart the network after making changes now?

This problem also applies to Debian as the netbase package is inherited from debian.

7 Answers 7

28

It is just saying that the restart option is going away

/etc/init.d/networking stop; /etc/init.d/networking start

Note there is one line only! That is important when running network restart through the network.

5
  • 29
    two commands :-/ bad idea if you are in remote. Better use a one liner: /etc/init.d/networking stop; /etc/init.d/networking start
    – hmontoliu
    May 15, 2011 at 16:55
  • @hmontoliu: then again it seems wise to use the deprecated restart since you cannot forget the starting command
    – mbx
    May 15, 2011 at 21:53
  • 1
    If you are in remote, you should always use screen
    – Avio
    Mar 21, 2013 at 11:09
  • 5
    Screen won't really help if you shut down networking on a remote server. In this case you would have to go search for some sort of direct access, which isn't always convenient.
    – metakermit
    May 14, 2014 at 20:06
  • 1
    stop and start are obviously not deprecated but used in combination they have the same potential problem that restart used to have. Aug 21, 2014 at 5:55
19

Run the init.d command without parameters, it will tell you which is the usage:

~# /etc/init.d/networking 
Usage: /etc/init.d/networking {start|stop}

Seems that restart is deprecated

It is deprecated also in Debian at least since:

netbase (4.38) unstable; urgency=low

  * Create /etc/sysctl.d/bindv6only.conf on upgrades and new installs
    to set net.ipv6.bindv6only=1.
  * Made the init script check for swap over the network. (Closes: #540697)
  * Temporarily depend on initscripts to work around a bug in multistrap.
    (Closes: #556399)
  * etc-services: added sieve (4190/tcp).
  * etc-services: removed sieve (2000/tcp). (Closes: #555664)
  * Made the init script warn that using the force-reload and restart
    parameters is not a good idea. (Closes: #550240)

 -- Marco d'Itri <[email protected]>  Sun, 06 Dec 2009 17:09:41 +0100

The related bug #550240 here

Which is quite nasty. To restart netwokring from remote probably the best and securest approach will be run the following within a screen session:

~# /etc/init.d/networking stop; /etc/init.d/networking start

As of today's networking init script, restart and force-reload will work in most circumstances. I guess it's reasonably safe to ignore the warning and still use restart. However I'll go with the stop + start way :-)

case "$1" in
start)
    process_options

    log_action_begin_msg "Configuring network interfaces"
    if ifup -a; then
        log_action_end_msg $?
    else
        log_action_end_msg $?
    fi
    ;;

stop)
    check_network_file_systems
    check_network_swap

    log_action_begin_msg "Deconfiguring network interfaces"
    if ifdown -a --exclude=lo; then
        log_action_end_msg $?
    else
        log_action_end_msg $?
    fi
    ;;

force-reload|restart)
    process_options

    log_warning_msg "Running $0 $1 is deprecated because it may not enable again some interfaces"
    log_action_begin_msg "Reconfiguring network interfaces"
    ifdown -a --exclude=lo || true
    if ifup -a --exclude=lo; then
        log_action_end_msg $?
    else
        log_action_end_msg $?
    fi
    ;;

*)
    echo "Usage: /etc/init.d/networking {start|stop}"
    exit 1
    ;;
esac
3
  • Really? Restart is useful when you are working remotely! May 15, 2011 at 16:41
  • 2
    See my edit. I agree that a bullet proof restart would be better than stop + start
    – hmontoliu
    May 15, 2011 at 16:53
  • I think it's worth noting that stop + start appears to do the exact same thing that restart would do. It does not appear to be any more safe, other than not using a deprecated option (deprecated specifically to discourage this operation). Aug 21, 2014 at 5:53
5

I use nohup sh -c "/etc/init.d/networking stop; sleep 2; /etc/init.d/networking start". I add sleep 2 because I think perhaps the issues with restart had something to do with hardware-dependent latencies, but this is unconfirmed and a semi-rule of thumb I'm somewhat ashamed to make public. So you can skip that if you're feeling rational!

2
  • so basically you're saying I have to alias restart="nohup sh -c /etc/init.d/networking stop; sleep 2; /etc/init.d/networking start" because somebody using Debian, thinks his or her job will be on the line if we actually evolve Linux beyond a hobbiest OS?
    – user82971
    May 29, 2011 at 12:51
  • 1
    Not at all. How zany of you! May 29, 2011 at 17:26
3

The command below works well in a server environment, without throwing warnings. It implements both stop and start request on the networking service.

sudo service networking start
2
  • That doesn't seem to do stop && start. Anyway, it didn't for me in Debian Wheezy. Maybe it does in some other distro.
    – mivk
    Jul 18, 2015 at 13:27
  • It works fine in Ubuntu
    – Erick
    Jul 22, 2015 at 17:07
2

how about nohup sh -c "ifdown -a && ifup -a"

1

In Debian Wheezy,

service networking restart

seems to do what is expected and doesn't complain.

I guess in Jessie with systemd it may be different again.

1
  • With systemd it's systemctl restart networking iirc, but the "old" service way is still working.
    – wb9688
    Jun 23, 2017 at 5:20
0

If you can't find the reason networking fails to restart, do it in the verbose mode inside of a screen session:

ifdown -v --force eth0; ifup -v eth0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .