Debian12 的网络用什么配置?

2025 年 2 月 12 日
 Koril

背景

我下载了 Debian12 的 iso 镜像(版本:debian-12.7.0-amd64-DVD-1.iso ,无桌面),在 virtualbox7 中安装好后,我发现默认使用的网络配置服务是 networing.service

然后,我阅读了这个官方的文档: https://www.debian.org/doc/manuals/debian-reference/ch05.zh-cn.html

在 5.3 小结中,文档给出了如何配置静态 IP 的方案,使用的是 systemd-networkd 。

我在 virtualbox 给这个 debian 系统网络设置了桥接模式,然后根据文档配置了静态地址:

sudo vim /etc/systemd/network/static.network 

[Match]
Name=en*

[Network]
DHCP=no
Address=192.168.0.201/24
Gateway=192.168.0.1
DNS=192.168.0.1


我的疑问

我把 networking.service 直接关掉了,开启了 systemd-networkd.service ,执行的是以下命令:

# 关闭 networking.service
sudo systemctl disable networking.service
sudo systemctl stop networking.service

# 开启 systemd-networkd.service
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd

第一个问题

平稳运行了一段时间后,我发现重启服务器或者重启路由器,服务器的 ip 又会变成一个不是我指定的地址,我在配置文件指定的是 192.168.0.201 ,但是它会变成 192.168.0.106 之类的,我猜测和 DHCP 有关,请问这是为什么?

第二个问题

在安装了 Debian12 系统的服务器中,我该使用哪一个配置网络,networking.service 还是 systemd-networkd.service ?

我在阿里云上买的云服务装的也是 debian12 ,它默认用的是 systemd-networkd.service 。

而我本地虚拟机安装 debian12 ,默认用的是 networking.service 。

4264 次点击
所在节点    Linux
24 条回复
easy88866
2025 年 2 月 13 日
@5xX4U5sUwdELgdQ3 感谢你的整理,非常实用。

这里再 append 一些内容。

根据 Debian 文档 [4 ways to configure the network]( https://wiki.debian.org/NetworkConfiguration#A4_ways_to_configure_the_network) 目前 Debian 支持 4 种方式配置网络。

> - The interfaces configuration file at /etc/network/interfaces (this page): for basic or simple configurations (e.g. workstation)
> - [NetworkManager]( https://wiki.debian.org/NetworkManager): This is the default for Laptop configuration
> - Systemd: [Debian reference Doc Chapter 5]( https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_modern_network_configuration_without_gui)
> - [Netplan]( https://wiki.debian.org/Netplan): [Debian reference Doc Chapter 5]( https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_modern_network_configuration_for_cloud)



之前站内有讨论过不同工具间关系,可以参考 [Linux 下的网络管理服务太乱了,我现在都没搞明白之间的关系]( https://v2ex.com/t/834317)



我个人偏好 systemd , 一般会在配置网络前,把不同工具的配置文件清理一遍,防止互相影响。具体路径如下

- /etc/network/interfaces
- /etc/network/interfaces.d
- /etc/systemd/network
- /etc/netplan

NetworkManager 的配置文件在 /etc/NetworkManager ,我没动过好像也没影响。
julyclyde
2025 年 2 月 14 日
@jasonyang9 networking 为什么和 desktop environment 相关呢?
julyclyde
2025 年 2 月 14 日
@flyqie netplay try 功能我觉得比 ifupdown 安全一些,万一改坏了似乎还有诈尸的可能性
julyclyde
2025 年 2 月 14 日
@easy88866 关系,就是阿猫阿狗都想当别人的 frontend
古代曾经在 sound 界就出过类似的事,oss 和 alsa 各自可以代理对方
现在 netplan 也是可以代理 networkmanager (和一个别的啥?)的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/1110984

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX