Trillex installing dns

From Teknologisk videncenter
Jump to: navigation, search

Installing and Configuring a Linux DNS server with zone file

Please note that this is done on a Ubuntu server. It can and probably will differ depending on the distro used.

The package managers believe that bind is obsolete and bind9 is to be used instead. That's why I am not completely doing it the way the teacher said.

PLEASE NOTICE THAT, IF NOT LOGGED IN AS SUPERUSER, YOU WILL NEED TO USE SUDO FOR ALL OF THESE COMMANDS!

Installing the DNS Daemon (Bind9)

Bind9 (Or generally bind) is the standard DNS server daemon for Linux. Install it by typing:

sudo apt-get install bind9

This will install the program. Wait for it.

Configuring the DNS Daemon (Bind9)

There are several things that needs to be setup, like domain name, dns forwarders, creating several files etc.

Domain Name

Domain name can can be changed in the file /etc/bind/named.conf.local Right now the file is either blank or filled out with a lot of commented lines. Just delete them all and insert this:

# This is the zone definition. replace example.com with your domain name
zone "example.com" {
       type master;
       file "/etc/bind/zones/example.com.db";
       };
# This is the zone definition for reverse DNS. replace 0.168.192 with your network address in reverse notation - e.g my network address is 192.168.0
zone "0.168.192.in-addr.arpa" {
    type master;
    file "/etc/bind/zones/rev.0.168.192.in-addr.arpa";
};

Replace example.com with your own domain name (I chose trillex.dk). Also change the "reverse DNS" with your IP. Remember to do it backwards, as explained in the comments. What it essentially does is point towards the zone files it will use.

DNS Forwarder

Since, on this school, we are stuck behind a "master" server, we will need to add that DNS as a forwarder so we can actually get responses back. To find your DNS, you can type:

cat /etc/resolv.conf

The nameserver will be the DNS server here.

Now edit the file /etc/bind/named.conf.options.

Uncomment the forwarder so it looks like this:

forwarders {
       172.16.4.77;
};

Obviously replace the IP with your DNS server.

Creating Files Needed

You linked to a file when choosing domain name, that does not exist. Create them by writing this:

sudo mkdir /etc/bind/zones
sudo vi /etc/bind/zones/example.com.db

Replace example.com with your domain name.

Editing the Zone Definition File

Stay inside the example.com.db file and write in:

// replace example.com with your domain name. do not forget the . after the domain name!
// Also, replace ns1 with the name of your DNS server
example.com.      IN      SOA     ns1.example.com. admin.example.com. (
// Do not modify the following lines!
                                                       2006081401
                                                       28800
                                                       3600
                                                       604800
                                                       38400
)
// Replace the following line as necessary:
// ns1 = DNS Server name
// mta = mail server name
// example.com = domain name
example.com.      IN      NS              ns1.example.com.
example.com.      IN      MX     10       mta.example.com.
// Replace the IP address with the right IP addresses.
www              IN      A       192.168.0.1
mta              IN      A       192.168.0.2
ns1              IN      A       192.168.0.3

Change example.com to your domain name. Ignore or replace the ns1 and mta unless you got these set up on different servers. Remember to put in the IP of your own server.

Now do:

sudo vi /etc/bind/zones/rev.0.168.192.in-addr.arpa 

and copy paste in:

//replace example.com with yoour domain name, ns1 with your DNS server name.
// The number before IN PTR example.com is the machine address of the DNS server. in my case, it's 1, as my IP address is 192.168.0.1.
@ IN SOA ns1.example.com. admin.example.com. (
                        2006081401;
                        28800; 
                        604800;
                        604800;
                        86400 
) 

                     IN    NS     ns1.example.com.
1                    IN    PTR    example.com

Still, change the example.com to your domain.name.

Now restart the bind service by writing:

sudo /etc/init.d/bind9 restart

Final Touches and Test

Make sure to change your /etc/resolv.conf so it points back at your own DNS.

sudo vi /etc/resolv.conf

Enter the following:

// replace example.com with your domain name, and 192.168.0.1 with the address of your new DNS server.
search example.com
nameserver 192.168.0.1

Change as you see fit.

Test by writing:

dig example.com

It should work.