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

相關文章
相關標籤/搜索