fedora系统部署和配置域名服务器

首先,我们需要按照以下步骤配置和安装好dns服务器

DNS server configuration

Install the bind packages using sudo:

$ sudo dnf install bind bind-utils -y

The /etc/named.conf configuration file is provided by the bind package to allow you to configure the DNS server.

Edit the /etc/named.conf file:

sudo vi /etc/named.conf

Look for the following line:

listen-on port 53 { 127.0.0.1; };

Add the IP address of your Master DNS server as follows:

listen-on port 53 { 127.0.0.1; 192.168.1.160; };

Look for the next line:

allow-query  { localhost; };

Add your local network range. The example system uses IP addresses in the 192.168.1.X range. This is specified as follows:

allow-query  { localhost; 192.168.1.0/24; };

Specify a forward and reverse zone. Zone files are simply text files that have the DNS information, such as IP addresses and host-names, on your system. The forward zone file makes it possible for the translation of a host-name to its IP address. The reverse zone file does the opposite. It allows a remote system to translate an IP address to the host name.

Look for the following line at the bottom of the /etc/named.conf file:

include "/etc/named.rfc1912.zones";

Here, you’ll specify the zone file information directly above that line as follows:

zone "dns01.fedora.local" IN {
type master;
file "forward.fedora.local";
allow-update { none; };
};

zone "1.168.192.in-addr.arpa" IN {
type master;
file "reverse.fedora.local";
allow-update { none; };
};

The forward.fedora.local and the file reverse.fedora.local are just the names of the zone files you will be creating. They can be called anything you like.

Save and exit.

接着我们需要按照自己的需要给几个特定的域名配置指定的zone文件。要知道每一个dns服务器都是按照自己的zone文件来解析域名的。

以下是给域名服务器配置访问gitlab.tuocad.com时,给解析到指定局域网的配置方法:

这是在/etc/named.conf文件中,指定访问gitlab.tuocad.com域名时去文件名为forward.tuocad.com文本文件中去寻找。

zone "gitlab.tuocad.com" IN {
type master;
file "forward.tuocad.com";
allow-update { none; };
};

默认情况下,域名服务器会在/var/named/目录下寻找zone文件。下面是/var/named/forward.tuocad.com的内容:

$TTL 86400
@ IN SOA gitlab.tuocad.com. root.tuocad.com. (
2011071001 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
@ IN NS gitlab.tuocad.com.
@ IN A 192.168.3.4

在配置其他电脑使用此域名服务器时可以修改/etc/resolv.conf文件。在配置此文件时需要注意以下事项

To prevent this from happening, make /etc/resolv.conf immutable:

$ sudo chattr +i /etc/resolv.conf 

If you want to set it back and allow it to be overwritten again:

$ sudo chattr -i /etc/resolv.conf