溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Shell腳本一鍵刷入簡單DHCP以及DNS服務(wù)(感興趣的可進(jìn)來看看)

發(fā)布時(shí)間:2020-06-07 17:01:26 來源:網(wǎng)絡(luò) 閱讀:499 作者:qq5d47f509174fe 欄目:系統(tǒng)運(yùn)維

一鍵刷入簡單DHCP服務(wù)

本次腳本配置:所屬服務(wù)器靜態(tài)IP地址為:192.168.100.100(只有此點(diǎn)需要自定義)

#! /bin/bash
#一鍵自動DHCP

yum install dhcp -y 
wangka="/etc/sysconfig/network-scripts/ifcfg-ens33"
#配置文件位置

sed -i -e '/BOOTPROTO/s/dhcp/static/g' -e '/ONBOOT/aIPADDR=192.168.100.100\nNETMASK=255.255.255.0\nGATEWAY=192.168.100.1' $wangka
systemctl restart network
#修改靜態(tài)IP地址

muban="/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example"
peizhi="/etc/dhcp/dhcpd.conf"
[ ! -e "$peizhi.bak" ] && cp $peizhi $peizhi.bak
#判斷配置文件是否存在備份,若沒有,則進(jìn)行備份

cp $muban $peizhi
sed -i '29asubnet 192.168.100.0  netmask 255.255.255.0 {\n range 192.168.100.120 192.168.100.150\;\n option routers 192.168.100.1\;\n}' $peizhi
systemctl start dhcpd
systemctl stop firewalld
setenforce 0
#開啟服務(wù),并關(guān)閉防火墻和增強(qiáng)性安全功能

一鍵刷入簡單DNS正向解析服務(wù)

腳本配置:所屬服務(wù)器IP地址:192.168.116.131

#!/bin/bash &>/dev/null
#一鍵DNS

rpm -q bind
if [ $? -ne 0 ];then
        yum install bind -y
        systemctl start named
fi
#DNS服務(wù)是否安裝

read -p "自定義域名(實(shí)例:test.com)" yu
quanju="/etc/named.conf"
quyu="/etc/named.rfc1912.zones"
[ ! -e $quanju.bak ] && cp $quanju $quanju.bak
  sed -i -e '13s/127.0.0.1/192.168.116.131/' -e '21s/localhost/any/' $quanju 
[ ! -e $quyu.bak ] && cp $quyu $quyu.bak
#備份全局、區(qū)域配置文件

grep "$yu" $quyu &> /dev/null
while [ $? -ne 0 ];do
  sed -i "18azone \"$yu\" IN {\n  type master\;\n  file \"$yu.dns\"\;\n}\;\n" $quyu
  peizhi="/var/named/$yu.dns"
cp -p /var/named/named.localhost $peizhi
done
#判斷域名是否存在,如果不存在進(jìn)行添加

sed -i -e '2d' -e "1a@       IN SOA  "$yu"\. admin\."$yu"\. (" /var/named/$yu.dns
sed -i '8d' /var/named/$yu.dns
sed -i '$d' /var/named/$yu.dns
sed -i -e "7a\  NS  $yu." -e "/A/s/127.0.0.1/192.168.116.131/" /var/named/$yu.dns
#修改區(qū)域文件

while [ 1 -ge 0 ];do
    read -p "請輸入自定義指針A記錄(實(shí)例:www  IN A 8.8.8.8)" zhen
    echo $zhen >> /var/named/$yu.dns
    read -p "是否繼續(xù)添加(y/n)" a
 if [ $a != "y" ];then
   break
fi
done
#循環(huán)

systemctl restart named
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
  echo "服務(wù)啟動"
else
  echo "啟動失敗"
fi
#判斷服務(wù)是否能正常啟動

sed -i 's/116.2/116.131/g' /etc/resolv.conf
#用于自檢
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI