1. 现象
CentOS7 阿里云ECS系统重启后,/etc/resolv.conf 会被dhclient 或者NetworkManager还原为默认配置/清空
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