shell 指令碼快速部署dhcp伺服器!

來源:互聯網
上載者:User

標籤:redhat快速部署dhcp伺服器

伺服器位址:192.168.1.110

 網段:192.168.1.0

 子網路遮罩:255.255.255.0

 網關:192.168.1.254

[[email protected] ~]# cat dhcp.sh
#!/bin/bash
#auto deploy dhcp server for  192.168.1.0/24 netmask
#this script need you have you yum repository
echo "____________mount-cdrom_____"
umount /dev/cdrom &> /dev/null                         # 卸載光碟片
mount /dev/cdrom /mnt  &> /dev/null &&          #重新掛載系統光碟片
touch /etc/yum.repos.d/yum.repo                # 建立yum的設定檔,名稱yum.repo
if [ $? -eq  0  ]
    then                                                                   # 判斷建立yum檔案成功就執行寫入以下參數
cat <<EOF > /etc/yum.repos.d/yum.repo
[server] 
name=rehat server yum
baseurl=file:///mnt/Server                      # URL的訪問路徑
enabled=1                                               #啟動yum的倉庫

gpgcheck=0                                              #不啟用軟體包的簽名
EOF                                                     

     else                                                             #否則列印出安裝yum錯誤!
 echo "_-----install yum error___"   
fi

#安裝dhcp軟體包

echo "___-install dhcp packet__ "
yum -y install dhcp &> /dev/null &&
if [ -f /etc/dhcpd.conf ]  #判斷是否有/etc/dhcpd.conf這個主設定檔
      then                                          #執行
  mv /etc/dhcp.conf /etc/dhcpd.conf.save   #儲存原有的設定檔
fi
#變數定義,主要包括網路,子網,地址等資訊
NET=192.168.1.0
MASK=255.255.255.0
RANGE="192.168.1.50 192.168.1.100"
DOMAIN_NAME="breaklinux.com"
ROUTER=192.168.1.254
DNS=8.8.8.8
#建立新的設定檔
echo "______create Configuration file______"
cat <<EOF > /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet $NET  netmask $MASK {

# --- default gateway
 option routers   $ROUTER;
 option subnet-mask  $MASK;

 option nis-domain  "$DOMAIN_NAME";
 option domain-name  "$DOMAIN_NAME";
 option domain-name-servers $DNS;

 option time-offset  -18000; # Eastern Standard Time
# option ntp-servers  192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don‘t change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;

 range dynamic-bootp $RANGE;
 default-lease-time 21600;
 max-lease-time 43200;

 # we want the nameserver to appear at a fixed address
 host ns {
  next-server marvin.redhat.com;
  hardware ethernet 12:34:56:78:AB:CD;
  fixed-address 207.175.42.254;
 }
}
EOF
echo "_____________dhcp Configuration file correctly "
service dhcpd  restart  #啟動dhcp服務
chkconfig dhcpd on      #開機啟動

 

                                           搭建dhcp伺服器完成

希望大家多多關注breaklinux.com 工作室,有錯誤的地方請指出,謝謝!

                                                                                                                                              ---新

本文出自 “渲染不變的昨天” 部落格,請務必保留此出處http://breaklinux.blog.51cto.com/8193722/1531320

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.