DNS

上下观古今,起伏千万途。这篇文章主要讲述DNS相关的知识,希望能为你提供帮助。
1. 安装

yum -y install bind
vi /etc/named.conf


options {
listen-on port 53 { 10.0.0.2; }; #监听地址,设置为内网地址,不能是127.0.0.1 不然别的机器访问不到
allow-query{ any; }; #运行查询的范围
forwarders{ 223.5.5.5; }; #上级dns查询,需要自行添加
recursion yes; #递归的方法查询

named-checkconf #检查配置文件,返回空,则语法无误

2. 配置区域配置文件
vi /etc/named.rfc1912.zones
GG跳到文件最下面.添加如下两个模块
zone "host.com" IN {
type master;
file "host.com.zone";
allow-update { 10.0.0.2; };
};

zone "hs.com" IN {
type master;
file "hs.com.zone";
allow-update { 10.0.0.2; };
};

3. 配置区域数据文件
vi /var/named/host.com.zone
$ORIGIN host.com.
$TTL 600; 10 minutes#过期时间
@IN SOAdns.host.com. dnsadmin.host.com. (
0; serial
10800; refresh (3 hours)
900; retry (15 minutes)
604800; expire (1 week)
86400; minimum (1 day)
)
NSdns.host.com.
$TTL 60 ; 1 minute
dnsA10.0.0.2
k8s-master1A10.0.0.2
k8s-master2A10.0.0.3
k8s-master3A10.0.0.4
k8s-vipA10.0.0.5

vi /var/named/hs.com.zone
$ORIGIN hs.com.
$TTL 600; 10 minutes#过期时间
@IN SOAdns.host.com. dnsadmin.host.com. (
0; serial
10800; refresh (3 hours)
900; retry (15 minutes)
604800; expire (1 week)
86400; minimum (1 day)
)
NSdns.hs.com.
$TTL 60 ; 1 minute
dnsA10.0.0.2
harborA10.0.0.2


named-checkconf

3. 启动服务。
systemctl start named
systemctl enable named

netstat -tlnup |grep 53
tcp00 10.0.0.2:530.0.0.0:*LISTEN18716/named
tcp00 127.0.0.1:9530.0.0.0:*LISTEN18716/named
tcp600 ::1:53:::*LISTEN18716/named
tcp600 ::1:953:::*LISTEN18716/named
udp00 10.0.0.2:530.0.0.0:*18716/named
udp600 ::1:53:::*18716/named

4. 更改DNS
sed -i.bak \'s/DNS1=223.5.5.5/DNS1=10.0.0.2/g\' /etc/sysconfig/network-scripts/ifcfg-ens33
根据自身实际情况更改
systemctl stop NetworkManager #关掉这个破东西,不然reslove配置的内容重启后会消失
systemctl disable NetworkManager
echo "search host.com" > > /etc/resolv.conf#添加这个选项,可以ping不带host.name的域名
systemctl restart network

【DNS】


    推荐阅读