在 Ubuntu 和 Debian 中重新启动网络的首选方法是什么

Ant*_*och 37 ubuntu debian ubuntu-11.04

当我使用以下命令重新启动网络时:

/etc/init.d/networking restart
Run Code Online (Sandbox Code Playgroud)

我收到此警告:

 Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
Run Code Online (Sandbox Code Playgroud)

那么现在进行更改后重新启动网络的最佳方法是什么?

这个问题也适用于 Debian,因为 netbase 包是从 debian 继承的。

Mik*_*ike 28

只是说重启选项正在消失

/etc/init.d/networking stop; /etc/init.d/networking start
Run Code Online (Sandbox Code Playgroud)

注意只有一行!这在通过网络运行网络重启时很重要。

  • 两个命令:-/ 如果您在远程位置,那是个坏主意。最好使用一行:`/etc/init.d/networking stop; /etc/init.d/networking start ` (29认同)
  • 如果您关闭远程服务器上的网络,屏幕将无济于事。在这种情况下,您将不得不去搜索某种直接访问,这并不总是很方便。 (5认同)

hmo*_*liu 19

不带参数运行 init.d 命令,它会告诉你哪个是用法:

~# /etc/init.d/networking 
Usage: /etc/init.d/networking {start|stop}
Run Code Online (Sandbox Code Playgroud)

似乎不推荐重新启动

它也在 Debian 中被弃用,至少因为:

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
Run Code Online (Sandbox Code Playgroud)

相关的错误 #550240 在这里

这是非常讨厌的。要从远程重新启动网络,最好和最安全的方法可能是在屏幕会话中运行以下命令:

~# /etc/init.d/networking stop; /etc/init.d/networking start
Run Code Online (Sandbox Code Playgroud)

作为今天的networking初始化脚本,restart并且force-reload将工作在大多数情况下。我想忽略警告并仍然使用 restart 是相当安全的。但是我会选择停止+开始的方式:-)

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
Run Code Online (Sandbox Code Playgroud)

  • 请参阅我的编辑。我同意防弹重启比停止 + 启动要好 (2认同)

Edu*_*nec 5

我用nohup sh -c "/etc/init.d/networking stop; sleep 2; /etc/init.d/networking start". 我补充说,sleep 2因为我认为重启的问题可能与依赖于硬件的延迟有关,但这是未经证实的,我有点羞于公开的经验法则。所以如果你感觉理性,你可以跳过它!