標籤:dhcp export 使用者
#!/bin/bash
#
# 1、檢查目前使用者的身份是否有許可權
# 2、檢查是否有YUM源,如果沒有需要建立YUM源的設定檔
# 3、安裝DHCP,如果已經安裝了,我們可以先刪除再安裝,但刪除之間需要備份原來的dhcpd.conf
# 4、配置dhcp服務,並且啟動服務和設定開機自啟動
export yum_path=/etc/yum.repos.d/
config_file=/etc/dhcp/dhcpd.conf
#1、檢查目前使用者的身份是否有許可權
[ $UID -ne 0 ] && echo "你沒root的許可權" && exit 1
# 2、檢查是否有YUM源,如果沒有需要建立YUM源的設定檔
# 3、安裝DHCP,如果已經安裝了,我們可以先刪除再安裝,但刪除之間需要備份原來的dhcpd.conf
rpm -q dhcp &> /dev/null
rel1=$?
if [ $rel1 -eq 0 ]
then
cp -a /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.`date +%F-%T`
rpm -e dhcp && echo "dhcp設定檔已備份"
yum -y install dhcp &> /dev/null
rpm -q dhcp &> /dev/null
rel2=$?
if [ rel2 -eq 0 ]
then
echo "dhcp軟體已經正確安裝"
else
echo "yum源有問題,沒有正確安裝,等待修複..."
mkdir -p /$yum_path/bak
mv $yum_path/*.repo $yum_path/bak
./yum_config.sh
yum -y install dhcp && echo "dhcp軟體已經安裝成功"
fi
else
yum -y install dhcp &> /dev/null
rpm -e dhcp &> /dev/null
rel2=&?
if [ $rel2 -eq 0 ]
then
echo "dhcp軟體已經正確安裝"
else
echo "yum源有問題,沒有正確安裝,等待修複..."
mkdir -p /$yum_path/bak
mv $yum_path/*.repo $yum_path/bak
./yum_config.sh
yum -y install dhcp && echo "dhcp軟體已經安裝成功"
fi
fi
# 4、配置dhcp服務,並且啟動服務和設定開機自啟動
read -p "輸入你的DHCP中網域名稱:" domain
read -p "輸入你的DHCP中DNS:" dns
read -p "輸入你的DHCP範圍:" subnet
read -p "輸入你的DHCP網關:" gateway
read -p "輸入你的DHCP子網路遮罩:" mask
read -p "輸入你的DHCP位址集區的起始位:" start
read -p "輸入你的DHCP結束位:" stop
cat > /etc/dhcp/dhcpd.conf <<END
dns-update-style interim;
ignore client-updates;
option domain-name "$domain";
option domain-name-servers $dns;
option time-offset -18000;
default-lease-time 21600;
max-lease-time 43200;
subnet $subnet netmask $mask {
option routers $gateway;
option subnet-mask $mask;
range dynamic-bootp $start $stop;
}
END
service dhcpd start &> /dev/null && echo "dhcpd已經啟動了" && chkconfig dhcpd on
shell dhcp安裝練習