[Linux] [网络] Linux如何配置DNS地址

方法1:直接编辑resolv.conf文件

  1. 如果是Ubnutu系统,需要先解除软连接,确保持久生效,不被systemd-resolved覆盖
unlink /etc/resolv.conf
  1. 关闭systemd-resolved服务避免影响
systemctl stop systemd-resolved
  1. 直接编辑文件/etc/resolv.conf
vim /etc/resolv.conf

写下内容:

nameserver 8.8.8.8
nameserver 114.114.114.114

image

  1. 测试
    直接curl拉取常规地址,如百度和谷歌,能返回结果则设置正确
# 国内环境
curl www.baidu.com
# 外网环境
curl www.google.com

百度通常返回结果:
image
谷歌通常返回结果:
image

方法2:使用systemd-resolved服务

  1. 编辑文件vim /etc/systemd/resolved.conf
vim /etc/systemd/resolved.conf
  1. 写入内容如下:
[Resolve]
DNS=114.114.114.114 8.8.8.8

image

  1. 重启服务
sudo systemctl enable systemd-resolved
sudo systemctl restart systemd-resolved
  1. 检查服务状态
systemctl status systemd-resolved

image

posted on 2025-10-09 17:50  风惊庭前叶  阅读(16)  评论(0)    收藏  举报