189 8069 5689

SHELL脚本之配置DNS分离服务

配置DNS分离服务之解析脚本文件

1.实验环境:

准备2个网卡

2.脚本如下:

#!/bin/bash
#配置双网卡
#定义网卡配置文件位置
k=/etc/sysconfig/network-scripts

#复制网卡配置文件模板
cd /etc/sysconfig/network-scripts
cp -p ifcfg-ens33 ifcfg-ens36

#修改第1块网卡配置文件
sed -i 's/dhcp/static/' $k/ifcfg-ens33
cat >>$k/ifcfg-ens33 <<-EOF
IPADDR=192.168.100.1
NETMASK=255.255.255.0
EOF

#修改第2块网卡配置文件
sed -i 's/dhcp/static/' $k/ifcfg-ens36
sed -i 's/ens33/ens36/' $k/ifcfg-ens36
sed -i '/UUID/d' $k/ifcfg-ens36
cat >>$k/ifcfg-ens36 <<-EOF
IPADDR=12.0.0.1
NETMASK=255.255.255.0
EOF

#重启网络服务
systemctl restart network

#安装dns服务
yum install bind -y

#修改主配置文件
sed -i '/listen-on/s/127.0.0.1/any/' /etc/named.conf
sed -i '/allow-query/s/localhost/any/' /etc/named.conf
sed -i '54,57d' /etc/named.conf
#修改区域配置文件
sed -i '12,$d' /etc/named.rfc1912.zones
cat >>/etc/named.rfc1912.zones <<-EOF
view "lan" {
        match-clients { 192.168.100.0/24; };
        zone "kgc.com." IN {
                type master;
                file "kgc.com.lan";
        };
        zone "." IN {
                type hint;
                file "named.ca";
        };
};
view "wan" {
match-clients { 12.0.0.0/24; };
        zone "kgc.com." IN {
                type master;
                file "kgc.com.wan";
        };
};
EOF

#复制区域数据配置文件模板
cp -p /var/named/named.localhost /var/named/kgc.com.lan
cp -p /var/named/named.localhost /var/named/kgc.com.wan

#修改lan区域数据配置文件
sed -i '2s/@/kgc.com/2' /var/named/kgc.com.lan
sed -i '2s/rname.invalid./admin.kgc.com/' /var/named/kgc.com.lan
sed -i '8,10d' /var/named/kgc.com.lan
cat >>/var/named/kgc.com.lan <<-EOF
        NS  kgc.com.
        A   192.168.100.1
www     IN      A       192.168.100.99
ftp     IN      A       192.168.100.88
EOF

#修改wan区域数据配置文件
sed -i '2s/@/kgc.com/2' /var/named/kgc.com.wan
sed -i '2s/rname.invalid./admin.kgc.com/' /var/named/kgc.com.wan
sed -i '8,10' /var/named/kgc.com.wan
cat >>/var/named/kgc.com.wan <<-EOF
        NS  kgc.com.
        A   12.0.0.1
www     IN      A       12.0.0.1
ftp     IN      A       12.0.0.1
EOF

#开启服务
systemctl start named

#关闭防火墙
systemctl stop firewalld.service
setenforce 0

分享名称:SHELL脚本之配置DNS分离服务
转载来源:http://cdxtjz.cn/article/jjjjcc.html

其他资讯