为什么在 Debian 上重新启动网络不起作用?

为什么在 Debian 上重新启动网络不起作用?

为什么重新启动网络无法在我的服务器上成功重新启动 eth0?我的 CentOS 虚拟机都没有这个问题。

root@living:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:91:00:01
          inet addr:192.168.1.110  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe91:1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9354 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4835 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1052796 (1.0 MiB)  TX bytes:1129902 (1.0 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:287 errors:0 dropped:0 overruns:0 frame:0
          TX packets:287 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:23280 (22.7 KiB)  TX bytes:23280 (22.7 KiB)
root@living:~# service networking restart
Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces ... (warning).
Reconfiguring network interfaces...
[PuTTY disconnects]
root@living:~# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:287 errors:0 dropped:0 overruns:0 frame:0
          TX packets:287 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:23280 (22.7 KiB)  TX bytes:23280 (22.7 KiB)

答案1

root@machine:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
 address 192.168.1.110
 gateway 192.168.1.1
 netmask 255.255.255.0
 network 192.168.1.0
 broadcast 192.168.1.255

解决方案是用 auto 替换 allow-hotplug。谢谢!:)

答案2

我怀疑您的问题是,当网络关闭(重新启动)时,sshd 会注意到并关闭连接。当 sshd 关闭连接时,伪 tty SIGHUP 会连同其中运行的程序一起对 shell 发出 SIGHUP 信号。这包括在init.d/networking重新启动连接之前即将终止的程序。

首先尝试运行screen(以便 shell 不被中断)或者至少nohup service networking restart以便脚本不会收到 SIGHUP 并终止。

相关内容