• CentOS7.6 鲜为人知的/etc/resolv.conf 之 /etc/resolv.conf.save (保持/etc/resolv.conf不被修改:/etc/dhcp/dhclient-enter-hooks 无效之/etc/resolv.conf被清空的特殊案例)


    目的:

    用户可以自定义/etc/resolv.conf内容,且不被系统修改。

    常规方法1:

    /etc/sysconfig/network-scripts/ifcfg-eth0 网卡配置文件中增加PEERDNS=no

    注意:云平台受cloud-init 管理网卡,制作镜像后创建新机器会被重置

    # Created by cloud-init on instance boot automatically, do not edit.
    #
    BOOTPROTO=dhcp
    DEVICE=eth0
    NM_CONTROLLED=no
    ONBOOT=yes
    TYPE=Ethernet
    USERCTL=no
    PEERDNS=no

    常规方法2:

    创建dhcp 配置文件 /etc/dhcp/dhclient-enter-hooks 写入空函数

    #!/bin/sh
    make_resolv_conf(){
    :
    }

    chmod +x /etc/dhcp/dhclient-enter-hooks

     常规方法3:

    类似2,直接修改dhcp脚本:/usr/sbin/dhclient-script将里面的make_resolv_conf函数置空同上

     然并卵..............

    案例1:

    方法2.方法3 仅配置 /etc/dhcp/dhclient-enter-hooks无效。重启系统后/etc/resolv.conf 并没有保持住,反而被置空

     

     查看是否有备份文件/etc/resolv.conf.save

    [root@localhost ~]# ls -l /etc/resolv.conf*
    -rw-r--r-- 1 root root 1 Dec 18 17:10 /etc/resolv.conf
    -rw-r--r-- 1 root root 1 Dec 18 17:13 /etc/resolv.conf.save
    [root@localhost ~]# cat /etc/resolv.conf.save 
    
    [root@localhost ~]# 

    解决:

      删除/etc/resolv.conf.save

     原因解析:

    /etc/resolv.conf.save 为备份文件,当dhcp脚本make_resolv_conf 为空时,直接从.save文件进行复制,导致配置无效。

    案例2:

      https://www.cnblogs.com/xulingjie/p/9227799.html

      每次重启服务器后,/etc/resolv.conf文件就被自动还原了,最后发现是被Network Manager修改了。

    查看Network Manager服务状态

    systemctl status  NetworkManager

    停止Network Manager服务

    systemctl stop  NetworkManager

    关闭Network Manager开机启动

    systemctl disable  NetworkManager
  • 相关阅读:
    hdu 2594 Simpsons’ Hidden Talents
    hdu 1358 Period
    hdu 3746 Cyclic Nacklace
    理解KMP算法
    ural 1039 Anniversary Party
    ural 1018 Binary Apple Tree
    RowDataBound事件
    aspxGridview 根据单元格值得不同,设置单元格字体的颜色(设置和读取值)
    Asp.Net中GridView加入鼠标滑过的高亮效果和单击行颜色改变
    GridView的行颜色高亮显示(包括满足条件的行)
  • 原文地址:https://www.cnblogs.com/zhangmingda/p/14156005.html
Copyright © 2020-2023  润新知