shell dhcp安裝練習

來源:互聯網
上載者:User

標籤: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安裝練習

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.