#!/bin/bash
echo ‘the script is install dhcpd server‘
read -p "please insert rhel5-cd to cdrom and enter to next:"aa
mount /dev/cdrom /media/ &>/dev/null
rpm -Uvh /media/Server/dhcp-* &>/dev/null
echo "请为本机配置IP地址"
read -p "请输入IP地址:" ip
read -p "请输入掩码:" ip_mask
MACADDR=$(ifconfig eth0 |grep eth0|awk ‘{print $5}‘)
cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=$ip
NETMASK=$ip_mask
HWADDR=$MACADDR
EOF
echo "正在为你启用新配置的IP地址"
ifdown eth0;ifup eth0
echo "IP地址已经生效"
read -p "请为DHCP配置网段:" dhcp_net
read -p "请为DHCP配置掩码:" dhcp_mask
read -p "请为DHCP配置网关:" dhcp_gw
read -p "请为DHCP配置分配的开始IP:" dhcp_bigin
read -p "请为DHCP配置结束IP:" dhcp_over
cat >/etc/dhcpd.conf <<EOF //dhcp3的配置文件默认安装在/etc下,dhcp4则会安装在/etc/dhcp下,注意自己的路径
ddns-update-style interim;
ignore client-updates;
subnet $dhcp_net netmask $dhcp_mask {
option routers $dhcp_gw;
option subnet-mask $dhcp_mask;
range $dhcp_bigin $dhcp_over;
default-lease-time 21600;
max-lease-time 43200;
}
EOF
service dhcpd start &>/dev/null
netstat -anpl |grep :67