一键刷入简单DHCP服务
本次脚本配置:所属服务器静态IP地址为:192.168.100.100(只有此点需要自定义)
#! /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
#修改静态IP地址
muban="/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example"
peizhi="/etc/dhcp/dhcpd.conf"
[ ! -e "$peizhi.bak" ] && cp $peizhi $peizhi.bak
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
#开启服务,并关闭防火墙和增强性安全功能
一键刷入简单DNS正向解析服务
脚本配置:所属服务器IP地址:192.168.116.131
#!/bin/bash &>/dev/null
#一键DNS
m="rpm -qa bind"
while [ $? -gt 0 ];do
yum install bind -y
systemctl start named
done
#判断DNS服务是否安装
read -p "自定义域名(实例: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
#备份全局、区域配置文件
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
#判断域名是否存在,如果不存在进行添加
sed -i -e ‘2d‘ -e "[email protected] 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
#修改区域文件
while [ 1 -ge 0 ];do
read -p "请输入自定义指针A记录(实例:www IN A 8.8.8.8)" zhen
echo $zhen >> /var/named/$yu.dns
read -p "是否继续添加(y/n)" a
if [ $a != "y" ];then
break
fi
done
#循环
systemctl restart named
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
echo "服务启动"
else
echo "启动失败"
fi
#判断服务是否能正常启动
sed -i ‘s/116.2/116.131/g‘ /etc/resolv.conf
#用于自检
原文地址:https://blog.51cto.com/14484404/2441328
时间: 2024-11-07 09:31:14