Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 02-20-2013, 03:48 PM   #1
Registered: Nov 2006
Posts: 91

Rep: Reputation: 27
dhcpd - Getting client-provided hostname in execute() script?

I'm writing some advanced scripts that will control network access based on many parameters. The scripts are basically to be executed whenever my dhcpd hands out an IP address. The script then takes care of configuring iptables, as needed.

I have the following test code:

on commit {
  set CIP = binary-to-ascii(10, 8, ".", leased-address);
  set CMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
  set LeaseTime = binary-to-ascii(10,32,"",encode-int(lease-time,32));

  execute("/home/user/", "commit", CIP, CMac, LeaseTime) ;
This code works as expected and the script is executed, being passed the mac address, IP address assigned and the lease time given.

I want to add to this script so that it can also receive the client-provided hostname. A lot of systems seem to pass their own computer name as a client hostname.

I can't find any parameter which I can use to get the client provided hostname into my execute command. Doing this:

  execute("/home/user/", "commit", CIP, CMac, LeaseTime, host-decl-name) ;
fails and the script actually never executes, and the error provided reads:

Feb 20 17:23:17 millions dhcpd: data: host_decl_name: not available
Feb 20 17:23:17 millions dhcpd: execute: bad arg 5
It seems this option is only good for working with explicit host blocks where a hostname was set in dhcpd.conf for a specific MAC address/IP address/etc.

Is there a way I can grab the name the client provided and pass it into the script? (IF the client doesn't pass a name that's OK, the script will be able to ignore it - that's also why I wanted it to be the last parameter in the script.)



Last edited by fmillion; 02-20-2013 at 03:49 PM.
Old 02-21-2013, 10:38 AM   #2
Registered: Nov 2006
Posts: 91

Original Poster
Rep: Reputation: 27
After some extensive research and just plain hacking around, I figured this out:

  set ClientHost = pick-first-value( 
        option fqdn.hostname,
        option host-name,
This seems to work as expected and results in returning the first value that will provide something, in the order given.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
"one-lease-per-client" option in ISC dhcpd dhcpd.conf file m4rtin Linux - Networking 3 09-27-2012 05:44 AM
Parameter to execute shell script on puppet client through Puppet server niraj.kumar Linux - Server 3 02-08-2011 10:01 PM
Setting static IP without hostname in dhcpd.conf eRJe Linux - Networking 1 04-15-2009 02:46 PM
hostname assignment by DHCPD omdrix Linux - Server 3 06-28-2007 10:44 AM
hostname/domainname and dhcpd terp4life2001 Linux - Networking 7 08-01-2006 01:38 PM

All times are GMT -5. The time now is 03:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration