#!/bin/bash
#一键安装dhcp
read -p "请输入服务的ip地址:" IP
Subnet=$( echo $IP | awk -F"." '{print $1"."$2"."$3}' )
IPCONF="/etc/sysconfig/network-scripts/ifcfg-eth0"
DHCP=$( cat $IPCONF | grep "BOOTPROTO" | awk -F "=" '{print $2}' )
if (( $DHCP -ne = "dhcp" ))
then
sed -i 's/^IPADDR/IPADDR="$IP"/' $IPCONF
else
sed -i 's/^ONBOOT/IPADD="$IP"/' $IPCONF
fi
service network restart
mount /dev/cdrom /mnt/
cd /mnt/Server/
rpm -ivh $( ls | grep "^dhcp-3*" ) &>/dev/null
BB=$(rpm -qa | grep "^dhcp-3.*')
\cp /user/share/doc/$BB/dhcpd.conf.sample /etc/dhcpd.conf
sed -i 'a/192.168.0/$Subnet/g' /etc/dhcpd.conf
service dhcpd restart