分離解析腳本
在運行腳本以前,須要VM虛擬機,Centos7,兩臺主機一臺win10 -1 做爲廣域網的主機, 一臺win10 -2做爲區域網的主機。
以前個人博客有教程
#!/bin/bash
//修改添加網卡配置文件
//設置雙網卡
sed -i '4s/dhcp/static/' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i '15aIPADDR=192.168.17.1\nNETMASK=255.255.255.0' /etc/sysconfig/network-scripts/ifcfg-ens33
cp -p /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens36
sed -i '13d' /etc/sysconfig/network-scripts/ifcfg-ens36
sed -i '12s/ens33/ens36/' /etc/sysconfig/network-scripts/ifcfg-ens36
sed -i '13s/ens33/ens36/' /etc/sysconfig/network-scripts/ifcfg-ens36
sed -i '15s/192.168.17.1/12.0.0.1/' /etc/sysconfig/network-scripts/ifcfg-ens36
systemctl restart network //重啓網路服務
//修改主配置文件
sed -i '13s/127.0.0.1/any/' /etc/named.conf
sed -i '21s/localhost/any/' /etc/named.conf
sed -i '54,57d' /etc/named.conf //刪除主配置文件的根域
//刪除添加區域配置文件
sed -i '13,48d' /etc/named.rfc1912.zones //刪除13到48行區域配置文件
cat >> /etc/named.rfc1912.zones <<-EOF //給區域配置文件添加外部網卡和內部網卡
view "wan" {
match-clients { 192.168.17.0/24; }; //內部網段
zone "kgc.com" IN {
type master;
file "kgc.com.wan";
};
zone "." IN {
type hint;
file "named.ca";
};
};
view "lan" {
match-clients { 12.0.0.0/24; }; //外部網段
zone "kgc.com" IN {
type master;
file "kgc.com.lan";
};
};
EOF
cd /var/named
cp -p named.localhost kgc.com.wan //複製模板到本身設置的區域數據配置文件
sed -i '2s/@/kgc.com./2' kgc.com.wan //把區域數據配置文件的第二行的@換成kgc.com
sed -i '2s/rname.invalid./admin.kgc.com./' kgc.com.wan
sed -i '8s/@/kgc.com./' kgc.com.wan
sed -i '9s/127.0.0.1/192.168.17.1/' kgc.com.wan
sed -i '10asmtp IN A 192.168.17.99\nwww IN A 192.168.17.88' kgc.com.wan
cp -p kgc.com.wan kgc.com.lan
sed -i '9s/192.168.17.1/12.0.0.1/' kgc.com.lan
sed -i '11s/192.168.17.99/12.0.0.1/' kgc.com.lan
sed -i '12s/192.168.17.88/12.0.0.1/' kgc.com.lan
systemctl stop firewalld.service //關閉防火牆
setenforce 0 //關閉加強功能
systemctl start named //開啓服務
最後咱們用WINDOW去試一試解析域名
謝謝你們觀看