zoukankan      html  css  js  c++  java
  • [转]ubuntu linux下DNS重启后丢失(不是Network-manager造成的情况)

    • 从网上得知 /etc/resolv.conf中的DNS配置是从/etc/resolvconf/resolv.conf.d/head中加载而来,所以每回改resolv.conf都会失效,在此文件里面已经有说明

    打开/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:

    
    sudo vim /etc/network/interfaces
    dns-nameservers 8.8.8.8
    

    ###方法2:(这个文件默认是空的)

    sudo vim /etc/resolvconf/resolv.conf.d/base
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    

    如果有多个DNS就一行一个

    修改好保存,然后执行

    resolvconf -u
    
    sudo vim /etc/resolvconf/resolv.conf.d/head
    
    • 再看/etc/resolv.conf,最下面就多了2行

    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 8.8.8.8 nameserver 8.8.4.4

    现在此DNS已经生效了,无需重启,当然重启也不会丢失

    此外还有一种方法是修改/etc/resolvconf/resolv.conf.d/headsudo vim /etc/resolvconf/resolv.conf.d/head

    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

    这个文件里提示不要手动修改。。。按照系统提示的说法,不建议改此文件

    ...............................................................认真写每篇博客,如同我对待生活............................................................
  • 相关阅读:
    使用a标签制作tooltips
    使用editorconfig配置你的编辑器
    JointJS绘制流程图
    用highcharts展现你的数据
    css段落首字母下沉
    sklearn框架的系统学习
    numpy删除二维数据矩阵的行和列
    sklearn中机器学习算法评价指标
    sklearn调用逻辑回归算法
    sklearn调用多项式回归
  • 原文地址:https://www.cnblogs.com/itholidaycn/p/6155822.html
Copyright © 2011-2022 走看看