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.

Antonius Bloch
  • 4,480
  • 6
  • 28
  • 41

7 Answers7

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.

DUzun
  • 103
  • 4
Mike
  • 21,910
  • 7
  • 55
  • 79
  • 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 '11 at 16:55
  • @hmontoliu: then again it seems wise to use the deprecated restart since you cannot forget the starting command – mbx May 15 '11 at 21:53
  • 1
    If you are in remote, you should always use `screen` – Avio Mar 21 '13 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 '14 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. – Håkan Lindqvist Aug 21 '14 at 05: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 <md@linux.it>  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
hmontoliu
  • 3,693
  • 3
  • 22
  • 24
  • Really? Restart is useful when you are working remotely! – Antonius Bloch May 15 '11 at 16:41
  • 2
    See my edit. I agree that a bullet proof restart would be better than stop + start – hmontoliu May 15 '11 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). – Håkan Lindqvist Aug 21 '14 at 05: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!

Eduardo Ivanec
  • 14,531
  • 1
  • 35
  • 42
  • 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? –  May 29 '11 at 12:51
  • 1
    Not at all. How zany of you! – Eduardo Ivanec May 29 '11 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
Erick
  • 131
  • 4
2

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

Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
Dazz
  • 21
  • 1
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.

mivk
  • 3,457
  • 1
  • 34
  • 29
  • With `systemd` it's `systemctl restart networking` iirc, but the "old" `service` way is still working. – wb9688 Jun 23 '17 at 05: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
sanmai
  • 521
  • 5
  • 19