• 不要直接手动修改文件 /etc/resolv.conf

安装好Ubuntu之后设置了静态IP地址,再重启后就无法解析域名。想重新设置一下DNS,打开/etc/resolv.conf

cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

内容是一段警告:说这个文件是resolvconf程序动态创建的,不要直接手动编辑,修改将被覆盖。

root@Ubuntu14:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.138
nameserver 100.100.2.136
options timeout:2 attempts:3 rotate single-request-reopen
root@Ubuntu14:~#

ubuntu修改DNS有如下两种方法。

  • 方法一:修改文件/etc/resolvconf/resolv.conf.d/base
root@Ubuntu14:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.138
nameserver 100.100.2.136
options timeout:2 attempts:3 rotate single-request-reopen
root@Ubuntu14:~# vim /etc/resolvconf/resolv.conf.d/base
root@Ubuntu14:~# cat !$
cat /etc/resolvconf/resolv.conf.d/base
nameserver 223.5.5.5
nameserver 223.6.6.6
root@Ubuntu14:~# resolvconf -u
root@Ubuntu14:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.138
nameserver 100.100.2.136
nameserver 223.5.5.5
options timeout:2 attempts:3 rotate single-request-reopen
root@Ubuntu14:~# nslookup www.baidu.com
Server: 100.100.2.138
Address: 100.100.2.138#53 Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 220.181.112.244
Name: www.a.shifen.com
Address: 220.181.111.188 root@Ubuntu14:~#
  • 方法二:修改文件 /etc/network/interfaces
root@iZbp1b66g5htibj2m7yyv3Z:~# cat /etc/network/interfaces

auto lo
iface lo inet loopback auto eth0
iface eth0 inet dhcp dns-nameservers 223.5.5.5 # 在最后添加这一行
  • 常用命令

linux刷新dns的缓存方法是:  sudo /etc/init.d/nscd restart

最暴力的方法刷dns,重启网络:  sudo /etc/init.d/networking restart

查看当前DNS解析情况:

  nslookup www.baidu.com

  dig | grep SERVER

root@iZbp1b66g5htibj2m7yyv3Z:~# /etc/init.d/nscd restart
* Restarting Name Service Cache Daemon nscd [ OK ]
root@iZbp1b66g5htibj2m7yyv3Z:~# /etc/init.d/networking restart
stop: Job failed while stopping
start: Job is already running: networking
root@iZbp1b66g5htibj2m7yyv3Z:~# dig |grep SERVER
;; SERVER: 100.100.2.138#53(100.100.2.138)
root@iZbp1b66g5htibj2m7yyv3Z:~# nslookup www.baidu.com
Server: 100.100.2.138
Address: 100.100.2.138#53 Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 220.181.111.188
Name: www.a.shifen.com
Address: 220.181.112.244 root@iZbp1b66g5htibj2m7yyv3Z:~#
  • CoreOS修改DNS

1)  vim /etc/resolv.conf

2)  vim /etc/systemd/resolved.conf

3)  systemctl restart systemd-resolved

4)  reboot

coreos1 ~ # cat /etc/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 DNS servers.
#
# 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 223.5.5.5
nameserver 223.6.6.6
search openstacklocal
coreos1 ~ # cat /etc/systemd/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=223.5.5.5 223.6.6.6      # 用空格分隔多个dns
#FallbackDNS=
#Domains=
LLMNR=no               # yes改为no
#DNSSEC=allow-downgrade
#Cache=yes
coreos1 ~ # systemctl restart systemd-resolved
coreos1 ~ # dig |grep SERVER
;; SERVER: 223.5.5.5#53(223.5.5.5)
coreos1 ~ # reboot


  

最新文章

  1. tyvj1193 括号序列
  2. maven工程pom.xml文件解读
  3. ActionScript学习笔记
  4. jquery miniui , 普加甘特图,流程管理
  5. oc-数据模型的建立
  6. 未能加载文件或程序集“System.Web.Razor”或它的某一个依赖项。文件或目录损坏且无法读取。
  7. [resource]Github上维护的一个机器学习相关的框架,库和工具列表
  8. uva 11235
  9. (转)在SQL中取出字符串中数字部分或在SQL中取出字符部分
  10. Python PIL创建文字图片
  11. linux下curl编程
  12. fancybox关闭弹出窗口parent.$.fancybox.close();
  13. php和java中的加密和解密
  14. Redis~Linux环境下的部署
  15. Nginx实现负载均衡功能
  16. macOS 10.14虚拟机安装教程
  17. 洛谷 P3327 【[SDOI2015]约数个数和】
  18. python lxml库生成xml文件-节点命名空间问题
  19. 构建eureka-server异常ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
  20. crm的知识点整理

热门文章

  1. git合作开发流程
  2. awk文本
  3. for,while,until三种循环
  4. 跟我一起写 Makefile(十二)
  5. Vue-cli4 唤醒摄像头扫描二维码
  6. Abp vNext 基础篇丨分层架构
  7. 【XXE学习】XML外部实体注入
  8. VRRP的基本配置
  9. 生成树-RSTP基础配置
  10. STM32—DAC配置