Difference between revisions of "Dhcpd lease time"
From SME Server
Jump to navigationJump to searchLine 23: | Line 23: | ||
# - added "GMT" indicator to Expiration col head | # - added "GMT" indicator to Expiration col head | ||
# | # | ||
− | echo "Source Host | + | echo "Source Host MAC Address IP Address Expiration (GMT)" |
− | echo "============= ==================== ================= =============== ================" | + | echo "============= ========================= ================= =============== ================" |
# | # | ||
awk ' { out = ""} \ | awk ' { out = ""} \ | ||
Line 34: | Line 34: | ||
| grep active \ | | grep active \ | ||
| sed -e s/'[{};" ]'/\ /g \ | | sed -e s/'[{};" ]'/\ /g \ | ||
− | | awk '{ printf "%-13s %- | + | | awk '{ printf "%-13s %-25s %-17s %-15s %-10s %-5s\n", "dhcpd.leases", $6, $5, $1, $2, $3 }' |
# | # | ||
Line 46: | Line 46: | ||
| grep : \ | | grep : \ | ||
| sed -e s/'[{};\" ]'/\ /g -e s/\.`config get DomainName`// \ | | sed -e s/'[{};\" ]'/\ /g -e s/\.`config get DomainName`// \ | ||
− | | awk '{ printf "%-13s %- | + | | awk '{ printf "%-13s %-25s %-17s %-15s %-15s \n", "dhcpd.conf", $1, $2, $3, "reservation"}' |
# | # | ||
# Finally, grab the current arp table | # Finally, grab the current arp table | ||
Line 52: | Line 52: | ||
arp -a \ | arp -a \ | ||
| sed -e s/\\..*\(/\ / -e s/\)// \ | | sed -e s/\\..*\(/\ / -e s/\)// \ | ||
− | | awk '{ printf "%-13s %- | + | | awk '{ printf "%-13s %-25s %-17s %-15s %-15s \n", "arp", $1, $4, $2, "n/a"}' |
==customize the lease duration== | ==customize the lease duration== |
Latest revision as of 09:38, 28 July 2015
Display the dhcp lease
according in bugzilla:2641 you have a script which display in your terminal how many computers are connected their ip, mac adress and their expiration of dhcp leases.
nano dhcpd.lease
paste the content below then save the file
chmod +x dhcpd.lease
#!/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/dhcpd/dhcpd.leases \ | grep active \ | sed -e s/'[{};" ]'/\ /g \ | awk '{ printf "%-13s %-25s %-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 %-25s %-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 %-25s %-17s %-15s %-15s \n", "arp", $1, $4, $2, "n/a"}'
customize the lease duration
You can customize the lease duration for the dhcp server (dhcpd) in SME using these instructions. The commands below will create custom template fragments for default-lease-time and max-lease-time, re-generate /etc/dhcpd.conf, and restart the dhcpd service in order to activate your changes.
mkdir -p /etc/e-smith/templates-custom/etc/dhcpd.conf cd /etc/e-smith/templates-custom/etc/dhcpd.conf echo " default-lease-time {21*86400};" > 25LeaseTimeDefault echo " max-lease-time {21*86400};" > 25LeaseTimeMax expand-template /etc/dhcpd.conf sv restart dhcpd
Notes
- Replace "21" with the desired number of days.
- The spaces in front of "default-lease-time" and "max-lease-time" are important!
- SME default 'default-lease-time' is 1 day (86400 seconds).
- SME default 'max-lease-time' is 7 days (7*86400 = 604800 seconds).
- The SME expand-template command performs the calculation inside the braces and puts the results into the output file without braces.
Verify your changes
Verify that your changes "stuck" by looking at the actual values in /etc/dhcpd.conf:
grep lease-time /etc/dhcpd.conf
The above sample, using {21*86400}, produces the following in /etc/dhcpd.conf:
default-lease-time 1814400; max-lease-time 1814400;
Un-Do these customizations
You can un-do these customizations with:
rm -f /etc/e-smith/templates-custom/etc/dhcpd.conf/25LeaseTimeDefault rm -f /etc/e-smith/templates-custom/etc/dhcpd.conf/25LeaseTimeMax expand-template /etc/dhcpd.conf sv restart dhcpd