새로운 resolv.conf를 작성하기 위해 DHCP 클라이언트를 원격으로 다시로드하는 방법은 무엇입니까? 동일한 작업을 수행 하면

dnsmasq(8)개인 DHCP기반 네트워크 의 데비안 GNU / 리눅스 시스템에서 구성하려고 합니다. 로컬, 수동 설정 dnsmasq중-istelf 설치 후 -간단하게 라인을 포함 할 수 있습니다

prepend domain-name-servers 127.0.0.1;

에서 /etc/dhcp/dhclient.conf다시 시작 네트워킹. 여기에는 로컬 호스트가 포함 /etc/resolv.conf되며 하나는 준비가 된 것입니다. (또한 참조 : http://wiki.debian.org/HowTo/dnsmasq#Local_Caching )

그러나 특히 구성 관리 소프트웨어로 작업 할 때 원격으로 동일한 작업을 수행 하면 네트워크 연결이 끊어 질 수 있습니다. 목표는 네트워크 재시작이 아니라 resolv.conf.. 업데이트입니다 .

어떻게 힘이 있습니다 dhclient(8)업데이트 resolv.conf까지 네트워크 연결을 유지하고 실행하는 동안?

[편집하다]

아래에서 나를 위해 일한 스크립트를 찾으십시오.

if grep '^\s*nameserver\>.\+\<127\.0\.0\.1\>' /etc/resolv.conf >/dev/null; then
    : # do nothing
else
    grep -v '^\s*nameserver\>' /etc/resolv.conf > /tmp/resolv.conf.new
    echo "nameserver 127.0.0.1" >> /tmp/resolv.conf.new
    grep '^\s*nameserver\>' /etc/resolv.conf >> /tmp/resolv.conf.new
    mv -f /tmp/resolv.conf.new /etc/resolv.conf
fi

그것은 어색합니다-나는 여전히 더 나은 해결책을 찾고 있습니다.



답변

ansible을 통해 dnsmasq를 설정할 때도 같은 문제에 직면했습니다. debian jessie에서는 dhclient.conf를 업데이트하고 다음을 수행 할 수 있습니다.

/usr/bin/killall dhclient
dhclient INTERFACE

또는 원하는 경우 :

dhclient -x
dhclient INTERFACE

임대가 만료되고 다른 IP 주소를 얻지 않으면 연결이 끊어지지 않습니다.

구성 관리에 대해 언급했습니다. 사용 가능한 경우 내 플레이 북의 관련 부분은 다음과 같습니다.

tasks:
- name: Ensure a correct resolv.conf
  template: src=templates/resolv.conf.j2 dest=/etc/resolv.conf

- name: Ensure dhclient config wont mess up my resolv.conf
  template: src=dhclient.conf.j2 dest=/etc/dhcp/dhclient.conf
  notify: Kill dhclient

handlers:
- name: Kill dhclient
  command: /usr/bin/killall dhclient
  ignore_errors: yes
  changed_when: false

dhclient를 종료 한 후 다시 시작하지 않습니다. 이것은 내 환경에서 잘 작동하지만 YMMV입니다. dhclient 중지 / 시작을 처리하기 위해 스크립트를 복사하고 처리기에서 해당 작업을 호출하는 다른 작업을 추가 할 수 있습니다 (아마도 {{ansible_default_ipv4.interface}}인터페이스 이름을 얻는 데 사용 ).

dhclient.conf템플릿은 다음과 같습니다.

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers, host-name, interface-mtu, rfc3442-classless-static-routes, ntp-servers, dhcp6.fqdn, dhcp6.sntp-servers;

따라서 대부분의 기본 데비안 dhclient.conf은 dns 관련 지시어를 사용합니다.


답변