#!/bin/ksh
# dhcp-setup.sh
#
# only for 172.25.xx.0 networks
#
# [email protected]
# 18/01/04
# Script Purpose
# Setup up DHCP for the range of IP address 51-250
# 172.25.x.0 x=site
#========================================================
# Check for DHCP packages
#
#SUNWdhcm DHCP Manager
#SUNWdhcsb Binary File Format Data Module for BOOTP/DHCP Services
#SUNWdhcsr BOOTP/DHCP Server Services, (Root)
#SUNWdhcsu BOOTP/DHCP Server Services, (Usr)
#========================================================
print "Checking for required DHCP packages"
for DHCP_PKG in SUNWdhcm SUNWdhcsb SUNWdhcsr SUNWdhcsu
do
/usr/bin/pkginfo -q $DHCP_PKG
if (( $? == 0 ))
then
print " $DHCP_PKG package OK"
else
print " Missing $DHCP_PKG package"
exit
fi
done
#========================================================
# IP Address pool 172.25.x.51-250
# x = the SITE number
#========================================================
SITENUM=0
/usr/bin/banner DHCP
read SITENUM?"Enter site network number "
echo "This will create a dhcp for the pool 172.25."$SITENUM".51-250"
read CONT?"Continue y/n? "
if [[ $CONT = [nN]* ]]
then
print "DHCP setup stopped"
exit
fi
#========================================================
# Create DHCP Server
#========================================================
/usr/sbin/dhcpconfig -D -r SUNWfiles -p /var/dhcp
#========================================================
# Site Network details
# updates macro with default router/netmask/DNS Server
# Default router Cisco 1701 172.25.xx.254
# DNS Server Sun Server 172.25.xx.1
# Broadcast address 172.25.xx.255
# Subnet 255.255.255.0
# Timeserver 172.25.xx.1
# Leasetime 24 Hours = 86400 seconds
#========================================================
print "/usr/sbin/dhtadm -M -m `uname -n` -d ':Broadcst=172.25.$SITENUM.255:Subnet=255.255.255.0:MTU=1500:Include=Locale:Timeserv=172.25.$SITENUM.1:LeaseTim=86400:LeaseNeg:DNSserv=172.25.$SITENUM.1:Router=172.25.$SITENUM.254:'" > /tmp/macro_cmd.sh
chmod +x /tmp/macro_cmd.sh
sh /tmp/macro_cmd.sh
#========================================================
# Create the site network table
#========================================================
/usr/sbin/dhcpconfig -N 172.25.$SITENUM.0
#========================================================
# Create ip addresses 51 to 250
# while loop 51 - 251
# pntadm batch mode is faster but implemented yet
#
#========================================================
print "Creating DHCP IP Pool 172.25.$SITENUM.51 to 172.25.$SITENUM.250"
COUNT=51
while [ $COUNT -lt 251 ]
do
print "Adding 172.25.$SITENUM.$COUNT"
/usr/sbin/pntadm -r SUNWfiles -m `uname -n` -p /var/dhcp -A \
172.25.$SITENUM.$COUNT 172.25.$SITENUM.0
COUNT=`expr $COUNT + 1`
done
#========================================================
# Start DHCP service
#========================================================
read DHCP_START?"Start the DHCP serivce now? "
if [[ $DHCP_START = [yY] ]]
then
print " DHCP starting"
/etc/init.d/dhcp start
fi
#========================================================
# Cleanup and Finish
#========================================================
rm /tmp/macro_cmd.sh
/usr/bin/banner DHCP DONE