#!/bin/bash
LOCALIP=192.168.142.128
NETMASK=255.255.255.0
DHCPIP1=192.168.142.0
DHCPIP2=192.168.1.0
DHCPIP3=192.168.2.0
DHCPIPRANGE="192.168.142.130 192.168.142.254"
DHCPIPRANGE2="192.168.1.5 192.168.1.253"
DHCPIPRANGE3="192.168.2.5 192.168.2.253"
DHCPROUTE=192.168.142.127
DHCPROUTE2=192.168.1.1
DHCPROUTE3=192.168.2.1
DNSIP=192.168.142.128
DNSNAME=www.mafei.com
NETMASK=255.255.255.0
ETH0=/etc/sysconfig/network-scripts/ifcfg-eth0
echo "# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]" > $ETH0
echo "DEVICE=eth0" >> $ETH0
echo "ONBOOT=yes" >> $ETH0
echo "TYPE=Ethernet" >> $ETH0
echo "IPADDR=$LOCALIP" >> $ETH0
echo "NETMASK=$NETMASK" >> $ETH0
echo "GATEWAY=$DHCPROUTE" >> $ETH0
service network restart
mkdir /mafei
mount /dev/cdrom /mafei
cd /mafei/Server
rpm -ivh /mafei/Server/dhcp-3.0.5-3.el5.i386.rpm
cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf << MAFEI
y
MAFEI
vi /etc/dhcpd.conf << MYMAFEI
:%s/ddns-update-style interim/ddns-update-style none
:%s/subnet 192.168.0.0 netmask 255.255.255.0/subnet $DHCPIP1 netmask 255.255.255.0
:%s/192.168.0.1;/$DHCPROUTE;
:%s/range dynamic-bootp 192.168.0.128 192.168.0.254;/range dynamic-bootp $DHCPIPRANGE;
:wq!
MYMAFEI
service dhcpd restart
echo "subnet $DHCPIP2 netmask 255.255.255.0 {" >> /etc/dhcpd.conf
echo "option routers$DHCPROUTE2;" >> /etc/dhcpd.conf
echo "option subnet-mask$NETMASK;" >> /etc/dhcpd.conf
echo "#option nis-domain"$DNSNAME";" >> /etc/dhcpd.conf
echo "#option domain-name"$DNSNAME";" >> /etc/dhcpd.conf
echo "#option domain-name-servers$DNSIP;" >> /etc/dhcpd.conf
echo "range dynamic-bootp $DHCPIPRANGE2;" >> /etc/dhcpd.conf
echo "default-lease-time 21600;" >> /etc/dhcpd.conf
echo "max-lease-time 43200;" >> /etc/dhcpd.conf
echo "}" >> /etc/dhcpd.conf
service dhcpd restart
echo "subnet $DHCPIP3 netmask 255.255.255.0 {" >> /etc/dhcpd.conf
echo "option routers$DHCPROUTE3;" >> /etc/dhcpd.conf
echo "option subnet-mask$NETMASK;" >> /etc/dhcpd.conf
echo "#option nis-domain"$DNSNAME";" >> /etc/dhcpd.conf
echo "#option domain-name"$DNSNAME";" >> /etc/dhcpd.conf
echo "#option domain-name-servers$DNSIP;" >> /etc/dhcpd.conf
echo "range dynamic-bootp $DHCPIPRANGE3;" >> /etc/dhcpd.conf
echo "default-lease-time 21600;" >> /etc/dhcpd.conf
echo "max-lease-time 43200;" >> /etc/dhcpd.conf
echo "}" >> /etc/dhcpd.conf
service dhcpd restart
chkconfig --level 35 dhcpd on