码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS7 dns自动覆盖

时间:2019-09-24 13:50:12      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:自动   present   dhclient   centos   with   item   block   导致   inf   

1. 现象

CentOS7 阿里云ECS系统重启后,/etc/resolv.conf 会被dhclient 或者NetworkManager还原为默认配置/清空

  

2. 解决方案

2.1 机制

  1. PEERDNS=yes|no 允许|禁止/etc/resolv.conf 重启/更新网络 被覆盖

  2. 当开启NetworkManager.service 时, PEERDNS是不生效的,通过设置dns=none解决

  3. 阿里云ECS内部服务不要开启NetworkManager, 可能导致网络不可用

2.2 方案

https://www.cyberciti.biz/faq/dhclient-etcresolvconf-hooks/

3. 最佳实践

系统初始化时:
1. /etc/resolv.conf template一份
2. 通过ansible的lineinfile 只增加一行PEERDNS=no
- block:
  - name: Modify /etc/resolv.conf
    template:
      src: resolv.conf.j2
      dest: /etc/resolv.conf
      mode: 0644
      owner: root
      group: root


  - name: Install common operate utils
    yum:
      name: "{{ item }}"
      update_cache: yes
    with_items: ["htop", "iftop", "nload", "iptraf", "dstat", "iotop", "screen", "hping3"]

  - name: Modify ifcfg-etho to forbid Autoupdate DNS
    lineinfile:
      dest: /etc/sysconfig/network-scripts/ifcfg-eth0
      state: present
      line: ‘PEERDNS=no‘
      mode: 0644
      owner: root
      group: root
  when: ansible_distribution == "CentOS"
  tags: update_dns

  

CentOS7 dns自动覆盖

标签:自动   present   dhclient   centos   with   item   block   导致   inf   

原文地址:https://www.cnblogs.com/leesirc/p/11577751.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!