Linux ETC

가상화 기반 DHCP 환경의 리눅스 서버에서 /etc/resolv.conf 파일을 수정해도
서버 리부팅이나 network restart시 resolv.conf 파일 내용이 초기화 되는 현상이 있습니다.

이것은 버그나 오류가 아니며, resolv.conf 파일 상단에 보면 아래와 같은 문구를 볼수 있습니다.

; generated by /sbin/dhclient-script

 

DHCP를 통해 IP를 자동으로 할당 받을 때 dhclient-script에 의해 resolv.conf 파일이 재생성된다는 뜻입니다.
resolv.conf 파일의 재생성을 원치 않을 경우 /sbin/dhclient-script 파일 내용 중 ‘make_resolv_conf’ 함수를 호출하는 부분을 찾아 주석 처리해주면 됩니다.

예제1)


# vi /sbin/dhclient-script

    337             ifconfig $interface:0- inet 0
    338             ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
    339             /sbin/ip route replace ${alias_ip_address}/32 dev $interface:0
    340         fi
    341     fi
    342     if [ -z "${dhc_dbus}" ] || (( ( dhc_dbus & 1 ) != 1 )); then
    343 #        make_resolv_conf  <--------------- 주석 처리
    344
    345         if [ -n "$new_host_name" ] && need_hostname; then
    346             hostname $new_host_name