# dhclient-script? How do I work this thing?



## adam2104 (Mar 25, 2012)

I'm trying to leverage dhclient-script, and specifically the /etc/dhclient-exit-hooks hook. The actual purpose is because I want to redirect the generated /etc/resolv.conf to some place else, say /etc/resolv.conf.auto. However, I'm not having much luck. As I read through /sbin/dhclient-script it seems like I can put some necessary functions within /etc/dhclient-exit-hooks and it will get executed as various times during the process.

For debugging, I've started easy, with just this:

```
echo "Reason is - $reason"
```

As far as I understand it, this should output something to console every time dhclient runs. I would expect to see it output some of the other states, like PREINIT, BOUND, etc. However, I'm only seeing "PREINIT" and none of the other states. dhclient is actually working, the interface gets an IP address. However, dhclient-script seems to only run one time, for PREINIT and never again.

Am I missing something fundamental? I'm using FreeBSD 9.0 release.


----------



## SirDice (Mar 26, 2012)

The script is called /etc/dhclient-enter-hooks:

```
add_new_resolv_conf() {
        # We don't want /etc/resolv.conf changed
        # So this is an empty function
        return 0
}

#add_new_routes() {
        #route add -net 10.0.0.138 -iface $new_ip_address
        #route add default 10.0.0.138
#}
```

Just redefine what add_new_resolv_conf() does. It's the function that eventually creates /etc/resolv.conf.


----------



## adam2104 (Mar 26, 2012)

Actually, there's both a /etc/dhclient-enter-hooks and a /etc/dhclient-exit-hooks according to the man pages for dhclient-script. Enter-hooks runs at the beginning, exit-hooks runs at the end. I have no desire in rewriting or overwriting the resolv.conf generation function. I'd rather let it do its thing. I'm attempting to jump in at the end with exit-hooks, as per the man page, but it doesn't seem to operate as described therein.


----------



## adam2104 (Mar 26, 2012)

*[Solved] dhclient-script? How do I work this thing?*

Figured this one out. dhclient runs in priv-seperation mode. Once fired up, the only output that is shown is from the original process (the one started by root). The only state done here is "PREINIT." Once that is done, the child process is spawned and it handles the rest of the configuration and states. Any "echo" statements in /etc/dhclient-exit-hooks are not seen on the console, but they will be seen in /var/log/messages if output with the following:


```
$LOGGER "message goes here"
```

The other states were actually happening. I've coded up my little bits that I needed and things are working now.


----------

