目录
一,shell脚本一键DNS部署
#!/bin/bash
#配置DNS服务
#关闭防火墙、关闭核心防护
systemctl stop firewalld
setenforce 0
#检查是否已安装dns服务
echo "正在检查是否已安装dns服务"
rpm -q bind
if [ $? -eq 0 ];then
echo "已安装bind"
else
echo "正在安装bind"
yum -y install bind > /dev/null
if [ $? -eq 0 ];then
echo "bind已安装"
fi
fi
#修改全局配置文件
read -p "请输入DNS服务器IP:" ip
#DNS服务器IP
sed -i "/listen-on/s/127.0.0.1/$ip/" /etc/named.conf
#允许使用该服务器的网段
sed -i "/allow-query/s/localhost/any/" /etc/named.conf
#修改区域配置文件
read -p "请输入添加的域名:" ym
ymzone=${ym}.zone
sed -i "/zone/s/localhost.localdomain/$ym/" /etc/named.rfc1912.zones
sed -i "/file/s/named.localhost/$ymzone/" /etc/named.rfc1912.zones
#修改区域数据配置文件
cp -p /var/named/named.localhost /var/named/$ymzone
sed -i "/IN SOA/s/@/$ym/2" /var/named/$ymzone
sed -i "/NS/s/@/$ym\./" /var/named/$ymzone
sed -i "/A/s/127.0.0.1/$ip/" /var/named/$ymzone
#开启dns服务
systemctl start named
二,shell脚本一键部署dhcp
#!/bin/bash
#关闭防火墙、关闭核心防护
systemctl stop firewalld
setenforce 0
echo "防火墙及核心防护已关闭"
#检查是否已安装dhcp
echo "正在检测是否已安装dhcpd"
rpm -q dhcp
if [ $? -eq 0 ];then
echo "已安装dhcp服务"
else
echo "准备安装dhcp服务"
yum -y install dhcp > /dev/null
if [ $? -eq 0 ];then
echo "dhcp已完成安装"
fi
fi
#修改网卡的配置信息
yuanip=`cat /etc/sysconfig/network-scripts/ifcfg-ens33 |grep 'IPADDR' |awk -F"=" '{print $2}'`
yuangateway=`cat /etc/sysconfig/network-scripts/ifcfg-ens33 |grep 'GATEWAY' |awk -F"=" '{print $2}'`
read -p "请输入ip: " ip
read -p "请输入网关: " gateway
sed -i "/IPADDR/s/$yuanip/$ip/" /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i "/GATEWAY/s/$yuangateway/$gateway/" /etc/sysconfig/network-scripts/ifcfg-ens33
#重启网卡
systemctl restart network
#复制配置文件
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf <<EOF
y
EOF
#修改配置文件
read -p "请输入要配置的网段: " wd
read -p "请输入地址池的左区间: " zwd
read -p "请输入地址池的右区间: " ywd
echo "subnet $wd netmask 255.255.255.0 {
range $zwd $ywd;
option routers $gateway;
}
" >> /etc/dhcp/dhcpd.conf
#启动dhcp服务
systemctl start dhcpd