3
  • Server OS : Ubuntu 12.0.4.1 LTS Server
  • Desktop OS : Ubuntu 12.0.4.1 LTS and Windows 7

I have followed an article on the net on how to update a powerdns database. ISC DHCP and PowerDNS How ever I am battling to get the host name of the client requesting the lease. I can see from the log file that the dhcp server has it (in brackets), when I look at the lines :-

  • dhcpd: DHCPREQUEST for 192.168.0.90 from 00:1c:c0:1c:1e:84 (MINION) via eth0
  • dhcpd: DHCPACK on 192.168.0.90 to 00:1c:c0:1c:1e:84 (MINION) via eth0

My problem lies in the fact that host-decl-name does not hold any values, I would have thought that it would hold MINION as that is the name of the client. How would I get hold of the name MINION in the dhcpd.conf execution. b.t.w. minion is a windows 7 machine.

My dhcpd.conf:

ddns-update-style none;
option domain-name "butylseal.int";
option domain-name-servers 192.168.0.201, 192.168.0.202;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;

subnet 192.168.0.0 netmask 255.255.255.0 {
   range 192.168.0.1 192.168.0.99;
   option routers 192.168.0.249;
   option netbios-name-servers 192.168.0.201;
   option netbios-node-type 8;
   on commit {
      log("=============[ START COMMIT ]================");
      log("The host name is:");
      log(host-decl-name);
      set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
      set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
      log(concat("Commit: IP: " , ClientIP, " Mac: ", ClientMac, "Hostname: " , host-decl-name));
      execute("/etc/dhcp/dhcp-event","commit", ClientIP, ClientMac, host-decl-name);
      log("============[ END COMMIT ]==================");
   }
   on release {
      log("============[ START RELEASE ]===============");
      set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
      set ClientMac = binary-to-ascii(16, 8, ":", substring(hradware, 1, 6));
      log(concat("Release: IP: ", ClientIP, " Mac: ", ClientMac, "Hostname: ", host-decl-name));
      execute("/etc/dhcp/dhcp-event", "release", ClientIP, ClientMace, host-decl-name);
      log("===========[ END RELEASE ]==================");
   } 
   on expiry {
      log("===========[ START EXPIRY ]================");
      set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
      set ClientMac = binary-to-ascii(16, 8, ":" , substring(hardware, 1, 6));
      log(concat("Expiry: IP: ", ClientIP, " Mac: ", ClientMac, "Hostname: ", host-decl-name));
      execute("/etc/dhcp/dhcp-event", "expiry", ClientIP, ClientMac);
      log("===========[ END EXPIRY ] =================");
   }
}

the scrip to execute:

#!/usr/bin/env python
import MySQLdb
import os, sys
import pprint
pp = pprint.PrettyPrinter()

mysql_host = "localhost"
mysql_user = "mysqlUsr"
mysql_pass = "mySqlPass"
mysql_db = "mypdnsdb"


if (len(sys.argv) > 1):
   command = sys.argv[1]
   clientIP = sys.argv[2]
   clientMac = sys.argv[3]
   hostname = sys.argv[4]
   if command == "commit":
      pp.pprint("commit")
      f = open("/tmp/leases","a")
      s = "Leased: %s to %s\n" % (clientIP, hostname)
      f.write(s)
      f.flush()
      f.close()
      db = MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_pass, db=mysql_db)
      cursor = db.cursor()
      cursor.execute("INSERT INTO records (domain_id,name,type,content,ttl,prio,change_date) VALUES (%s,%s,%s,%s,%s,%s, UNIX_TIMESTAMP(NOW()))", [1,hostname,"A",clientIP,3600,0])
      cursor.close()
      db.commit()
      db.close()
   elif command == "release":
      pp.pprint("release")
      f = open("/tmp/leases","a")
      s = "Released: %s from %\n" % (clientIP, hostname)
      f.write(s)
      f.flush()
      f.close()
      db = MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_pass, db=mysql_db)
      cursor = db.cursor()
      cursor.execute("DELETE FROM records WHERE content = %s AND name = %s", [clientIP,hostname])
      db.commit()
      db.close()
   elif command == "expiry":
      pp.pprint("expiry")
      f = open("/tmp/leases","a")
      s = "Expired: %s from %s\n" % (clientIP, hostname)
      f.write(s)
      f.flush()
      f.close()
      db = MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_pass, db=mysql_db)
      cursor = db.cursor()
      cursor.execute("DELETE FROM records WHERE content = %s AND name = %s", [clientIP,hostname])
      db.commit()
      db.close()

thank you
Mark Hollander

1 Answer 1

4

I think "pick-first-value" can help you. You can do it in this way: set clientName = pick-first-value ( option fqdn.hostname, option host-name );

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .