DHCLIENT.CONF System variables

7,229

Solution 1

The bleeding edge (4.2.x) versions of dhclient support this by providing a gethostname() function.

So with the latest dhclient alpha, you can put something like this in dhclient.conf

send host-name = gethostname();

Ubuntu have a patch in their version of dhclient which lets you do

send host-name = "<hostname>";

and it will replace it with the proper hostname.

Redhat patch their dhclient to provide -H and -F (-H = send host-name, -F = send fqdn.fqdn) command line options. So on Redhat you can run

dhclient -H $(hostname) 

and it will send the proper hostname.

I'm not aware of anything available for Debian though - you might want to look at patching your dhclient with the Ubuntu patch

Solution 2

I guess you have a number of different approaches here. AFAIK, the dhclient.conf does not support variable expansion as you have listed. So that leaves two obvious options:

  1. Script to login to all hosts and build config file
  2. Configuration management (puppet/cfengine/chef)

Option 1. is ugly, it will get you past this hurdle but it will be difficult to maintain. Before you know it, you will regularly be writing scripts to login to all of your machines, which will take a long time, be error-prone (for instance how do you handle down hosts gracefully and come back later) and hard to maintain.

Option 2. is definitely what I would recommend, and I would recommend puppet as its far more flexible and easy to use relative to cfengine, yet relatively mature.

Here is your manifest (not tested)

class dhcp-client {
   file { "/etc/dhclient.conf":
       content => template("dhclient.conf")
   }
}

And the template :

other dhclient.conf stuff
send "<%= fqdn %>"

and node config:

node default { 
   include dhcp-client
}
Share:
7,229
Dr I
Author by

Dr I

Systems Operations fanatic, Open Sources and Python addict, I'm just another system engineer, trying to do his best to promot IT Knowledges and Open sources culture!

Updated on September 17, 2022

Comments

  • Dr I
    Dr I over 1 year

    I've just a little question.

    My DNS Servers are updated by our DHCP Server (Microsoft Windows 2003 R2 SP2).

    My clients are Debian Linux Distro's, and I have to modify my DHCLIENT.CONF file on it to send his Full Qualified Hostname.

    BUT I've about 1600 computers and I don't want to modify each client one by one, then, Could I for exemple use a System Variable on the Config file?

    Exemple:

    #DHCLIENT CONF;
    send "$hostname"
    where $hostname variable is the alias write on BASHRC for the hostname -f command.

    If you need any more informations just tell me.

  • Dr I
    Dr I about 14 years
    Is there any way to send automatically our Hostname to the DHCP?? Is quite strange, how the multinational under linux did to list and have a correct synchronisation between their Windows DNS/DHCP and their linux? IMO, normally the DHClient should be able to send his informations isn't it? I'll check your differents ways.
  • Dr I
    Dr I about 14 years
    Many thanks for your help, I've made a starting script in fact.