On 2015/07/19 13:08, Gregor Best wrote:
> Hello,
> 
> the following is a patch that adds an option called `update_unbound' to
> dhclient.conf. With this option enabled, dhclient will call
> 
>       unbound-control forwards <ns1> <ns2> <ns3>
> 
> instead of rewriting /etc/resolv.conf.
> 
> My usage scenario is that I'm running unbound on my laptop as a local
> resolver. /etc/resolv.conf is configured to only use 127.0.0.1 as the
> nameserver.

I'm doing this without patches, using a script run by entr (from packages)
to watch the lease file (written with -L /etc/dhclient.lease.<ifname>,
i.e. "!dhclient -L /etc/dhclient.lease.iwn0 iwn0" in /etc/hostname.iwn0).

The code doing -L in dhclient takes care to keep the same inode for this
file specifically to support doing this.

$ cat dhcp-watcher
#!/bin/sh
gw=$(route -n get -inet 0.0.0.0 | awk '/interface/ {print $2}')
dns=$(awk '/domain-name-servers/ {gsub("[;,]", " ", $3); print $3;}' 
/etc/dhclient.lease.$gw)
unbound-control forward_add . $dns > /dev/null
echo "default now on $gw: $(unbound-control list_forwards)" | logger -t 
dhcp-watcher

$ cat dhcp-watcher.run
#!/bin/sh
/etc/dhcp-watcher
echo /etc/dhclient.lease.* | tr ' ' '\n' | /usr/local/bin/entr /etc/dhcp-watcher

Reply via email to