要求:
1、自動完成安裝,基本配置
2、通過提示輸入網段、子網路遮罩、網關、DNS、IP起止位址等資訊完成作用域的添加
【方法一】:
#!/bin/bash
conf="/etc/dhcpd.conf"
rpm -q dhcp &> /dev/null
if [ $? -ne 0 ];then
yum -y install dhcp
fi
grep "subnet" $conf &> /dev/null
if [ $? -ne 0 ]; then
echo "
ddns-update-style interim;
ignore client-updates;
default-lease-time 21600;
max-lease-time 43200;
" > $conf
read -p "please input network:" network
read -p "please input netmask:" netmask
read -p "please input gateway:" gateway
read -p "please input DNS:" dns
read -p "please input start_ip:" start_ip
read -p "please input end_ip:" end_ip
subnet $network netmask $netmask {
option routers $gateway;
option subnet-mask $netmask;
option domain-name-servers $dns;
range dynamic-bootp $start_ip $end_ip;
}
" >> $conf
service dhcpd restart
【方法二】:
dhcpconf=/etc/dhcpd.conf
grep "subnet" $dhcpconf &> /dev/null
echo "ddns-update-style interim;
max-lease-time 43200;" > $dhcpconf
while true
do
read -p "please input Network:" network
read -p "please input Netmask:" netmask
read -p "please input Gateway:" gateway
read -p "please input Start_IP:" start_ip
read -p "please input End_IP:" end_ip
grep $network $dhcpconf &> /dev/null
echo "subnet $network netmask $netmask {
option routers $gateway;
option subnet-mask $netmask;
option domain-name-servers $dns;
range dynamic-bootp $start_ip $end_ip;
}" >> $dhcpconf
read -p "continue to do (yes/no)?" yn
if [ $yn = "no" ]; then
service dhcpd status &> /dev/null
service dhcpd start &> /dev/null
else
service dhcpd reload &> /dev/null
exit 0
done
本文轉自甘兵 51CTO部落格,原文連結:http://blog.51cto.com/ganbing/1241895,如需轉載請自行聯系原作者