搭建一台网关服务器,可以内网和外网分别提供dhcp自动分配,同时能够解析xueyin.com的ip地址分别为网关服务器的内外网地址,如图
1、先安装dhcp和bind软件;
2、配置两张网卡,对应ens33和ens36,ens33为nat模式VM8网卡,ens36为仅主机VM1网卡;分配设置ip地址,网关为自己,此时会发现自己断网了,所以提前下载好软件,这是正常的;
ps:(我个人喜欢最后修改ens33的网卡ip,因为怕会断网,可以先执行dhcp和dns服务,到最后都正常获取以后和外网解析没问题以后再改网关服务器的ens33网卡ip)
3、搭建dhcp服务端,能够分配12外网和192内网
4、搭建dns服务端,修改主配置文件、区域配置文件、数据库文件
先将Windows开一台仅主机,一台nat,Linux开一台仅主机,一台nat,提前配置好为dhcp获取
-
- 47 subnet 12.0.0.0 netmask 255.255.255.0 {
- 48 range 12.0.0.20 12.0.0.80;
- 49 option domain-name-servers 12.0.0.1;
- 50 option routers 12.0.0.1;
- 51 default-lease-time 600;
- 52 max-lease-time 7200;
- 53 }
- 54
- 55 subnet 192.168.20.0 netmask 255.255.255.0 {
- 56 range 192.168.20.100 192.168.20.120;
- 57 option domain-name-servers 192.168.20.2;
- 58 option routers 192.168.20.2;
- 59 default-lease-time 600;
- 60 max-lease-time 7200;
- 61 }
- [root@localhost ~]#vim /etc/named.rfc1912.zones
-
- 12 view "lan"{
- 13 match-clients{192.168.20.0/24;};
- 14 zone "xueyin.com" IN {
- 15 type master;
- 16 file "xueyin.com.zone.lan";
- 17 };
- 18
- 19 zone "." IN {
- 20 type hint;
- 21 file "named.ca";
- 22 };
- 23 };
- 24
- 25 view "wan"{
- 26 match-clients{any;};
- 27 zone "xueyin.com" IN {
- 28 type master;
- 29 file "xueyin.com.zone.wan";
- 30 };
- 31
- 32 zone "." IN {
- 33 type hint;
- 34 file "named.ca";
- 35 };
- 36 };
- [root@localhost ~]#cd /var/named/
- [root@localhost named]#ls
- data dynamic named.ca named.empty named.localhost named.loopback slaves
- [root@localhost named]#cp -a named.localhost xueyin.com.zone.lan
- [root@localhost named]#cp -a named.localhost xueyin.com.zone.wan
- [root@localhost named]#vim xueyin.com.zone.lan
- [root@localhost named]#vim xueyin.com.zone.wan
- [root@localhost named]#named-c
- named-checkconf named-checkzone named-compilezone
- [root@localhost named]#named-checkzone xueyin.com /var/named/xueyin.com.zone.lan
- zone xueyin.com/IN: loaded serial 0
- OK
- [root@localhost named]#named-checkzone xueyin.com /var/named/xueyin.com.zone.wan
- zone xueyin.com/IN: loaded serial 0
- OK
- [root@localhost named]#systemctl restart named
- [root@localhost named]#
总结:
- 在配置网卡之前需要先下载好需要的软件,要不然就得搭建本地yum仓库安装
- DNS主配置文件中,需要注意:一定要删除“.”根域
- DNS的区域配置文件中, zone“.”的配置文件,与主配置文件一样,另外需要设置可解析的客户机,另外其他的内容需要全部删除掉
- 每做一步记得进行语法检查,很重要!!!一步一步排错,这样出错概率低。