openSUSE 13.1 搭建 DNS服务器

时间:2023-11-26 11:45:20

1. Setup Primary DNS Server

Install bind9

BIND (Berkely Internet Name Domain) is a software for translating domain names into IP addresses.

Install it using command:

# zypper in bind

The DNS configuration files are stored in the /etc/ directory. The primary configuration file is /etc/named.conf.

Configure Bind9

Open up the file /etc/named.conf in any editor.

# nano /etc/named.conf

Add the following lines to define forward and reverse zone files.

[...]
## Uncomment and add your local area network ip series
allow-query { 127.0.0.1; 192.168.1.0/24;};
[...]
zone    "unixmen.local"   {
type master;
file    "for.unixmen.local";
}; zone   "1.168.192.in-addr.arpa"        {
type master;
file    "rev.unixmen.local";
};

Save and close the file.

Create Zone Files

Now create the forward and reverse zone files which we defined in the above step.

1. Forward Zone file

Copy the existing zone file template /var/lib/named/localhost.zone to create a new forward zone file.

# cp /var/lib/named/localhost.zone /var/lib/named/for.unixmen.local

Now edit the file /var/lib/named/for.unixmen.local,

# nano /var/lib/named/for.unixmen.local

Change the contents as shown below and replace the domain name and ip address with your own.

;
; BIND data file for forward.unixmen.local zone
;
$TTL    604800
@       IN      SOA     master.unixmen.local. root.unixmen.local. (
2         ; Serial
604800         ; Refresh
86400         ; Retry
2419200         ; Expire
604800 )       ; Negative Cache TTL
IN      A       192.168.1.101
;
@       IN      NS      master.unixmen.local.
@       IN      NS      slave.unixmen.local.
@       IN      A       192.168.1.101
@       IN      A       192.168.1.102
@       IN      A       192.168.1.100
@       IN      AAAA    ::1
master  IN      A       192.168.1.101
slave   IN      A       192.168.1.102
client  IN      A       192.168.1.100

2. Reverse Zone file

Copy the existing zone file template /var/lib/named/127.0.0.zone to create a new reverse zone file.

# cp /var/lib/named/127.0.0.zone /var/lib/named/rev.unixmen.local

Now edit the file /etc/bind/rev.unixmen.local,

# nano /var/lib/named/rev.unixmen.local

Change the contents as shown below and replace the domain name and ip address with your own.

;
; BIND reverse data file for rev.unixmen.local
;
$TTL    604800
@       IN      SOA     master.unixmen.local. root.unixmen.local. (
3         ; Serial
604800         ; Refresh
86400         ; Retry
2419200         ; Expire
604800 )       ; Negative Cache TTL
;
@       IN      NS      master.
@       IN      NS      slave.
@       IN      A       192.168.1.101
@       IN      A       192.168.1.102
@       IN      A       192.168.1.100
101     IN      PTR     master.unixmen.local.
102     IN      PTR     slave.unixmen.local.
100     IN      PTR     client.unixmen.local.

Save and close the file.

As you see in the above configuration, i increased the serial number for reverse zone file. For each change you should increase the reverse zone serial number as well.

Now start bind9 service.

# /etc/init.d/named start
# chkconfig named on

Test DNS Configuration and Zone Files

You can check the DNS configuration and zone files configuration for any syntax errors.

Check DNS configuration file using command:

# named-checkconf /etc/named.conf

If it returns nothing, your configuration file doesn’t have any syntax errors.

Check Forward Zone:

# named-checkzone unixmen.local /var/lib/named/for.unixmen.local

Sample Output:

zone unixmen.local/IN: loaded serial 2
OK

Check Reverse Zone:

# named-checkzone unixmen.local /var/lib/named/rev.unixmen.local

Sample output:

zone unixmen.local/IN: loaded serial 3
OK http://www.unixmen.com/setup-dns-server-opensuse-13-1/