Setting up BIND on CentOS 5.5

Discussion in 'VPS Tutorials' started by pornophobic, Jun 29, 2010.

  1. pornophobic

    pornophobic Member

    This is part of an x10hosting directed series of tutorials that I am writing. It continues the last post I wrote for this series. It could be used in practice, though it's stability or security can't be guaranteed if you have already configured BIND or haven't followed the previous tutorial. This is probably the longest of all the tutorials and almost absolutely the hardest, hence it's length.

    This tutorial will teach the Linux beginner to configure BIND DNS daemon to be able to answer requests for their domains names on their x10 VPS. At the end of the tutorial the user will have:


    • Learned how to set configure a BIND server.
    • Learned how to add domains, MX records, subdomains, etc.
    • Been familiarized with the Linux directory structure and file system.
    • Provided with lots of links for more information on everything that's being discussed :p



    Also, this tutorial assumes that:



    1. Have no prior experience with the Linux command line.
    2. You have followed the tutorial located here.
    3. You have registered a domain with x10hosting

    First I will start by briefly describing what BIND is. I guess it's best said quoting the project's home page:
    That being said, if you didn't understand half of that I will explain in a bit more simpler terms. BIND is a DNS server which allows your VPS to answer requests made to your domain name. It is used widely across the internet, and the last little bit means it's really good at what it does.

    If you didn't register your domain with x10 you will have to adapt this tutorial to your needs. I will write in notes where adaptation will be needed.

    For this tutorial, I will be using example.com as my FQDN, or domain name. I will also be using 192.168.1.100 as my VPS's IP. You can use and change the following files to meet your needs.

    So we have our basic LAMP set up working and we know this because we visited our server's IP from a browser. But if I wanted to visit my domain, example.com, it comes up as not found in the browser because my VPS isn't set up to answer requests for that domain. We are going to set up a basic BIND configuration, or commonly known as named (pronounced "named", or "name-d"), which stands for name daemon.

    First thing we'll have to do is to edit a couple files using vim. First file is named.conf. This is your main BIND configuration file. If you search google for this, you will find a lot of stuff that you really don't need to know to get your VPS answering calls and it can turn out quite confusing. So the goal here is to keep it simple and explain everything.

    I will briefly explain the file system structure here in order to lessen confusion, and, perhaps, answer any questions. You can skip this by scrolling down to the next paragraph. The Linux file system isn't built like windows, instead of using forward slashes (\) between directories, it uses a back slash (/). On Linux there are no drive letters (C:\, D:\, etc.) instead, your root directory is just /. A good rule of thumb when working from the command line on your VPS is to think of the first / when you are changing directories, or editing files as "C:\" if you're a windows user. Here is more reading on this.

    So, logged in as our privileged user (joe), we open up the file /etc/named.conf
    Code:
    sudo vim /etc/named.conf
    This should bring up a new file. If you see anything on your screen, except a bunch of ~'s and something like: ""/etc/named.conf" [New File]" at the bottom, you should reconsider editing this file. You should not have any problem if you've followed the last tutorial.

    I will show you a basic named.conf file and explain it a bit in more detail after. Here is the file:

    Code:
    options {
      directory "/var/named";
      version "Nope.";
    };
    
    Each section's directives are contained within '{' and '}'.
    Each directive is terminated with ';'.


    options { - The directives passed in this section are the main options for BIND.

    directory "/var/named"; - This tells BIND where to look for configuration and other files. We will leave it at the default, /var/named.

    version "Nope."; - This is a version statement for a bit of security, all that happens is when version requests are sent to BIND it will return "Nope." instead of the version. This is to avoid exploiting any potential weaknesses.


    Now we will add in our site's entry to this file. When we're done, our named.conf file should look like this:
    Code:
    options {
      directory "/var/named";
      version "Nope.";
    };
    
    zone "example.com" in {
      type master;
      file "example.com"
    };
    
    I will describe what we added to this does as I did above.

    zone "example.com" in { - This tells us the the zone we are answering for. This must be an FQDN, not a subdomain, this includes your domain without the "www.", as it is a subdomain as well.

    type master; - This tells that this is a master zone and everything is on this server.

    file "example.com" - This is the file name in which we will find our configuration for this domain. I like to just name it as the domain to make life easier, but you can name it anything you like, really. Note that this file will need to be in the /var/named directory, or whatever was specified above.

    Good stuff. Now before we go adding in the configuration for our site we must register the name servers in the x10hosting client area. I have wrote a tutorial on how to do this here.

    Now we have the name servers that we want to use (ns1.example.com and ns2.example.com) pointing to our VPS's IP (192.168.1.100). We can now insert the DNS record in the /var/named directory.

    This is how we're going to do it.
    Code:
    vim /var/named/example.com
    For our example.com we'll want to have a file that looks like the one below, I will explain it more in parts and attach the exact file in it's completeness.
    Code:
    $TTL            86400 ;
    
    This is is the Time To Live statement. It tells DNS Caching servers how long this record should stay in the cache. The value following it is in seconds, this record stays alive for 24 hours. You could also write this as:
    Code:
    $TTL        24h;
    
    Next is:
    Code:
    @   IN  SOA ns2.example.com. admin.example.com. ( 
                2010062801  ; Serial
                10800   ; Refresh
                3600    ; Retry
                604800  ; Expire
                86400   ; Minimum
    )
    
    This is the Start of Authority record. Basically all you need to know at this point is that you don't need to change the numbers you see (Serial, Refresh, etc.). What you can change is "ns2.example.com" and "admin.example.com". These are one of your nameservers that you registered with x10hosting, and the administrator's (your) email, respectively.
    For the email, you must replace the @ with a period. I'm not too sure why and nobody really is; meaning that if you have trouble understanding DNS not to fret as it really is the hardest part of this series and many people have lost sleep over configuring DNS.

    Moving on...
    Code:
    example.com. IN  NS  ns1.example.com.
    example.com. IN  NS  ns2.example.com.
    
    These are the two name servers you registered in this article. They follow the syntax
    Code:
    domain.tld.     IN     NS     nameserver1.domain.tld.
    
    The "IN" just has to be there if this is a site's DNS record. It is telling the internet that this is all IN the record for this site. Notice the periods after every domain and subdomain entry. Domains and subdomains with dots after them are absolute domains (FQDN) and those without are relative (PQDN). You can read about both here.

    Next Section
    Code:
    example.com.                    IN  A   192.168.1.100
    ns1.example.com.                IN  A   192.168.1.100
    ns2.example.com.                IN  A   192.168.1.100
    mail.example.com.               IN  A   192.168.1.100
    www.example.com.                IN  A   192.168.1.100
    ftp.example.com.                IN  A   192.168.1.100
    
    The above is just a list of domains that your VPS will answer to. You don't need to enter any of these except the FQDN, example.com. The others are for giving services their own subdomain. (ftp, www, mail) and completeness (nameservers).

    Code:
    example.com.                    IN  MX 10 mail.example.com.
    
    This last bit of code is the MX record, or the mail record. It will tell other mail servers where to send mail. We will set ours to mail.example.com for example.com.
  2. pornophobic

    pornophobic Member

    The rest of it.

    I had to wait for this to be approved, so I will finish it in this reply.

    I will note that in the part where you name your sub-domains (www.example.com, etc.) this is where you must add any other sub-domains that you wish to have. For example, if I wanted to add 'info.example.com' and 'testing.example.com' to my DNS record I would simply just add them to the end of that section, like so:

    Code:
    ;What we already have.
    example.com.                    IN  A   192.168.1.100
    ns1.example.com.                IN  A   192.168.1.100
    ns2.example.com.                IN  A   192.168.1.100
    mail.example.com.               IN  A   192.168.1.100
    www.example.com.                IN  A   192.168.1.100
    ftp.example.com.                IN  A   192.168.1.100
    
    ;What we are adding.
    info.example.com.              IN  A   192.168.1.100
    testing.example.com.            IN  A  192.168.1.100
    
    
    Any other FQDNs that you wish to add should be done the same way we added example.com to our DNS records.

    There you are, pretty straightforward.

    So now that we've got our example.com configuration file complete and all the sub-domains we want are added, we can exit and save the file (press 'esc', and type ':x') and start the BIND service. To do this we type:
    Code:
    service named start
    
    You should see something like the following:

    Code:
    Starting named:                                            [  OK  ]
    
    If it says [FAILED] instead of [ OK ] it should give you a brief reason as to why it failed. If you followed this tutorial to the word, it should start up just fine. If named has started up successfully you can now open your browser and type in your domain name. If you've followed the tutorials, you should see an Apache test page on your domain.

    If nothing comes up, you can try a few things to see if it's your computer that is causing it. You can try pressing the refresh button, or you could try flushing your DNS.

    That's all for this tutorial. In my next I will go through the steps needed to configure Apache to start hosting your sites, or sites.

    If you find anything in error or false or have anything to add, please message me and let me know and I will make the necessary changes. I will also post the links to those articles when I have written them.
  3. Zubair

    Zubair Community Leader Community Support

    ***Moved to VPS tutorials***

Share This Page