Koozali.org: home of the SME Server

how to track the work of the DHCP Server?

Offline TeNeCo

  • **
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« on: March 03, 2007, 12:30:42 PM »
I'm using SME 7.1.1 in gateway mode. How can I track the work of its DHCP Server? I would like to know the given IP-address, the DNS-Name, the lease time.
I've added sme7admin.

Further I would like to force certain IP addresses for certain MAC addresses.

Offline mmccarn

  • *
  • 2,628
  • +10/-0
how to track the work of the DHCP Server?
« Reply #1 on: March 03, 2007, 01:24:51 PM »
dhcpd activity is logged in /var/log/dhcpd/current

To configure dhcp reservations use "Hostnames and addresses" under "Configuration" in the server-manager.

Offline TeNeCo

  • **
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« Reply #2 on: March 03, 2007, 02:55:08 PM »
Quote from: "mmccarn"
dhcpd activity is logged in /var/log/dhcpd/current


OK, found it, thanks. But it would be very helpfull to have a summary, a table of the actual IP adresses in the server-manager.

Offline mmccarn

  • *
  • 2,628
  • +10/-0
how to track the work of the DHCP Server?
« Reply #3 on: March 03, 2007, 07:52:48 PM »
I can't find any way to list the active dhcp leases in server-manager; you might consider opening a 'feature request' in the bug tracker for this.

Here's a script that (at least on my SME 7.0 system) shows your active leases:
Code: [Select]
#!/bin/sh
#
# dhcpactiv.sh
#
# First, collapse all dhcp leases onto one line
# Second, extract the 'active' entries,
# Last, simplify the output format
#
sed -e :a -e '$!N;s/\n\ / /;ta' -e 'P;D' /var/lib/dhcp/dhcpd.leases \
  | grep active \
  | sed -e 's/{.*ends ./expiration/' \
        -e 's/\;  binding.*ethernet/ address/' \
        -e 's/\;.*client-hostname \"/ name /' \
        -e 's/\"\;//'

Offline TeNeCo

  • **
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« Reply #4 on: March 03, 2007, 09:24:21 PM »
OK, thanks; but could you please explain me how to use that script.

Offline byte

  • *
  • 2,183
  • +2/-0
how to track the work of the DHCP Server?
« Reply #5 on: March 03, 2007, 10:48:59 PM »
Quote from: "TeNeCo"
OK, thanks; but could you please explain me how to use that script.


Just create a new file make it excuteable and hey presto!
--[byte]--

Have you filled in a Bug Report over @ http://bugs.contribs.org ? Please don't wait to be told this way you help us to help you/others - Thanks!

Offline mmccarn

  • *
  • 2,628
  • +10/-0
how to track the work of the DHCP Server?
« Reply #6 on: March 03, 2007, 10:50:48 PM »
Option 1:
    Open a command shell using putty or ssh
    Copy and paste the script from my earlier post

Option 2:
    open a command shell using putty or ssh
    create the script using
pico -w ~/dhcpactiv.sh
copy and paste the contents of the script from here to your command shell
press ^X to close pico, saving your file as you exit
run using sh ~/dhcpactiv.sh[/list]Here's another version of the script that lists
    Active leases from /var/lib/dhcp/dhcpd.leases
    Reservations that exist in /etc/dhcpd.conf
    Recently accessed network hosts using
arp -a[/list]
(Note: This version must be saved as a script using "Option 2" or the output is unreadable...)
Code: [Select]
#!/bin/sh
#
# dhcpactiv.sh
#
# v.004
# - rewritten again to pull data from dhcpd files according to labels instead of position
#
# v.003
# - add code to remove tstp information from dpcpd.leases
#
# v.002
# - rewritten to use awk more for parsing
# - added "GMT" indicator to Expiration col head
#
echo "Source        Host       MAC Address       IP Address      Expiration (GMT)"
echo "============= ========== ================= =============== ================"
#
awk ' { out = ""} \
      { $1=="lease"||$1=="client-hostname" ? out=" " $2 : out=out } \
      { $1=="binding"||$1=="hardware" ? out= " " $3: out=out } \
      { $1=="ends"? out=" " $3 " " $4: out=out } \
      { $1=="}"? out="\n": out=out } \
      { printf out," " }' /var/lib/dhcp/dhcpd.leases \
  | grep active \
  | sed -e s/'[{};" ]'/\ /g  \
  | awk '{ printf "%-13s %-10s %-17s %-15s %-10s %-5s\n", "dhcpd.leases", $6, $5, $1, $2, $3 }'

#
# Now do the same for /etc/dhcpd.conf
#
 awk ' { out = ""}
       { $1=="host"||$1=="fixed-address" ? out=" " $2 : out=out } \
       { $1=="hardware" ? out= " " $3: out=out } \
       { $1=="}"? out="\n": out=out } \
       { printf out," " }' /etc/dhcpd.conf \
  | grep : \
  | sed -e  s/'[{};\" ]'/\ /g -e  s/\.`config get DomainName`// \
  | awk  '{ printf "%-13s %-10s %-17s %-15s %-15s \n", "dhcpd.conf", $1, $2, $3, "reservation"}'
#
# Finally, grab the current arp table
#
arp -a \
  |  sed -e s/\\..*\(/\ / -e s/\)// \
  |  awk '{ printf "%-13s %-10s %-17s %-15s %-15s \n", "arp", $1, $4, $2, "n/a"}'


Offline byte

  • *
  • 2,183
  • +2/-0
how to track the work of the DHCP Server?
« Reply #7 on: March 03, 2007, 10:52:24 PM »
Or do as mmccarn mentions  8)
--[byte]--

Have you filled in a Bug Report over @ http://bugs.contribs.org ? Please don't wait to be told this way you help us to help you/others - Thanks!

Offline TeNeCo

  • **
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« Reply #8 on: March 04, 2007, 12:45:36 PM »
Fine, thanks a lot. I took option 2 and the second script. Fine thanks. There are only two flaws:

the sonyvaio in the first line is currently offline, the MAC address is missing and the hostname moves to the MAC-address column. And there is a strange ( in the last line:

Why gets the formatting always lost in a posting?

Source        Host       MAC Address       IP Address      Expiration
============= ========== ================= =============== ================
dhcpd.leases             sonyvaio          192.168.2.239   2007/03/04 12:17:31
dhcpd.leases  BRN_72BB06 00:80:77:72:bb:06 192.168.2.238   2007/03/04 21:43
dhcpd.leases  Wireless   00:11:6b:b0:11:35 192.168.2.240   2007/03/05 00:48
dhcpd.leases  WSUSSERVER 00:0b:6a:08:3c:16 192.168.2.176   2007/03/05 08:52
dhcpd.leases  BRN_72BB06 00:80:77:72:bb:06 192.168.2.238   2007/03/05 09:43
arp           pc-00176   00:0B:6A:08:3C:16 192.168.2.176   n/a
arp           localhost  00:15:0C:9B:D0:75 (192.168.178.2  n/a

Offline mmccarn

  • *
  • 2,628
  • +10/-0
how to track the work of the DHCP Server?
« Reply #9 on: March 04, 2007, 04:30:45 PM »
Quote
the sonyvaio in the first line is currently offline
The DHCP lease doesn't depend on the computer being connected and will be listed as "active" until the lease time expires.  The "default-lease-time" in  /etc/dhcpd.conf is 24 hours and is controlled by the template-fragment /etc/e-smith/templates/etc/dhcpd.conf/25LeaseTimeDefault.  Also, the "Expiration" time listed by my script is GMT, not your local time zone - this is how dhcpd tracks leases.

Quote
the MAC address is missing and the hostname moves to the MAC-address column
Oops; I suspect my script-writing abilities are at fault here... Please run
Code: [Select]
sed -e :a -e '$!N;s/\n\ / /;ta' -e 'P;D' /var/lib/dhcp/dhcpd.leases   | grep active and post the results back here; I'll try to figure out what's up.

Quote
And there is a strange ( in the last line:
Yes, I see it. Now you know why I don't write bash scripts professionally!  if you run arp -a and post the results I'll try to fix that, too.  Do you know why "localhost" is at "192.168.178.2" - this seems a bit odd to me...

Quote
Why gets the formatting always lost in a posting?
This is a feature of the forum (probably because html works this way, too...).  You have to surround text with "[code]" tags to use a fixed-width font, preserve white space, and prevent automatic line wrap. I use "[code]...[/code]" tags for long lines of code or output where line wrapping would be dangerous, and "" for short commands or references to files on the SME server.

Offline TeNeCo

  • **
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« Reply #10 on: March 04, 2007, 08:02:59 PM »
lease 192.168.2.238 {  starts 0 2007/03/04 09:43:47;  ends 1 2007/03/05 09:43:47;  tstp 1 2007/03/05 09:43:47;  binding state active;  next binding state free;  hardware ethernet 00:80:77:72:bb:06;  client-hostname "BRN_72BB06";
lease 192.168.2.239 {  starts 0 2007/03/04 13:34:06;  ends 1 2007/03/05 13:34:06;  tstp 1 2007/03/05 13:34:06;  binding state active;  next binding state free;  hardware ethernet 00:11:6b:60:e5:c6;  uid "\001\000\021k`\345\306";  client-hostname "sonyvaio";
lease 192.168.2.240 {  starts 0 2007/03/04 14:18:31;  ends 1 2007/03/05 14:18:31;  tstp 1 2007/03/05 14:18:31;  binding state active;  next binding state free;  hardware ethernet 00:11:6b:b0:11:35;  uid "\001\000\021k\260\0215";  client-hostname "Wireless Access Point";
lease 192.168.2.176 {  starts 0 2007/03/04 18:22:13;  ends 1 2007/03/05 18:22:13;  binding state active;  next binding state free;  hardware ethernet 00:0b:6a:08:3c:16;  uid "\001\000\013j\010<\026";  client-hostname "WSUSSERVER";

arp -a is

fritz.fonwlan.box (192.168.178.2) at 00:15:0C:9B:D0:75 [ether] on eth1
pc-00176.teneco.homeftp.net (192.168.2.176) at 00:0B:6A:08:3C:16 [ether] on eth0

"localhost" is at "192.168.178.2":

This is the address of the "FritzBox" infront of the SME; it's own external IP is 192.168.178.3

Offline TeNeCo

  • **
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« Reply #11 on: March 04, 2007, 09:05:50 PM »
ahhh - voilĂ :

Code: [Select]

Source        Host       MAC Address       IP Address      Expiration
============= ========== ================= =============== ================
dhcpd.leases             BRN_72BB06        192.168.2.238   2007/03/05 09:43:47
dhcpd.leases             sonyvaio          192.168.2.239   2007/03/05 13:34:06
dhcpd.leases  Access     Wireless          192.168.2.240   2007/03/05 14:18:31
dhcpd.leases  WSUSSERVER 00:0b:6a:08:3c:16 192.168.2.176   2007/03/05 18:22
arp           fritz      00:15:0C:9B:D0:75 192.168.178.2   n/a
arp           pc-00176   00:0B:6A:08:3C:16 192.168.2.176   n/a

Offline mmccarn

  • *
  • 2,628
  • +10/-0
how to track the work of the DHCP Server?
« Reply #12 on: March 04, 2007, 10:23:31 PM »
"localhost" is supposed to be a special case that always points to "127.0.0.1" as far as I know.  I don't know what happens when it points to 192.168.178.2...

[edit 3/6/07]
The script that was in this post has been moved to the bug tracker and can now be viewed at http://bugs.contribs.org/attachment.cgi?id=947 or downloaded directly to your SME server using:
wget -O dhcpactiv.sh http://bugs.contribs.org/attachment.cgi?id=947

[/edit]

Offline TeNeCo

  • **
  • 60
  • +0/-0
how to track the work of the DHCP Server?
« Reply #13 on: March 04, 2007, 10:52:17 PM »
Quote from: "mmccarn"
"localhost" is supposed to be a special case that always points to "127.0.0.1" as far as I know.  I don't know what happens when it points to 192.168.178.2...

I can find this address in SME only as the external gateway address.
Here the new layout:

Code: [Select]

[root@gateway ~]# sh ~/dhcpactiv.sh
Source        Host       MAC Address       IP Address      Expiration (GMT)
============= ========== ================= =============== ================
dhcpd.leases  00:80:77:72:bb:06 state             192.168.2.238   2007/03/05 09:43:47
dhcpd.leases  00:11:6b:60:e5:c6 state             192.168.2.239   2007/03/05 13:34:06
dhcpd.leases  00:11:6b:b0:11:35 state             192.168.2.240   2007/03/05 14:18:31
dhcpd.leases  00:0b:6a:08:3c:16 state             192.168.2.176   2007/03/05 18:22:13
dhcpd.leases  sonyvaio   00:11:6b:60:e5:c6 192.168.2.239   2007/03/05 21:35:08
dhcpd.leases  sonyvaio   00:11:6b:60:e5:c6 192.168.2.239   2007/03/05 21:36:01
dhcpd.leases             00:80:77:72:bb:06 192.168.2.238   2007/03/05 21:37:18
arp           localhost  00:15:0C:9B:D0:75 (192.168.178.2  n/a
arp           pc-00176   00:0B:6A:08:3C:16 192.168.2.176   n/a
[root@gateway ~]#


Offline mmccarn

  • *
  • 2,628
  • +10/-0
how to track the work of the DHCP Server?
« Reply #14 on: March 05, 2007, 05:30:59 AM »
OK - I've updated the earlier script again.  This time I'm pulling the fields out of the dhcpd files by fieldname instead of trying to pull them out with sed.