LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-20-2013, 02:48 PM   #1
fmillion
Member
 
Registered: Nov 2006
Posts: 93

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


Hi,
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, et.al. as needed.

I have the following test code:

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/test.py", "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:

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

Code:
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.)

Thanks!

F

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

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

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

Thanks!

F
 
  


Reply


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 04:44 AM
Parameter to execute shell script on puppet client through Puppet server niraj.kumar Linux - Server 3 02-08-2011 09:01 PM
Setting static IP without hostname in dhcpd.conf eRJe Linux - Networking 1 04-15-2009 01:46 PM
hostname assignment by DHCPD omdrix Linux - Server 3 06-28-2007 09:44 AM
hostname/domainname and dhcpd terp4life2001 Linux - Networking 7 08-01-2006 12:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:59 AM.

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