Ubuntu 18.04设置dns

最近使用了最新版的ubuntu 18.04运行一些服务,而后发现服务器常常出现网络不通的状况,主要是一些域名没法解析。php

检查/etc/resolv.conf,发现以前修改的nameserver老是会被修改成127.0.0.53,不管是改为啥,过段时间,总会变回来。linux

查看/etc/resolv.conf这个文件的注释,发现开头就写着这么一行:ubuntu

# This file is managed by man:systemd-resolved(8). Do not edit.

这说明这个文件是被systemd-resolved这个服务托管的。缓存

经过netstat -tnpl| grep systemd-resolved查看到这个服务是监听在53号端口上。bash

查了下,这个服务的配置文件为sudo leafpad /etc/systemd/resolved.conf,大体内容以下:服务器

[Resolve] DNS=1.1.1.1 1.0.0.1 #FallbackDNS= #Domains= LLMNR=no #MulticastDNS=no #DNSSEC=no #Cache=yes #DNSStubListener=yes

若是咱们要想让/etc/resolve.conf文件里的配置生效,须要添加到systemd-resolved的这个配置文件里DNS配置项(如上面的示例,已经完成修改),而后重启systemd-resolved服务便可。网络

另外一种更简单的办法是,咱们直接停掉systemd-resolved服务,这样再修改/etc/resolve.conf就能够一直生效了。dom

 

chongqi cmdide

 sudo systemctl restart systemd-resolvedpost

clean dns

sudo /etc/init.d/dns-clean start

 

中止方法

sudo systemctl disable systemd-resolved.service
sudo service systemd-resolved stop
 https://superuser.com/questions/1153203/ubuntu-17-04-systemd-resolved-dns-lookups-randomly-fail
 
网络检测
1. sudo lshw -numeric -class network
2. sudo ip addr show
3. sudo ip route show
4. sudo tracepath forum.ubuntu.org.cn
5. sudo traceroute forum.ubuntu.org.cn
http://forum.ubuntu.org.cn/viewtopic.php?t=487423
 

从 NetworkManager 切换到 Systemd-networkd

从 NetworkManager 切换到 systemd-networkd 其实很是简答(反过来也同样)。

首先,按照下面这样先停用 NetworkManager 服务,而后启用 systemd-networkd。

  1. sudosystemctl disable NetworkManager
  2. sudosystemctl enable systemd-networkd

你还要启用 systemd-resolved 服务,systemd-networkd用它来进行域名解析。该服务还实现了一个缓存式 DNS 服务器。

  1. sudosystemctl enable systemd-resolved
  2. sudosystemctl start systemd-resolved

当启动后,systemd-resolved 就会在 /run/systemd 目录下某个地方建立它本身的 resolv.conf。可是,把 DNS 解析信息存放在 /etc/resolv.conf 是更广泛的作法,不少应用程序也会依赖于 /etc/resolv.conf。所以为了兼容性,按照下面的方式建立一个到 /etc/resolv.conf 的符号连接。

  1. sudorm/etc/resolv.conf
  2. sudoln-/run/systemd/resolve/resolv.conf /etc/resolv.conf

 

 

https://www.linuxidc.com/Linux/2015-11/125430.htm

 

sudo dpkg-reconfigure resolvconf

 

sudo systemctl restart systemd-resolved



/etc/resolv.conf
sudo systemctl disablesystemd-resolved.service

nameserver 8.8.8.8 << or another if you don't trust google nameserver 8.8.4.4

sudo service systemd-resolved stop
 

 https://superuser.com/questions/1153203/ubuntu-17-04-systemd-resolved-dns-lookups-randomly-fail

Ubuntu 17.04 systemd-resolved DNS lookups randomly fail

相关文章
相关标签/搜索