ubuntu

Ubuntu中如何编辑resolv.conf文件

小樊
265
2024-08-08 19:52:39
栏目: 智能运维

  1. 打开终端,输入以下命令打开resolv.conf文件:
sudo nano /etc/resolv.conf
  1. 在打开的文件中,可以编辑nameserver行添加DNS服务器的IP地址,例如:
nameserver 8.8.8.8
nameserver 8.8.4.4
  1. 按下Ctrl + O保存文件,然后按下Ctrl + X退出编辑器。

  2. 如果想要禁止系统更新resolv.conf文件,可以编辑/etc/resolv.conf.head文件,输入以下内容:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but
# only through the symlink at /etc/resolv.conf. To manage resolv.conf(5)
# in a different way, replace this symlink by a static file or a different
# symlink.
#
# See systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
  1. 按下Ctrl + O保存文件,然后按下Ctrl + X退出编辑器。

  2. 重启网络服务以使更改生效:

sudo systemctl restart systemd-resolved.service

0
看了该问题的人还看了