当前位置: 首页 > news >正文

AWS Ubuntu设置DNS解析(解决resolve.conf被覆盖问题)

众所周知:

Ubuntu在域名解析时,最直接使用的是/etc/resolve.conf文件,它是/run/systemd/resolve/resolve.conf的软链接,而对于刚装完的ubuntu系统,该文件的内容如下

ubuntu@ip-172-31-36-184:/etc$ cat resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 172.31.0.2
search ap-northeast-1.compute.internal

第1步, 修改/etc/systemd/resolved.conf,例如:
谷歌的dns=8.8.8.8 cloudflare的dns: 1.1.1.1

ubuntu@ip-172-31-36-184:/etc/systemd$ ls
journald.conf  logind.conf  network  networkd.conf  pstore.conf  resolved.conf  sleep.conf  system  system.conf  timesyncd.conf  user  user.conf
ubuntu@ip-172-31-36-184:/etc/systemd$ cat resolved.conf 
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details[Resolve]
DNS=8.8.8.8 1.1.1.1
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no-negative
#DNSStubListener=yes
#ReadEtcHosts=yes

个人猜测,这个时候,系统在往/run/systemd/resolve/resolv.conf里面写域名解析服务器地址的时候,会从/etc/systemd/resolved.conf中取得DNS相关的配置。

    2,重启域名解析服务systemctl restart systemd-resolvedsystemctl enable systemd-resolved3,备份当前的/etc/resolve.conf,并重新设置/run/systemd/resolve/resolv.conf  到/etc/resolve.conf的软链接mv    /etc/resolv.conf    /etc/resolv.conf.bakln  -s   /run/systemd/resolve/resolv.conf    /etc/

验证:

ubuntu@ip-172-31-36-184:/etc$ cat resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver 172.31.0.2
search ap-northeast-1.compute.internal

参考:
1-华为云开发者论坛
2-csdn https://blog.csdn.net/booklijian/article/details/116491288

在这里插入图片描述

http://www.lryc.cn/news/257325.html

相关文章:

  • 学会这些可以升职加薪!EXCEL基础函数入门【一】
  • kubeadm搭建1.20.7版本k8s
  • LeetCode 力扣: 寻找两个正序数组的中位数 (Javascript)
  • 第 4 部分 — 增强法学硕士的安全性:对越狱的严格数学检验
  • Next.js 中的中间件
  • 一、C#笔记
  • 井盖发生位移怎么办?智能井盖传感器效果
  • go-zero 开发之安装 goctl 及 go-zero 开发依赖
  • win11 CUDA(12.3) + cuDNN(12.x) 卸载
  • 037.Python面向对象_关于抽象类和抽象方法
  • 华为OD机试真题-5G网络建设-2023年OD统一考试(C卷)
  • 【Spring教程25】Spring框架实战:从零开始学习SpringMVC 之 SpringMVC入门案例总结与SpringMVC工作流程分析
  • 设计模式再探——装饰模式
  • 【Python必做100题】之第一题(求两数相加)
  • java面试-Dubbo和zookeeper运行原理
  • Rsync+Sersync
  • Leetcode刷题笔记题解(C++):25. K 个一组翻转链表
  • 从线性回归到神经网络
  • LANDSAT_7/02/T1/RAW的Landsat7_C2_RAW类数据集
  • 绕过360给目标机器添加账户
  • C/C++ 题目:给定字符串s1和s2,判断s1是否是s2的子序列
  • Nginx的stream配置
  • ubuntu 20.04 server 安装 zabbix
  • hive映射es表任务失败,无错误日志一直报Task Transitioned from NEW to SCHEDULED
  • 手眼标定 - 最终精度和误差优化心得
  • pytorch一致数据增强
  • MapReduce
  • Spring Boot 快速入门
  • 什么是神经网络的非线性
  • 前端知识(十四)——浅谈用户体验测试的主要功能