* Autamatically populate resolv.conf when new DNS is acquired @ 2018-06-26 16:11 john doe 2018-06-26 19:23 ` Automatically " Brian Inglis 2018-06-27 11:01 ` Autamatically " Andrey Repin 0 siblings, 2 replies; 6+ messages in thread From: john doe @ 2018-06-26 16:11 UTC (permalink / raw) To: cygwin Hi, 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? -- John Doe -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Automatically populate resolv.conf when new DNS is acquired 2018-06-26 16:11 Autamatically populate resolv.conf when new DNS is acquired john doe @ 2018-06-26 19:23 ` Brian Inglis 2018-06-27 11:08 ` john doe 2018-06-27 11:01 ` Autamatically " Andrey Repin 1 sibling, 1 reply; 6+ messages in thread From: Brian Inglis @ 2018-06-26 19:23 UTC (permalink / raw) To: cygwin [-- Attachment #1: Type: text/plain, Size: 1372 bytes --] 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 c=/etc/resolv.conf 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 fi 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 #2: resolv.awk --] [-- Type: text/plain, Size: 766 bytes --] #!/usr/bin/awk -f # resolv.awk - create Windows resolv.conf from ipconfig /all output { sub( /\r/, "", $NF) } # trim \r # collect DNS domain suffixes /D[Nn][Ss]\sSuffix[^:]*:\s\S/ { domain[$NF] = $NF } # collect DNS search suffixes /Search\sList[^:]*:\s\S/ { search[$NF] = $NF } # collect DNS server IP addresses /DNS\sServers[^:]*:\s\S/ { dns = 1 } # enable dns && $NF ~ /^[0-9.]+$/ { nameserver[++ns] = $NF } # collect dns && $NF !~ /^[0-9.]+$/ { dns = 0 } # disable # output unique resolv.conf entries END { for (n = 1; n <= ns; ++n) { print "nameserver", nameserver[n] } for (d in domain) { print "domain", domain[d] } p = "search" for (s in search) { printf "%s %s", p, search[s] p = "" } if (!p) { print p } } [-- Attachment #3: Type: text/plain, Size: 219 bytes --] -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Automatically populate resolv.conf when new DNS is acquired 2018-06-26 19:23 ` Automatically " Brian Inglis @ 2018-06-27 11:08 ` john doe 2018-06-28 4:40 ` Brian Inglis 0 siblings, 1 reply; 6+ messages in thread From: john doe @ 2018-06-27 11:08 UTC (permalink / raw) To: cygwin Good morning Brian, bottom posting. On 6/26/2018 4:18 PM, Brian Inglis wrote: > 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 > c=/etc/resolv.conf > 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 > fi > > 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. > Thanks for the awk script and the explanation on how to use it! :) By Windows Admin you mean "Windows Admin Center"? I'm using Cygwin on a laptop (win 7 pro) and sadly, if I'm not mistaking, "Windows Admin" is not available on non-server platform. If I can't find a way to determine when my DNS changes I can clearly emulate an hourly cron job by using "task scheduler". Many thanks for the task scheduler hint and for your help. -- John Doe -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Automatically populate resolv.conf when new DNS is acquired 2018-06-27 11:08 ` john doe @ 2018-06-28 4:40 ` Brian Inglis 0 siblings, 0 replies; 6+ messages in thread From: Brian Inglis @ 2018-06-28 4:40 UTC (permalink / raw) To: cygwin On 2018-06-27 03:31, john doe wrote: > Good morning Brian, bottom posting. > By Windows Admin you mean "Windows Admin Center"? Line wrapped - Windows Admin Tools - on W10 - or search for event (log) viewer > I'm using Cygwin on a laptop (win 7 pro) and sadly, if I'm not mistaking, > "Windows Admin" is not available on non-server platform. May be Administrative Tools on W7 > If I can't find a way to determine when my DNS changes I can clearly emulate > an hourly cron job by using "task scheduler". If you're using DHCP it could potentially change when your lease expires, sometimes a couple of days, (depends on your router settings or ISP: my external IP changes every few months, internal and DNS never) or if on WiFi, when you connect to a new AP. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Autamatically populate resolv.conf when new DNS is acquired 2018-06-26 16:11 Autamatically populate resolv.conf when new DNS is acquired john doe 2018-06-26 19:23 ` Automatically " Brian Inglis @ 2018-06-27 11:01 ` Andrey Repin 2018-06-27 16:10 ` john doe 1 sibling, 1 reply; 6+ messages in thread From: Andrey Repin @ 2018-06-27 11:01 UTC (permalink / raw) To: john doe, cygwin Greetings, john doe! > 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. Looks like an upstream bug. /etc/resolv.conf is not a required file for DNS resolution. > 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? -- With best regards, Andrey Repin Wednesday, June 27, 2018 10:44:06 Sorry for my terrible english... -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Autamatically populate resolv.conf when new DNS is acquired 2018-06-27 11:01 ` Autamatically " Andrey Repin @ 2018-06-27 16:10 ` john doe 0 siblings, 0 replies; 6+ messages in thread From: john doe @ 2018-06-27 16:10 UTC (permalink / raw) To: cygwin On 6/27/2018 9:45 AM, Andrey Repin wrote: > Greetings, john doe! > >> 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. > > Looks like an upstream bug. /etc/resolv.conf is not a required file for DNS > resolution. > Yes, I have also contacted the dirmngr developer regarding that issue. But I have to find a work around in the meantime! :) -- John Doe -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-06-27 16:45 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-06-26 16:11 Autamatically populate resolv.conf when new DNS is acquired john doe 2018-06-26 19:23 ` Automatically " Brian Inglis 2018-06-27 11:08 ` john doe 2018-06-28 4:40 ` Brian Inglis 2018-06-27 11:01 ` Autamatically " Andrey Repin 2018-06-27 16:10 ` john doe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).