编写安装配置DHCP服务脚本


要求:

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

fi


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


echo "

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



【方法二】:

#!/bin/bash

dhcpconf=/etc/dhcpd.conf

rpm -q dhcp &> /dev/null


if [ $? -ne 0 ];then

yum -y install dhcp

fi

grep "subnet" $dhcpconf  &> /dev/null


if [ $? -ne 0 ];then

echo "ddns-update-style interim;

ignore client-updates;

default-lease-time 21600;

max-lease-time 43200;" > $dhcpconf

fi


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 DNS:" dns

read -p "please input Start_IP:" start_ip

read -p "please input End_IP:" end_ip


grep $network $dhcpconf &> /dev/null


if [ $? -ne 0 ];then

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

if [ $? -ne 0 ]; then

service dhcpd start &> /dev/null

else

service dhcpd reload &> /dev/null

fi

exit 0

fi

fi

done





你可能感兴趣的:(linux,shell脚本,编写安装配置DHCP服务脚本)