centos7.1 /etc/resolv.conf刷新问题

问题描述

今天同事告诉我一个奇怪的问题: 当他在/etc/resolv.conf下添加options single-request-reopen(解决dns解析慢的问题)此行参数时,第一次重启network没问题:

1
2
3
options single-request-reopen
; generated by /usr/sbin/dhclient-script
nameserver 10.0.2.3

当第二次重启network时除了options行其他的都会删掉!

问题原因

这是initscripts的一个bug,bug已经在initscripts-9.49.25-1.el7这个版本修复
redhat bugzilla

问题根源

At first the options from the existing /etc/resolv.conf are saved. (This is why this bug may only appear after a reboot and not on the first boot).

1
2
3
4
s=$(/bin/grep '^[\ \ ]*option' /etc/resolv.conf 2>/dev/null);
if [ "x$s" != "x" ]; then
s="$s"$'\n';
fi;

很明显除了option行全替换了.