• 不要直接手动修改文件 /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程序动态创建的,不要直接手动编辑,修改将被覆盖。

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

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

  • 方法一:修改文件/etc/resolvconf/resolv.conf.d/base
  1. root@Ubuntu14:~# cat /etc/resolv.conf
  2. # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
  3. # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
  4. nameserver 100.100.2.138
  5. nameserver 100.100.2.136
  6. options timeout:2 attempts:3 rotate single-request-reopen
  7. root@Ubuntu14:~# vim /etc/resolvconf/resolv.conf.d/base
  8. root@Ubuntu14:~# cat !$
  9. cat /etc/resolvconf/resolv.conf.d/base
  10. nameserver 223.5.5.5
  11. nameserver 223.6.6.6
  12. root@Ubuntu14:~# resolvconf -u
  13. root@Ubuntu14:~# cat /etc/resolv.conf
  14. # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
  15. # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
  16. nameserver 100.100.2.138
  17. nameserver 100.100.2.136
  18. nameserver 223.5.5.5
  19. options timeout:2 attempts:3 rotate single-request-reopen
  20. root@Ubuntu14:~# nslookup www.baidu.com
  21. Server: 100.100.2.138
  22. Address: 100.100.2.138#53
  23.  
  24. Non-authoritative answer:
  25. www.baidu.com canonical name = www.a.shifen.com.
  26. Name: www.a.shifen.com
  27. Address: 220.181.112.244
  28. Name: www.a.shifen.com
  29. Address: 220.181.111.188
  30.  
  31. root@Ubuntu14:~#
  • 方法二:修改文件 /etc/network/interfaces
  1. root@iZbp1b66g5htibj2m7yyv3Z:~# cat /etc/network/interfaces
  2.  
  3. auto lo
  4. iface lo inet loopback
  5.  
  6. auto eth0
  7. iface eth0 inet dhcp
  8.  
  9. 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

  1. root@iZbp1b66g5htibj2m7yyv3Z:~# /etc/init.d/nscd restart
  2. * Restarting Name Service Cache Daemon nscd [ OK ]
  3. root@iZbp1b66g5htibj2m7yyv3Z:~# /etc/init.d/networking restart
  4. stop: Job failed while stopping
  5. start: Job is already running: networking
  6. root@iZbp1b66g5htibj2m7yyv3Z:~# dig |grep SERVER
  7. ;; SERVER: 100.100.2.138#53(100.100.2.138)
  8. root@iZbp1b66g5htibj2m7yyv3Z:~# nslookup www.baidu.com
  9. Server: 100.100.2.138
  10. Address: 100.100.2.138#53
  11.  
  12. Non-authoritative answer:
  13. www.baidu.com canonical name = www.a.shifen.com.
  14. Name: www.a.shifen.com
  15. Address: 220.181.111.188
  16. Name: www.a.shifen.com
  17. Address: 220.181.112.244
  18.  
  19. root@iZbp1b66g5htibj2m7yyv3Z:~#
  • CoreOS修改DNS

1)  vim /etc/resolv.conf

2)  vim /etc/systemd/resolved.conf

3)  systemctl restart systemd-resolved

4)  reboot

  1. coreos1 ~ # cat /etc/resolv.conf
  2. # This file is managed by man:systemd-resolved(8). Do not edit.
  3. #
  4. # This is a dynamic resolv.conf file for connecting local clients directly to
  5. # all known DNS servers.
  6. #
  7. # Third party programs must not access this file directly, but only through the
  8. # symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
  9. # replace this symlink by a static file or a different symlink.
  10. #
  11. # See man:systemd-resolved.service(8) for details about the supported modes of
  12. # operation for /etc/resolv.conf.
  13.  
  14. nameserver 223.5.5.5
  15. nameserver 223.6.6.6
  16. search openstacklocal
  17. coreos1 ~ # cat /etc/systemd/resolved.conf
  18. # This file is part of systemd.
  19. #
  20. # systemd is free software; you can redistribute it and/or modify it
  21. # under the terms of the GNU Lesser General Public License as published by
  22. # the Free Software Foundation; either version 2.1 of the License, or
  23. # (at your option) any later version.
  24. #
  25. # Entries in this file show the compile time defaults.
  26. # You can change settings by editing this file.
  27. # Defaults can be restored by simply deleting this file.
  28. #
  29. # See resolved.conf(5) for details
  30.  
  31. [Resolve]
  32. DNS=223.5.5.5 223.6.6.6      # 用空格分隔多个dns
  33. #FallbackDNS=
  34. #Domains=
  35. LLMNR=no               # yes改为no
  36. #DNSSEC=allow-downgrade
  37. #Cache=yes
  38. coreos1 ~ # systemctl restart systemd-resolved
  39. coreos1 ~ # dig |grep SERVER
  40. ;; SERVER: 223.5.5.5#53(223.5.5.5)
  41. coreos1 ~ # reboot
  1.  
  1.  

  

Ubuntu / CoreOS修改DNS配置的更多相关文章

  1. Linux 如何查看修改DNS配置

    DNS服务器介绍 DNS是计算机域名系统(Domain Name System 或Domain Name Service) 的缩写,它是由域名解析器和域名服务器组成的.域名服务器是指保存有该网络中所有 ...

  2. [转载]--Ubuntu下修改DNS重启也能用的方法

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

  3. Ubuntu 14.04 DNS 配置

    最近得到一个比较好用的DNS,每次重启后都修改DNS配置文件 /etc/resolv.conf 重启就会失效 从网上得知 /etc/resolv.conf中的DNS配置是从/etc/resolvcon ...

  4. Ubuntu怎么修改DNS

    有时候会出现配置好网络之后,可以ping通网关却ping不通www.baidu.com orangepi@orangepi3:~$ ping 192.168.1.1 PING 192.168.1.1 ...

  5. ubuntu(Mint-17)修改dns

    国内默认dns常被劫持,所以需要修改: $ sudo vi /etc/network/interfaces 在下面添加一行: dns-nameservers 8.8.8.8 8.8.4.4 然后,网上 ...

  6. Ubuntu下修改DNS重启也能用的方法

    1.通过修改:/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)实现 内容填上需要修改的nameserver

  7. cmd命令快速修改dns

    新建cmd文件,修改红色ip部分,以 ANSI 编码保存,双击运行即可快速修改dns配置 netsh interface ip set dns "本地连接" source=stat ...

  8. Cent OS 修改网卡配置

    进入网卡修改界面 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 描述网卡设备名称 BOOTPROTO=static 静态IP,这里一 ...

  9. CentOS 7设置静态IP并修改DNS

    1. 设置静态IP 首先需要确定网线插在服务器的哪一个网络接口上,接口旁边一般都有写.我这边是插在1号接口上的. 然后修改网络配置文件,文件位于 /etc/sysconfig/network-scri ...

随机推荐

  1. 『go成长之路』 defer 作用、典型用法以及多个defer调用顺序,附加defer避坑点,拿来吧你

    预习内容 defer 的作用有哪些? 多个 defer 的执行顺序是怎样的? defer,return,函数返回值 三者之间的执行顺序 defer的作用 go中的defer是延迟函数,一般是用于释放资 ...

  2. vue 源码详解(二): 组件生命周期初始化、事件系统初始化

    vue 源码详解(二): 组件生命周期初始化.事件系统初始化 上一篇文章 生成 Vue 实例前的准备工作 讲解了实例化前的准备工作, 接下来我们继续看, 我们调用 new Vue() 的时候, 其内部 ...

  3. Vue系列-02-axios

    vue.js和aixos.js # https://blog-static.cnblogs.com/files/lichengguo/vue.js # 下载该文件,保存的路径为代码同级目录 js/vu ...

  4. Java Lambda 表达式源码分析

    基本概念 Lambda 表达式 函数式接口 方法引用 深入实现原理 字节码 为什么不使用匿名内部类? invokedynamic 总结 参考链接 GitHub 项目 Lambda 表达式是什么?JVM ...

  5. IDEA永久使用!!(很全)

    IDEA虽然好用,但是下载后只能试用30天,烦恼呀!所以今天就带来IDEA的激活版来帮助大家摆脱30天的苦恼! 准备工作: 破解所需要的软件和jar都在网盘里,需要的自行下载,在这里idea安装就不带 ...

  6. PyCharm启动报错 TypeError: unsupported operand type(s) for /: ‘str’ and ‘str’ 解决

    这个提示大概是说:"类型错误:不支持操作类型为字符串和字符串",直接把两个字符串(BASE_DIR = os.path.dirname(os.path.dirname(os.pat ...

  7. noip18

    T1 来自cf原题 考场直接暴力枚举 \(A,B\),15pts. 正解: 首先时间的表达式,\(T=\frac{A}{a_{i}}+\frac{B}{b_{i}}\),然后以\(\frac{1}{a ...

  8. 安装RHEL7配置本地yum源 -- yum不能安装时,在本地安装,亲测成功

    RHEL7 本地yum源配置我们在安装Redhat的时候一般都不会填写注册信息,因为该产品是要购买的,所以我们在使用安装好的Redhat时有的功能是受限的,使用yum源install就是其中之一.那么 ...

  9. 9、二进制安装K8s之增加node

    二进制安装K8s之增加node 1.复制文件,要部署几台就直接复制即可 #二进制文件 scp /data/k8s/bin/{kubelet,kube-proxy} root@192.168.100.1 ...

  10. mysql查询附近门店

    mysql 查询一个地点(经纬度) 附近N公里内的数据.(根据一个地点的经纬度查询这个地点方圆几公里内的数据)1.创建测试表 CREATE TABLE `location` ( `id` int(10 ...