What is the preferred method to restart networking in Ubuntu and Debian
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.
Solution 1:
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.
Solution 2:
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
Solution 3:
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!
Solution 4:
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
Solution 5:
how about nohup sh -c "ifdown -a && ifup -a"