Koozali.org: home of the SME Server
Obsolete Releases => SME Server 7.x => Topic started by: TeNeCo 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.
-
dhcpd activity is logged in /var/log/dhcpd/current
To configure dhcp reservations use "Hostnames and addresses" under "Configuration" in the server-manager.
-
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.
-
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:#!/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/\"\;//'
-
OK, thanks; but could you please explain me how to use that script.
-
OK, thanks; but could you please explain me how to use that script.
Just create a new file make it excuteable and hey presto!
-
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 listsActive 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...)
#!/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"}'
-
Or do as mmccarn mentions 8)
-
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
-
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.
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 runsed -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.
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...
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.
-
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
-
ahhh - voilĂ :
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
-
"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]
-
"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:
[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 ~]#
-
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.
-
Source Host MAC Address IP Address Expiration (GMT)
============= ========== ================= =============== ================
dhcpd.leases WSUSSERVER 00:0b:6a:08:3c:16 192.168.2.176 2007/03/05 18:22:13
dhcpd.leases BRN_72BB06 00:80:77:72:bb:06 192.168.2.238 2007/03/05 21:37:18
dhcpd.leases Wireless 00:11:6b:b0:11:35 192.168.2.240 2007/03/06 03:48:37
dhcpd.leases sonyvaio 00:11:6b:60:e5:c6 192.168.2.239 2007/03/06 06:26:34
dhcpd.leases WSUSSERVER 00:0b:6a:08:3c:16 192.168.2.176 2007/03/06 06:40:51
dhcpd.leases Sempron 00:01:6c:d8:f4:24 192.168.2.241 2007/03/06 06:47:32
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
I think that I have solved the miracle of the starnge localhost: I have given the sme server the name "gateway" but the local gateway ist that router at 192.168.178.2. Although I've changed the name of SME this morning the entry for that local host is still in de shell- output.
-
Also see contrib "Sme7admin". It has what you are looking for.
-
Also see contrib "Sme7admin". It has what you are looking for.
Where? I have that Sme7admin but I can't find the actual IP-adresses with its windows names in there like here:
Source Host MAC Address IP Address Expiration (GMT)
============= ========== ================= =============== ================
dhcpd.leases BRN_72BB06 00:80:77:72:bb:06 192.168.2.238 2007/03/05 21:37:18
dhcpd.leases Wireless 00:11:6b:b0:11:35 192.168.2.240 2007/03/06 03:48:37
dhcpd.leases sonyvaio 00:11:6b:60:e5:c6 192.168.2.239 2007/03/06 06:26:34
dhcpd.leases WSUSSERVER 00:0b:6a:08:3c:16 192.168.2.176 2007/03/06 06:40:51
dhcpd.leases Sempron 00:01:6c:d8:f4:24 192.168.2.241 2007/03/06 06:47:32
dhcpd.leases Wireless 00:11:6b:b0:11:35 192.168.2.240 2007/03/06 09:15:06
dhcpd.leases BRN_72BB06 00:80:77:72:bb:06 192.168.2.238 2007/03/06 09:37:25
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
-
Also see contrib "Sme7admin"
Doh! I use sme7admin on several hosts -- but I'm not using any of them for dhcp so I never noticed!
-
I get the folowing error:
Source Host MAC Address IP Address Expiration (GMT)
============= ========== ================= =============== ================
awk: cmd. line:1: { out = ""} \
awk: cmd. line:1: ^ backslash not last character on line
test.sh: line 24: syntax error near unexpected token `|'
'est.sh: line 24: ` | grep active \
-
Also see contrib "Sme7admin". It has what you are looking for
Not quite ... it displays host name as eg: pc-00249.tibors.net ... it does not give you the pc name.
If SME7admin displayed the PC name as well it would be complete in my book.
I requested the creator to put that in when it was first made but nothing happened.
Regards,
Tib
-
bpivk:
Make sure your 'test.sh' hasn't acquired any spaces after the various backslashes in the script... the backslash is used to "escape" the <newline>, but if there's a space after it then it escapes that, instead, and breaks the command...
-
Well i did a copy & paste in windows and linux twice and i had the same problem. But i won't give up. :D
-
Well i did a copy & paste in windows and linux twice and i had the same problem. But i won't give up. :D
bpivk, I had the same problem. Pasting puts an extra space at the end of the line. Open the file with pico or other editor and go to the end of each line with a / and delete any spaces after the / and save the file.
It should work fine after that at least it did for me.
-
I have double-checked the post with the script on page one and don't see any extraneous spaces in the post itself; I don't know why they're showing up when you copy/paste the script into pico...
-
Yes the problem was in the empty spaces in pico. I had to go from line to line and delete them. It works now.
Thanks
-
OK - I've updated the earlier script again.
Mike (I think) could you please post your code into a New Feature Request in the bug tracker. It'll just get lost here.
-
New Feature Request created: http://bugs.contribs.org/show_bug.cgi?id=2641
Script can be downloaded from: http://bugs.contribs.org/attachment.cgi?id=947
Or, download directly to your SME server using:
wget -O dhcpactiv.sh http://bugs.contribs.org/attachment.cgi?id=947
-
install sme7admin contrib, it gives you the information you need plus a lot more.
-
One more question:
how can I influence the work of the DHCP-Server? It would be nice if a certain MAC address would get always the same IP from the DHCP server.
-
It would be nice if a certain MAC address would get always the same IP from the DHCP server.
Hostnames and addresses panel. Have you read the User Manual?
-
Fine.
And how can I add the call of the script to the suface of the server-manager?
-
For the server-manager to display your dhcp data you would require a 'panel' (see the dev manual).
I have a nice script which will display this info in a browser. Let me know if you are interested.
Craig
-
What i did was:
Create a directory called /opt/dhcpactive
Put the dhcpactiv.sh script in there:
#!/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
#
date
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 %-25s %-22s %-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 %-25s %-22s %-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 %-25s %-22s %-15s %-15s \n", "arp", $1, $4, $2, "n/a"}'
Note I changed the script ever so slightly to include the current date/time in the output as well as making the columns for the output just a little bit wider so it was easier to read.
Then created another script called dhcplog:
#!/bin/sh
#
# Creats a log file from the dhcpactiv.sh script
./dhcpactiv.sh > ./dhcpleases.now
Which simply writes the output to a file in the /opt/dhcpactive directory.
Then, I created a symbolic link from /opt/dhcpactive/dhcpleases.now to /var/log
ln -s /opt/dhcpactive/dhcpleases.now /var/log/dhcpleases.now
Finally, I used Stephen Nobels dungog-cron contrib. http://www.dungog.net/wiki/Dungog-cron (http://www.dungog.net/wiki/Dungog-cron) to create a cron job that runs every 5 mins to update the /opt/dhcpactive/dhcpleases.now file. I can now take a look at it in the server-manager Administration -> View log files panel.
-Rick