标签:gateway host example netmask lan route conf 关闭 正向解析
一键刷入简单DHCP服务#! /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
#开启服务,并关闭防火墙和增强性安全功能
#!/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 "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
#修改区域文件
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
#用于自检
Shell脚本一键刷入简单DHCP以及DNS服务(感兴趣的可进来看看)
标签:gateway host example netmask lan route conf 关闭 正向解析
原文地址:https://blog.51cto.com/14484404/2441328