BuyVM Web Console

站长所用 Linux distribution 一直是以 Debian 为主,所以以下重启网络服务失败的解决办法仅针对 Debian。当然其它 distribution 可依此为参考

Interface

下面是站长所用 BuyVM 的 /etc/network/interfaces 网络接口配置,IPv4 使用的是 DHCP 配置,IPv6 使用的是静态的 Stateless Address Auto-configuration (SLAAC) 配置,由于此处 interfaces.d 目录中无其它独立的配置文件,因此可直接修改 interfaces 主配置文件就可以啦

每个主机商提供的系统模板多少都有差别,所以下面配置文件仅作参考

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

iface eth0 inet6 static
    address 2605:6400:30:eabf::1
    netmask 48
    gateway 2605:6400:30::1

auto 字段开头或以 allow- 开头标识的作用不一致,详情请见下面的参考资料

General Restart Networking Service

service 命令

service networking restart

systemctl 命令

systemctl restart networkingsystemctl restart networking.service

或是

/etc/init.d/networking restart

How to Solve Restart Failure

以下提供三种思路或是称作为方法,如有补充或是更正可以在下方留言

Edit interfaces

如上面的 interfaces 示例,第一个办法是更改 allow-hotplug 字段为 auto

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

iface eth0 inet6 static
    address 2605:6400:30:eabf::1
    netmask 48
    gateway 2605:6400:30::1

ifupdown

ifupdown 是配置网络接口的高层次工具,它们可以用来根据 /etc/network/interfaces 文件中的接口定义配置和取消配置网络接口,Debian 特有

如果重启 networking service 后导致网络服务异常,可以尝试 ifup eth0 手动启用 interface eth0 网卡,或是 ifdown eth0 停止

一句命令概括即为 systemctl restart networking && ifup eth0

Reboot

无脑直接 reboot 重启,直接利索但是可能会影响到其它服务的正常运行,一般不推荐这么做

Some problems

可能由于误操作导致 iptables 防火墙软体找不到,此时上述命令无法奏效,重启 networking 服务或重启 reboot 都不能解决问题。因此需要看日志具体分析

举个例子,有次修改 /etc/networking/interfaces 文件后想要重启 networking 服务或是 ifup eth0 或是 reboot 都无法奏效,查看日志后意外发现 iptables 工具消失了,无法找到该命令。无法联网的情况下,是无法 apt-get install -y iptables 下载安装 iptables,之后 find / -name iptables 找到 /etc/network/if-pre-up.d/iptables 注释后重启解决了联网的问题

Reference

interfaces(5) — ifupdown — Debian bullseye — Debian Manpages

ifup(8) — ifupdown — Debian bullseye — Debian Manpages

ifdown(8) — ifupdown — Debian bullseye — Debian Manpages

第 5 章 网络设置 (debian.org)

最后修改:2023 年 06 月 11 日
如果觉得我的文章对你有用,请随意赞赏