리눅스맨

/sbin/dhclient-script, dhclient-script, resolv.conf 초기화 방지

dhclient-script overwrites resolv.conf 초기화 방지

※ 위 배너를 클릭하면 1달러에 (900원~1800원) 살 수 있는 가성비 레어템 많습니다.

지워도 지워도 계속 똑같은 resolv.conf 파일!!

; generated by /usr/sbin/dhclient-script
search ap-northeast-2.compute.internal
nameserver 172.31.0.2

아마존 AWS EC2 사용자라면 가상화 VM 에서 사설 아이피로 인한 DHCP 환경으로 /usr/sbin/dhclient-script 스크립트에 의해서 자동으로 초기화가 됩니다.

vi /sbin/dhclient-script

vi 편집 프로그램으로 주석 하나 달아주면 해결됩니다.

# After dhclient brings an interface UP with a new IP address, subnet mask, 
    # and routes, in the REBOOT/BOUND states -> search for "dhclient-up-hooks".
    if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] ||
       [ ! "${old_ip_address}" = "${new_ip_address}" ] ||
       [ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] ||
       [ ! "${old_network_number}" = "${new_network_number}" ] ||
       [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] ||
       [ ! "${old_routers}" = "${new_routers}" ] ||
       [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then

        if [ -x ${ETCDIR}/dhclient-${interface}-up-hooks ]; then
            . ${ETCDIR}/dhclient-${interface}-up-hooks
        elif [ -x ${ETCDIR}/dhclient-up-hooks ]; then
            . ${ETCDIR}/dhclient-up-hooks
        fi
    fi

    #제 경우에는 626번째 라인이었습니다.
    #make_resolv_conf

    if [ -n "${new_host_name}" ] && need_hostname; then
        hostname ${new_host_name} || echo "See -nc option in dhclient(8) man page."
    fi

    if [[ ( "${DHCP_TIME_OFFSET_SETS_TIMEZONE}" = [yY1]* ) &&
          ( -n "${new_time_offset}" ) ]]; then
        # DHCP option "time-offset" is requested by default and should be
        # handled.  The geographical zone abbreviation cannot be determined
        # from the GMT offset, but the $ZONEINFO/Etc/GMT$offset file can be
        # used - note: this disables DST.
        ((z=new_time_offset/3600))
        ((hoursWest=$(printf '%+d' $z)))

        if (( $hoursWest < 0 )); then
            # tzdata treats negative 'hours west' as positive 'gmtoff'!
            ((hoursWest*=-1))
        fi

        tzfile=/usr/share/zoneinfo/Etc/GMT$(printf '%+d' ${hoursWest})
        if [ -e ${tzfile} ]; then
            cp -fp ${tzfile} /etc/localtime
/sbin/dhclient-script, dhclient-script, resolv.conf 초기화 방지
dhclient-script overwrites resolv.conf 초기화 방지 3

주석처리하고 네트워크 재실행 하면 이때부터 resolv.conf 계속 유지됩니다.

검색 해보면 chmod 444 준다니 여러 방법 보이지만 버전이 오르면서 그러한 부분들도 모두 되지 않습니다.

2023년 2월 기준으로 현재는 위 방법으로 해결하고 있으니 도움되셨으면 합니다.

모든 부분들을 직접 해결하다보니 시간이 많이 걸리며 더디게 걸어가고 있지만…

계속 성장중입니다.

AWS EC2 인스턴스에서 네임서버 운영중인데 resolv.conf 파일이 변하니깐 DNS가 오락가락 했네요.

서버때문에 2~3개월 다른일 못하고 있네요.

곧 마무리되는대로 다시 돌아오겠습니다.

오늘은 백업서버 자동화, DNS 서버 안정화 작업했습니다.

일단 모두 해결되었습니다.


게시됨

카테고리

,

작성자

태그: