bash: /etc/resolv.conf: 权限不够
时间: 2024-01-01 18:05:36 浏览: 90
这个问题表示你在尝试访问或修改 `/etc/resolv.conf` 文件时遇到了权限不足的错误。这个文件用于配置域名解析的设置。
要解决这个问题,你可以使用管理员权限来访问或修改该文件。你可以尝试以下方法之一:
1. 使用 `sudo` 命令:在命令前加上 `sudo`,然后输入管理员密码,例如:`sudo vi /etc/resolv.conf`。这将以管理员身份运行命令,给予足够的权限。
2. 使用 root 用户:如果你有 root 用户权限,可以使用 `su` 命令切换到 root 用户,然后执行相应的命令,例如:`su -` 之后输入 root 用户密码,然后再运行 `vi /etc/resolv.conf`。
无论哪种方法,都要小心操作 `/etc/resolv.conf` 文件,确保只做必要的更改,并且在完成后记得恢复文件的权限。
相关问题
怎么在/etc/resolv.conf加东西
可以通过以下步骤在/etc/resolv.conf中添加内容:
1. 打开终端并使用root权限登录。
2. 执行以下命令创建文件/etc/resolvconf/resolv.conf.d/tail:
```bash
touch /etc/resolvconf/resolv.conf.d/tail
```
3. 执行以下命令编辑文件/etc/resolvconf/resolv.conf.d/tail并添加需要的DNS服务器地址,例如:
```bash
nameserver 8.8.8.8
nameserver 8.8.4.4
```
4. 执行以下命令更新/etc/resolv.conf文件:
```bash
resolvconf -u
```
这将把/etc/resolvconf/resolv.conf.d/tail中的内容添加到/etc/resolv.conf文件的末尾。
检查/etc/resolv.conf是否为空的shell脚本
#!/bin/bash
if [[ ! -s "/etc/resolv.conf" ]]; then
echo "The file /etc/resolv.conf is empty"
else
echo "The file /etc/resolv.conf is not empty"
fi
Explanation:
This script checks if the file /etc/resolv.conf is empty or not. The "-s" option of the "test" command (also known as "[") returns true if the file exists and has a size greater than zero. The "!" operator negates the test, so the script echoes a message indicating that the file is empty if the test fails (i.e., the file does not exist or has a size of zero). If the test succeeds, the script echoes a message indicating that the file is not empty.