当我这样做时,systemctl status network
我看到它的状态为失败,但它仍然可以请求外部 URL。有人可以解释一下,这项服务到底是做什么的吗?是物理连接的接口吗?
答案1
背景
首先,这不是技术上的network.service
,而是network.target
。请注意,当我们在 CentOS 7 机器上查找这些文件中的任何一个时,我们只找到该network.target
文件。
$ locate network.service
$
$ locate network.target
/usr/lib/systemd/system/network.target
$
您可以通过命令直接从 systemd 获取 systemd 单元文件描述systemctl
。例如:
$ systemctl show network | grep -i description
Description=LSB: Bring up/down networking
如果您查看通知的输出,systemctl status ...
则会显示此描述:
$ systemctl status network
● network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2018-09-03 21:49:05 EDT; 2 days ago
Docs: man:systemd-sysv-generator(8)
Process: 809 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
另请注意,以手册页的形式提供了对文档的引用。
man systemd-sysv-generator
systemd-sysv-generator is a generator that creates wrapper .service units for SysV init[1] scripts in /etc/init.d/* at boot and when configuration of the system manager is reloaded. This will allow systemd(1) to support them similarly to native units. LSB headers[2] in SysV init scripts are interpreted, and the ordering specified in the header is turned into dependencies between the generated unit and other units. LSB facilities "$remote_fs", "$network", "$named", "$portmap", "$time" are supported and will be turned into dependencies on specific native systemd targets. See systemd.special(5) for more details. SysV runlevels have corresponding systemd targets (runlevelX.target). Wrapper unit that is generated will be wanted by those targets which correspond to runlevels for which the script is enabled. systemd does not supports SysV scripts as part of early boot, so all wrapper units are ordered after basic.target. systemd-sysv-generator implements systemd.generator(7).
systemd-sysv-generator
基于现有 SysV 初始化脚本构建目标和服务。在这种情况下,systemd“包装”的初始化脚本是这个文件 - /etc/rc.d/init.d/network
.
目的
就该单元文件的作用而言,它是调出 下指定的网络接口的函数/etc/sysconfig/network
。这是以前使用过的目录,大多数基于 Red Hat 的发行版在 NetworkManager 和 systemd 存在之前都使用过。
Systemd 将调出此目录中定义的所有网络接口,作为与 Red Hat 早期版本(CentOS、Fedora 和 RHEL)的行为方式保持向后兼容的一种方式。
答案2
grep desc -A 1 /etc/rc.d/init.d/network
# description: Activates/Deactivates all network interfaces configured to \
# start at boot time.
动态主机配置协议等