shell脚本详解——一键部署DNS和DHCP

目录

一,shell脚本一键DNS部署

二,shell脚本一键部署dhcp

一,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脚本详解------一键部署DNS和DHCP

二,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 

原文链接:https://blog.csdn.net/m0_54594153/article/details/126424145?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169114665816800227463769%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=169114665816800227463769&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-17-126424145-null-null.268%5Ev1%5Ekoosearch&utm_term=dns%E9%98%B2%E6%8A%A4

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/21388

(0)
上一篇 2023年9月8日 09:07
下一篇 2023年9月8日 13:15

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml