# Freebsd-8 dhclient script



## SirDice (Nov 19, 2009)

With a bit of coercing I managed to upgrade my firewall from 7.2-stable to 8. I have only one problem though. On 7.2-stable I used a /etc/dhclient-enter-hooks script to add two special routes after the lease was acquired. Unfortunately the 8 dhclient doesn't seem to support this anymore.

After looking through the dhclient and dhclient.conf man pages I did see an option "script" I might be able to use. 



> *script "script-name";*
> The script statement is used to specify the pathname of the DHCP client configuration script. This script is used by the DHCP client to set each interface's initial configuration prior to requesting an address, to test the address once it has been offered, and to set the interface's final configuration once a lease has been acquired. If no lease is acquired, the script is used to test predefined leases, if any, and also called once if no valid lease can be identified. For more information, see dhclient.leases(5).



However, I can't find any info on how to actually use this. I need to set something after the lease has been obtained.

For reference, here's my old 7-stable 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 -cloning
        route add default 10.0.0.138
}
```

Anybody have any info on how to do this with the version of dhclient from freebsd-8?


----------



## DutchDaemon (Nov 19, 2009)

Have you tried dhclient from ports? It may still support what you want. As an aside, is there no way to use dhclient.conf for what you want to do? 

BTW, the manuals differ between the base system and the ports version, so maybe some combined insight might help 

dhclient-script(8)
dhclient-script(8)

The one from ports still has a HOOKS section.


----------



## SirDice (Nov 19, 2009)

Ah.. Brilliant. It looks like I can use the builtin dhclient. I just couldn't find any info. There's no mention of the dhclient-script man page in dhclient and/or dhclient.conf, just a reference to dhclient.leases. 

Looks like I need to write something that checks $reason and based on that I should be able to set those route commands.


----------



## DutchDaemon (Nov 19, 2009)

Yep, I had to scan my system for the existence of those manuals. They _are_ in apropos output. I guess it just scans /usr/share/man.


----------



## DutchDaemon (Nov 19, 2009)

http://www.freebsd.org/cgi/man.cgi?...ktion=8&manpath=FreeBSD+8-current&format=html

That's specifically for dhclient-script under 8 (the one above is for 7.2)

--------
Never mind, they're the same


----------



## SirDice (Nov 19, 2009)

I think the last line of the explanation of the "script" option in the dhclient.conf man page needs to refer to dhclient-script, not dhclient.leases.

On a related note (man page wise), the man page of route still mentions -cloning. The command itself however doesn't accept it. Thankfully my 'problem' works even without the -cloning option :e

Should I file PRs for those man pages?


----------



## DutchDaemon (Nov 19, 2009)

Sure, I've had some good results with docs PRs (takes a while though ...)


----------



## SirDice (Nov 19, 2009)

Ha! BOOYA! 

No need to write my own dhclient-script. As I read the man page it suddenly dawned on me, I read this before :stud

It already exists, duh! It's in /sbin/dhclient-script and it will get called by /sbin/dhclient. From there /etc/dhclient-enter-hooks gets called. And the reason mine didn't work was because of the route -cloning option that's not supported anymore x(

:beergrin


----------



## FBSDin20Steps (Nov 19, 2009)

+1 lol


----------

