resolv.conf和resolved.conf两者区别
时间: 2025-07-15 10:01:05 浏览: 4
### `resolv.conf` 和 `resolved.conf` 的区别
`resolv.conf` 是 Linux 系统中用于配置 DNS 解析器(Resolver)的核心文件之一,它包含了域名服务器(DNS)、搜索域以及其他与 DNS 解析相关的参数。每当一个程序需要通过域名访问 Internet 上的主机时,系统会使用 Resolver 库函数来查询该文件,并根据其中的配置将域名转换为对应的 IP 地址[^1]。
然而,现代 Linux 系统通常使用网络管理工具(如 `systemd-resolved`、`NetworkManager` 或 `resolvconf`)来动态管理 `/etc/resolv.conf` 文件的内容。这意味着手动对该文件的修改可能会在重启或网络状态变化后被覆盖。例如,在使用 `systemd-resolved` 的系统中,`/etc/resolv.conf` 通常是一个指向 `/run/systemd/resolve/resolv.conf` 的符号链接,而后者的实际内容由 `systemd-resolved` 动态生成[^2]。
与此相对,`resolved.conf` 是 `systemd-resolved` 服务自身的配置文件,通常位于 `/etc/systemd/resolved.conf`。此文件定义了 `systemd-resolved` 服务的行为,包括静态 DNS 配置、默认的搜索域等。用户可以通过编辑该文件来指定全局的 DNS 设置,这些设置随后会被 `systemd-resolved` 应用并反映到 `/run/systemd/resolve/resolv.conf` 中,最终影响系统的 DNS 解析行为[^3]。
简而言之:
- `resolv.conf` 是当前生效的 DNS 配置文件,可能被多个系统组件动态控制。
- `resolved.conf` 是 `systemd-resolved` 的静态配置文件,用于定义其运行时的行为,尤其是 DNS 相关的全局策略。
### 示例:查看 `resolv.conf` 内容
```bash
cat /etc/resolv.conf
```
输出示例:
```
# This file is managed by systemd-resolved(8). Do not edit.
nameserver 8.8.8.8
nameserver 114.114.114.114
search example.com
```
### 示例:修改 `resolved.conf` 配置
```ini
[Resolve]
DNS=8.8.8.8 114.114.114.114
Domains=example.com internal.net
```
修改后需重启服务以应用新配置:
```bash
sudo systemctl restart systemd-resolved
```
此外,确保 `/etc/resolv.conf` 是指向 `/run/systemd/resolve/resolv.conf` 的符号链接:
```bash
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
```
---
阅读全文
相关推荐


















