This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Automatically populate resolv.conf when new DNS is acquired

On 2018-06-26 04:33, john doe wrote:
> In gnupg2 the use of dirmngr utility is required to interact with a keyserver.
> Dirmngr requires that '/etc/resolv.conf' be populated with my name servers.
> That means that everytime the dns changes (new network ...) I need to manually
> edit that file.
> How can I let Cygwin update that file whenever the DNS is changed?

Attached an awk script to generate resolv.conf from Windows ipconfig /all
output, run from .cygwin_profile (sourced under Cygwin from login .bash_profile)
using the stanza below: it only replaces an existing writable /etc/resolv.conf
when the content changes - touch, chown, chmod /etc/resolv.conf to enable.

# update /etc/resolv.conf if changed
test -w $c					&& \
i=$(/usr/bin/which -- ipconfig)			&& \
r=$(/usr/bin/which -- resolv.awk)		&& \
t=$(/bin/mktemp -t -- resolv.conf.$$.XXXXXXXX)  && \
if $i /all | $r      >  $t; then
    /usr/bin/cmp -s -- $t $c	|| \
    /bin/cp -fv     -- $t $c
    /bin/rm -f	    -- $t

unset c i r t

This could be used in a bash script run from a Windows scheduled task when a
relevant DHCP event occurs: you can find DHCP events by checking Windows Admin
Tools/Event Viewer/Window Logs/System/Filter Current Log/Event
Sources/Dhcp-Client,DHCPv6-Client, or a similar PowerShell script.

Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

Attachment: resolv.awk
Description: Text document

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]