linux dns server - lan

Upload: getasif535

Post on 29-May-2018

247 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Linux DNS Server - LAN

    1/33

    How To Set Up Linux DNS Services

    The material on this page was prepared using Sarge or Etch

    configured using our Installation and Packages pages.If you did not use our pages to set up your system, what you

    encounter on your system may be different than what is given here.

    As mentioned on the Networking page, every system on the Internet must have aunique IP address. (This does not include systems that are behind a NAT firewallbecause they are not directly on the Internet.) DNS acts as a directory service forall of these systems, allowing you to specify each one by its hostname. Atelephone book allows you to look up an individual person by name and get theirtelephone number, their unique identifier on the telephone system's network. DNSallows you to look up individual server by name and get its IP address, its uniqueidentifer on the Internet.

    There are other hostname-to-IP directory services in use, mainly for LANs. Windows

    LANs can use WINS. UNIX LANs can use NIS. But because DNS is the directoryservice for the Internet (and can also be used for LANs) it is the most widely used.UNIX LANs could always use DNS instead of NIS, and starting with Windows 2000Server, Windows LANs could use DNS instead of, or in addition to, WINS. And onsmall LANs where there are only a few machines you could just use HOSTS fileson each system instead of setting up a server running DNS, NIS, or WINS.

    As a service, DNS is critical to the operation of the Internet. When you enterin a Web browser, it's DNS that takes the host name

    and translates it to an IP address. Without DNS, you could be connected to theInternet just fine, but you ain't goin' no where. Not unless you keep a record of the

    IP addresses of all of the resources you access on the Internet and use thoseinstead of host/domain names.

    So when you visit a Web site, you are actually doing so using the site's IP addresseven though you specified a host and domain name in the URL. In the backgroundyour computer quickly queried a DNS server to get the IP address that correspondsto the Web site's server and domain names. Now you know why you have tospecify one or two DNS server IP addresses in the TCP/IP configuration on yourdesktop PC (in the resolv.conf file on a Linux system and the TCP/IP properties in

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    2/33

    the Network Control Panel on Windows systems).

    A "cannot connect" error doesn't necessarily indicate there isn't a connection to thedestination server. There may very well be. The error may indicate a failure in"resolving" the domain name to an IP address. I use the open source Firefox Webbrowser on Windows systems because the status bar gives more informationalmessages like "Resolving host", "Connecting to", and "Transferring data" ratherthan just the generic "Opening page" with IE. (It also seems to render pages fasterthan IE.)

    In short, always check for correct DNS operation when troubleshooting a probleminvolving the inability to access an Internet resource. The ability to resolve names iscritical, and later in this page we'll show you some tools you can use to investigateand verify this ability.

    When you are surfing the Web viewing Web pages or sending an e-mailyour workstation is sending queries to a DNS server to resolve

    server/domain names. (Back on the Modems page we showed you howto set up your resolv.conf file to do this.) When you have you own Website that other people visit you need a DNS server to respond to thequeries from their workstations.

    When you visit Web sites, the DNS server your workstation queries for nameresolution is typically run by your ISP, but you could have one of your own. Whenyou have your own Web site the DNS servers which respond to visitors queries aretypically run by your Web hosting provider, but you could likewise have your ownone of these too. Actually, if you set up your own DNS server it could be used torespond to both "internal" (from your workstation) and "external" (from your Web

    site's visitors) queries.

    Even if you don't have your own domain name, or even your own LAN, you can stillbenefit from using a DNS server to allow others to access your Debian system. Ifyou have a single system connected to the Interent via a cable or DSL connection,you can have it act as a Web/e-mail/FTP server using a neat service called"dynamic DNS" which we'll cover later. Dynamic DNS will even work with a modemif you want to play around with it.

    DNS Server Functions

    You can set up a DNS server for several different reasons:

    Internet Domain Support: If you have a domain nameand you're operating Web, e-mail, FTP, or otherInternet servers, you'll use a DNS server ro respond toresolution queries so others can find and access yourserver(s). This is a serious undertaking and you'd haveto set up a minimum of two of them. On this page we'll

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    3/33

    refer to these types of DNS servers as authoritativeDNS servers for reasons you'll see later. However,there are alternatives to having your own authoritativeDNS server if you have (or want to have) your owndomain name. You can have someone else host yourDNS records for you. Even if someone else is takingcare of your domain's DNS records you could still setup one of the following types of DNS servers.

    Local Name Resolution: Similar to the abovescenario, this type of DNS server would resolve thehostnames of systems on your LAN. Typically in thisscenario there is one DNS server and it does both jobs.The first being that it receives queries fromworkstations and the second being that it serves as theauthoritative source for the responses (this will be moreclear as we progress). Having this type of DNS serverwould eliminate the need to have (and manuallyupdate) a HOSTS file on each system on your LAN. On

    this page we'll refer to these as LAN DNS servers.

    During the Debian installationyou are asked to supply adomain name. This is an internal(private) domain name which isnot visible to the outside worldso, like the private IP addressranges you use on a LAN, itdoesn't have to be registeredwith anyone. A LAN DNS serverwould be authoritative for thisinternal, private domain. Forsecurity reasons, the name for

    this internal domain should notbe the same as any publicdomain name you haveregistered. Private domainnames are not restricted to using

    one of the established publicTLD (Top Level Domain) namessuch as or . You coulduse or or anything elsefor your TLD. Since a single DNSserver can be authoritative formultiple domains, you could usethe same DNS server for bothyour public and private domains.However, the server would need

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    4/33

    to be accessible from both theInternet and the LAN so you'dneed to locate it in a DMZ.Though you want to use differentpublic and private domainnames, you can use the samename for the second-leveldomain. For example,

    for the publicname and for theprivate name.

    Internet Name Resolution: LAN workstations andother desktop PCs need to send Internet domain nameresolution queries to a DNS server. The DNS servermost often used for this is the ISP's DNS servers.These are often the DNS servers you specify in yourTCP/IP configuration. You can have your own DNS

    server respond to these resolution queries instead ofusing your ISP's DNS servers. My ISP recently had aproblem where they would intermittently loseconnectivity to the network segment that their DNSservers were connected to so they couldn't becontacted. It took me about 30 seconds to turn one ofmy Debian systems into this type of DNS server and Iwas surfing with no problems. On this page we'll refer

    to these as simple DNS servers. If a simple DNS serverfails, you could just switch back to using your ISP'sDNS servers. As a matter of fact, given that youtypically specify two DNS servers in the TCP/IPconfiguration of most desktop PCs, you could have oneof your ISP's DNS servers listed as the second(fallback) entry and you'd never miss a beat if yoursimple DNS server did go down. Turning your Debiansystem into a simple DNS server is simply a matter ofentering a single command.

    Don't take from this that you need three different types of DNS servers. If you wereto set up a couple authoritative DNS servers they could also provide thefunctionality of LAN and simple DNS servers. And a LAN DNS server can

    simultaneously provide the functionality of a simple DNS server. It's a progressivetype of thing.

    If you were going to set up authoritative DNS servers or a simple DNS server you'dhave to have a 24/7 broadband connection to the Internet. Naturally, a LAN DNSserver that didn't resolve Internet host/domain names wouldn't need this.

    A DNS server is just a Debian system running a DNS application. The most widely

    used DNS application is BIND (Berkeley Internet Name Domain) and it runs a

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    5/33

    daemon called named that, among other things, responds to resolution queries.We'll see how to install it after we cover some basics.

    DNS Basics

    Finding a single server out of all of the servers on the Internet is like trying to find asingle file on drive with thousands of files. In both cases it helps to have somehierarchy built into the directory to logically group things. The DNS "namespace" ishierarchical in the same type of upside-down tree structure seen with file systems.Just as you have the root of a partition or drive, the DNS namespace has a rootwhich is signified by a period.

    When specifying the absolute path to a file in a file system you start at the root andgo to the file:

    When specifying the absolute path to a server in the DNS namespace you start atthe server and go to the root:

    Note that period after the 'com' as it's important. It's how you specify the root of thenamespace. An absolute path in the DNS namespace is called a FQDN (FullyQualified Domain Name). The use of FQDNs are prevalent in DNS configurationfiles and it's important that you always use that trailing period.

    Internet resources are usually specified by a domain name anda server hostname.

    The part of a URL is often the hostname of the Web server (or it could be analias to a server with a different host name). DNS is basically just a database withrecords for these hostnames. The directory for the entire telephone system is notstored in one huge phone book. Rather, it is broken up into many pieces with eachcity having, and maintaining, its piece of the entire directory in its phone book. Bythe same token, pieces of the DNS directory database (the "zones") are stored, andmaintained, on many different DNS servers located around the Internet. If you wantto find the telephone number for a person in Poughkeepsie, you'd have to look inthe Poughkeepsie telephone book. If you want to find the IP address of theserver in the domain, you'd have to query the DNS server that

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    6/33

    stores the DNS records for that domain.

    The entries in the database map a host/domain name to an IP address. Here is asimplistic logical view of the type of information that is stored (we'll get to the A,CNAME, and MX designations in a bit).

    This is why a real Internet server needs a static (unchanging) IP address. The IPaddress of the server's NIC connected to the Internet has to match whateveraddress is in the DNS database. Dynamic DNS does provide a way around this forhome servers however, which we'll see later.

    When you want to browse to your DNS server (the one youspecify in the TCP/IP configuration on your desktop computer) most likely won'thave a DNS record for the domain so it has to contact the DNS

    server that does. When your DNS server contacts the DNS server that has the DNSrecords (referred to as "resource records" or "zone records") foryour DNS server gets the IP address of the server and relays that addressback to your desktop computer. So which DNS server has the DNS records for aparticular domain?

    When you register a domain name with someone like Network Solutions, one of thethings they ask you for are the server names and addresses of two or three "nameservers" (DNS servers). These are the servers where the DNS records for yourdomain will be stored (and queried by the DNS servers of those browsing to yoursite). So where do you get the "name servers" information for your domain?

    Typically, when you host your Web site using a Web hosting service they not onlyprovide a Web server for your domain's Web site files but they will also provide aDNS server to store your domain's DNS records. In other words, you'll want to knowwho your Web hosting provider is going to be before you register a domain name(so you can enter the provider's DNS server information in the name servers sectionof the domain name registration application).

    You'll see the term "zone" used in DNS references. Most of thetime a zone just equates to a domain. The only times this

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    7/33

    wouldn't be true is if you set up subdomains andset up separateDNS servers to handle just those subdomains. For example, acompany would set up the subdomains and

    and would "delegate" a separate DNSserver to each one of them. In the case of these two DNS serverstheir zone would be just the subdomains. The zone of the DNS

    server for the parent (which would contain theservers and ) wouldonly contain records for those few machines in the parentdomain.

    Note that in the above example " " and " " aresubdomains while " " and " " are host names of servers inthe parent domain.

    Once you've got your Web site up and running on your Web hosting provider'sservers and someone surf's to your site, the DNS server they specified in their local

    TCP/IP configuration will query your hosting provider's DNS servers to get the IPaddress for your Web site. The DNS servers that host the DNS records for yourdomain, i.e. the DNS servers you specify in your domain name registrationapplication, are the authoritative DNS servers for your domain. The surfer's DNSserver queries one of your site's authoritative DNS servers to get an address andgets an authoritative response. When the surfer's DNS server relays the addressinformation back to the surfer's local PC it is a "non-authoritaive" response becausethe surfer's DNS server is not an authoritative DNS server for your domain.

    Example: If you surf to MIT's Web site the DNS server you have specified in yourTCP/IP configuration queries one of MIT's authoritative DNS servers and gets an

    authoritative response with the IP address for the 'www' server. Your DNS serverthen sends a non-authoritative response back to your PC. You can easily see thisfor yourself. At a shell prompt, or a DOS window on a newer Windows system, typein:

    nslookup www.mit.edu

    First you'll see the name and IP address of your locally-specified DNS server. Thenyou'll see the non-authoritative response your DNS server sent back containing thename and IP address of the MIT Web server.

    If you're on a Linux system you can also see which name server(s) your DNS servercontacted to get the IP address. At a shell prompt type in:

    whois mit.edu

    and you'll see three authoritative name servers listed with the hostnames STRAWB,W20NS, and BITSY. The 'whois' command simply returns the contents of a site'sdomain record.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.mit.edu/http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htmhttp://www.mit.edu/
  • 8/8/2019 Linux DNS Server - LAN

    8/33

    Records and Records

    Don't confuse DNS zone records with domain records. Your

    domain record is created when you fill out a domain nameregistration application and is maintained by the domainregistration service (like Network Solutions) you used to

    register the domain name. A domain only has one domainrecord and it contains administrative and technical contactinformation as well as entries for the authoritative DNS servers(aka "name servers") that are hosting the DNS records for thedomain. You have to enter the hostnames and addresses formultiple DNS servers in your domain record for redundancy(fail-over) purposes.

    DNS records (aka zone records) for a domain are stored inthe domain's zone file on the authoritative DNS servers.Typically, it is stored on the DNS servers of whatever Web

    hosting service is hosting your domain's Web site. However, ifyou have your own Web server (rather than using a Webhosting service) the DNS records could be hosted by youusing your own authoritative DNS servers (as in MIT's case), orby a third party like EasyDNS.

    In short, the name servers you specified in your domain recordhost the domain's zone file containing the zone records. Thename servers, whether they be your Web hosting provider's,those of a third party like EasyDNS, or your own, which hostthe domain's zone file are auhoritative DNS servers for the

    domain.

    Because DNS is so important to the operation of the Internet, when you register adomain name you must specify a minimum of two name servers. If you set up yourown authoritative DNS servers for your domain you must set up a minimum of twoof them (for redundency) and these would be the servers you specify in yourdomain record. While the multiple servers you specify in your domain record areauthoritative for your domain, only one DNS server can be the primary DNS serverfor a domain. Any others are "secondary" servers. The zone file on the primary DNS

    server is "replicated" (transferred) to all secondary servers. As a result, any

    changes made to DNS records must be made on the primary DNS server. Thezone files on secondary servers are read-only. If you made changes to the recordsin a zone file on a secondary DNS server they would simply be overwritten at thenext replication. As you will see below, the primary server for a domain and thereplication frequency are specified in a special type of zone record.

    Early on in this page we said that the DNS zone records are stored in a DNSdatabase which we now know is called a zone file. The term "database" is usedquite loosely. The zone file is actually just a text file which you can edit with any

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    9/33

    text editor. A zone file is domain-specific. That is, each domain has its own zonefile. Actually, there are two zone files for each domain but we're only concernedwith one right now. The DNS servers for a Web hosting provider will have manyzone files, two for each domain it's hosting zone records for. A zone "record" is, inmost cases, nothing more than a single line in the text zone file.

    There are different types of DNS zone records. These numerous record types giveyou flexibility in setting up the servers in your domain. The most common types ofzone records are:

    An A (Address) record is a "host record" and it is the mostcommon type. It is simply a static mapping of a hostname to an IPaddress. A common hostname for a Web server is 'www' so the Arecord for this server gives the IP address for this server in thedomain.

    An MX (Mail eXchanger) record is specifically for mail servers. It'sa special type of service-specifier record. It identifies a mail serverfor the domain. That's why you don't have to enter a hostname like'www' in an e-mail address. If you're running Sendmail (mailserver) and Apache (Web server) on the same system (i.e. thesame system is acting as both your Web server and e-mail server),both the A record for the system and the MX record would refer tothe same server.

    To offer some fail-over protection for e-mail, MX records also havea Priority field (numeric). You can enter two or three MX recordseach pointing to a different mail server, but the server specified inthe record with the highest priority (lowest number) will be chosenfirst. A mail server with a priority of 10 in the MX record will receivee-mail before a server with a priority of 20 in its MX record. Notethat we are only talking about receiving mail from other Internetmail servers here. When a mail server is sending mail, it acts like adesktop PC when it comes to DNS. The mail server looks at thedomain name in the recipient's e-mail address and the mail serverthen contacts its local DNS server (specified in the resolv.conf file)to get the IP address for the mail server in the recipient's domain.When an authoriative DNS server for the recipient's domainreceives the query from the sender's DNS server it sends back theIP addresses from the MX records it has in that domain's zone file.

    A CNAME (Canonical Name) record is an alias record. It's a way tohave the same physical server respond to two differenthostnames. Let's say you're not only running Sendmail andApache on your server, but you're also running WU-FTPD so italso acts as an FTP server. You could create a CNAME recordwith the alias name 'ftp' so people would useand to access different services on the

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    10/33

    same server.

    Another use for a CNAME record was illustrated in the examplenear the top of the page. Suppose you name your Web server'debian' instead of 'www'. You could simply create a CNAMErecord with the alias name 'www' but with the hostname 'debian'and debian's IP address.

    NS (Name Server) records specify the authoritative DNS serversfor a domain.

    There can multiples of all of the above record types. There is onespecial record type of which there is only one record in the zone

    file. That's the SOA (Start Of Authority) record and it's the firstrecord in the zone file. An SOA record is only present in a zone filelocated on authoritative DNS servers (non-authoritative DNSservers can cache zone records). It specifies such things as:

    The primary authoritative DNS server for thezone (domain).The e-mail address of the zone's (domain's)administrator. In zone files, the '@' has aspecific meaning so the e-mail address iswritten as me.my-domain.com.Timing information as to when secondary DNSservers should refresh or expire a zone file anda serial number to indicate the version of thezone file for the sake of comparison.

    The SOA record is the one that takes up several lines.

    Several important points to note about the records in a zone file:

    Records can specify servers in other domains. This is most commonly usedwith MX and NS records when backup servers are located in a differentdomain but receive mail or resolve queries for your domain.

    There must be an A record for systems specified in all MX, NS, and CNAME

    records.

    A and CNAME records can specify workstations as well as servers (whichyou'll see when we set up a LAN DNS server).

    Now lets look at a typical zone file. When a Debian system is set up as a DNSserver the zone files are stored in the directory. In a zone file the twoparantheses around the timer values act as line-continuation characters as doesthe '\' character at the end of second line. The ';' is the comment character. The 'IN'indicates an INternet-class record.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    0 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    11/33

    $TTL 86400

    my-name.com. IN SOA debns1.my-name.com. \

    joe.my-name.com. {

    2004011522 ; Serial no., based on date

    21600 ; Refresh after 6 hours

    3600 ; Retry after 1 hour

    604800 ; Expire after 7 days3600 ; Minimum TTL of 1 hour

    )

    ;Name servers

    debns1 IN A 192.168.1.41

    debns2.joescuz.com. IN A 192.168.1.42

    @ IN NS debns1

    my-name.com. IN NS debns2.my-name.com.

    ;Mail servers

    debmail1 IN A 192.168.1.51

    debmail2.my-name.com. IN A 192.168.1.52

    @ IN MX 10 debmail1

    my-name.com. IN MX 20 debmail2.my-name.com.

    ;Aliased servers

    debhp IN A 192.168.1.61

    debdell.my-name.com. IN A 192.168.1.62

    www IN CNAME debhp

    ftp.my-name.com. IN CNAME debdell.my-name.com.

    Several things to take note of when evaluating this example zone file:

    Records are grouped in fours and then subgrouped in twos.The lines are spaced apart only to aid in the readability of

    this example. You don't want any blank lines in a zone

    file.

    The first two records in the group of four use A records tospecify the servers, and then the second two records are

    types which specify what those servers are used for.Optionally, you could list all A records together, all NSrecords together, all CNAME records together, etc.

    The first record in the subgroup of two is a shorthand way ofentering the information (without the FQDN). The secondrecord is the longhand way. The '@' is a shorthand way ofspecifying "this zone" (domain).

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    1 of 33 9/1/2010 5:37

    ftp://ftp.my-name.com/http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htmftp://ftp.my-name.com/
  • 8/8/2019 Linux DNS Server - LAN

    12/33

    Whenever you specify a domain in a zone file it must have

    a trailing period to make it a FQDN.

    The line at the very top of the file specifies theTime To Live value for the record (used by secondary DNSservers).

    Notice that this zone file specifies the required two DNSservers (with the primary specified in the SOA record) andtwo mail servers (also for redundancy).

    Also notice the priority numbers before the hostnames in theMX records.

    If you had a simpler setup with only one server with the hostname 'debian' thatoperated as a Web, e-mail, and FTP server and you had your DNS records hosted

    by someone like EasyDNS, your zone file would look a lot simpler:

    Naturally, the private address in this example would have to be anISP-assigned public address for an Internet-accessible server. We just used aprivate address as an example.

    Notice that the last CNAME record is a little different from the others. It specifieswhich server should handle requests when no hostname is specified, i.e. requestsgoing to simply in a URL, etc. Notice also that you can specify otherdomains in your zone file which is where the long-hand way of specifying a FQDNis useful.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    2 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    13/33

    Dynamic DNS

    If you set up a Debian system to act as a combination firewall, NAT, and home Webserver you (and others if you wish) can access the Web pages on it (such as yourWeb cam images) from a remote location by entering the system's IP address in

    the URL. The IP address would be whatever is assigned to you by your ISP. Theproblem is that, unless you pay extra to have a static IP address, the IP addressassigned by your ISP will change from time to time and trying keeping up withthese changes can be a pain. You can get around this by using a host and domainname to access your system instead of an IP address. Being able to access yoursystem using a consistent name in the URL even though the IP address changes isa major benefit of dynamic DNS.

    Dynamic DNS (DDNS) is the ability for a host (your Debian server) to update itsown DNS A record. A host's IP address (or what appearsto be its IP address) canchange when you use a home broadband service such as cable or DSL, or when

    you dial into an ISP (PPP connection) using a modem. If you have a broadbandconnection, DDNS allows you to have a full-time Internet server even though youdon't have a static IP address.

    You run a small DDNS client on your server that sends DNS record updaterequests to the DDNS server. If you have your own domain name, the DDNS serveris the one that's listed as the primary name server in your domain record. MostDNS servers do not support dynamic updates by default. They have to beconfigured to listen for dynamic updates. When your server is booted up (or yourun the client software manually) it sends a request to the DDNS server tocheck/update the IP address in the A record for your server. If you've pulled a

    different IP address from your ISP since the last time a request was sent, the Arecord is updated with this new IP address.

    When you use a firewall router, what appears to be your server's IP address isactually the IP address on the "external" router interface. As mentioned on theNetworking page, the router does NAT and this address translation can causedifficulties for dynamic DNS. ddclient is a DDNS client that works with firewalls, iscompatible with a number of DDNS services, and is available as a Debian package.

    Dynamic DNS with Your Own Domain

    You can use dynamic DNS if you already have, or want to have, your ownregistered domain name. You may want your own domain name for severalreasons:

    You want to set up production Internet servers for anorganization or business with static IP addresses.You want to use your own domain name with your homeserver(s).

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    3 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    14/33

    You want to (as in my case) set up a "non-production"domain just for playing around with. A non-productiondomain would allow you to investigate how DNS works byplaying around with the zone record values. Being thatthere's no production servers in the domain, there's noproblem if you screw something up. (A non-production

    domain is a real domain with whatever name you choosebut you just use it with test servers. Naturally, you can makeit a production domain at any time just by setting up "real"servers.)

    For this I use the Domain Name+DNS Only Service bundle from EasyDNS.combecause it kills two birds with one stone (and because they have toll-free telephonetech support). EasyDNS will not only host your zone files on their DNS server, butregister your domain name (and annually renew the domain name registration) allfor $35/year. That's a pretty good deal as well as being convenient. You don't have

    to go to one place to register/renew your domain name, and then go to anotherplace to host your DNS records. When you register a domain name with EasyDNSthey'll set up some preliminary zone records for you and you just go in andadd/modify/delete records.

    EasyDNS provides a Web interface for DNS management so you can play aroundwith the settings, change server names, create alias records, etc.

    The best part is support for dynamic DNS is included in their DNS offerings so

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    4 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    15/33

    you can use them for home and test servers that don't have static IP addresses(and ddclient will work with them too).

    As a side note, what if you already have a domain name with servers that havestatic IP addresses? Most places that will host your DNS records (like your ISP orWeb hosting provider) won't let you even see them much less work with them.Having EasyDNS host your DNS records will allow you to have some control in themanagement of your DNS. Their straight DNS records hosting service (without thedomain registration/renewal piece) costs $20/year. Just be sure to update yourdomain record with the EasyDNS name servers information once you sign up forthe service and get your DNS records set up. (You also have the option oftransferring your domain to them, i.e. making them the domain name registrar, ifyou want to take advantage of the single-payment convenience thing.)

    Having your own non-production domain will not only let you play around with zonerecords, but you can experiment with having your own authoritative DNS server.One of EasyDNS's servers would be the primary authoritative name server and youcould set up your Debian server as a secondary. Then you'd just use the'nameservers' link in the Web interface to enter your server's hostname and IPaddress as a secondary server entry. This way you could play with the "zonetransfers" that take place between authoritative servers.

    But the benefits of having your own non-production domain go beyond just DNS. Italso comes in handy for testing Sendmail e-mail server and Apache Web serverconfigurations, etc. For instance, you can see if your Debian system properly sendsand receives e-mail for your non-production domain. Or you could install a testcerfificate (available for free from most certifying authorities like Thawte or Verisign)on your Debian system acting as a Web server so you can investigate SSLfunctionality. Just about any type of Internet server you want to play with will havemore functionality when you can give it a registered domain name that has DNSresolution capabilities. And if you don't have any plans to eventually use it as aproduction domain, just let it expire after the first year is up and the knowledgegained will be well worth the 35 bucks.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    5 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    16/33

    ddclient Configuration File for EasyDNS

    We'll install ddclient in a bit. It'll prompt you for the necessary configurationinformation during the install. When it's finished it'll create the fileand it should look something like this (the information you enter during the clientinstall is in blue):

    # Configuration file for ddclient generated by debconf

    #

    # /etc/ddclient.conf

    pid=/var/run/ddclient.pidprotocol=easydns

    use=if, if=eth0

    server=members.easydns.com

    login=bgates

    password=luvlinux

    my-last-name.net

    If your server is behind a cable/DSL router (such as a Linksys, DLink, or Netgear)or some other type of firewall or proxy server, replace the line:

    with the line:

    This simply uses a page on EasyDNS's Web site to display your 'outside' IPaddress. The ddclient software will read the IP address off the returned HTML codeand send it to EasyDNS. It'll do this periodically which is necessary with the

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    6 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    17/33

    changing IP addresses you get with cable and DSL services.

    Support for dynamic DNS is disabled by default which is fine if you do have staticIP address(es) on your server(s). Enabling dynamic DNS using the EasyDNS Webinterface is simply a matter of clicking on the "disabled" link as illustrated belowand acknowledging the change on the subsequent confirmation page.

    Once you've got your configuration file set up and you've set your domain fordynamic DNS, you can test your ddclient configuration to make sure it's workingwith the command:

    If you use Apache's virtual hosts feature to host multiple Web sites on your serverand you have multiple domain names registered with EasyDNS you can update thedynamic DNS for all the domains simultaneously by separating each of thedomains with a comma (,) like so:

    # Configuration file for ddclient generated by debconf

    #

    # /etc/ddclient.conf

    pid=/var/run/ddclient.pid

    protocol=easydns

    use=if, if=eth0

    server=members.easydns.com

    login=bgates

    password=luvlinux

    my-last-name.net,moe.com,larry.com,curly.com

    The EasyDNS Web interface allows you to add/modify A records, MX records andpriorities, aliases (CNAME records), and even the time intervals in the SOA record,

    all by clicking on the "dns" link shown in the figure above. The "nameservers" linktakes you to a page which lists the authoritative DNS server information(EasyDNS's name servers) for your domain.

    Your Own DNS Server ?

    If you have your own domain name and you also want to try running your own DNSserver, EasyDNS.com has a Secondary DNS Service for $15/year which takessome of the risk out of running your own DNS. You set their servers up to transfer

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    7 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    18/33

    zone information from your DNS server. You would then enter your DNS serveraddress as the primary in your domain record, and the EasyDNS DNS serveraddresses as the secondary DNS servers in your domain record. Then, should yourDNS server ever fail, name resolution queries will go to the EasyDNS servers.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    8 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    19/33

    Your Own Domain WithoutYour Own Servers

    Would you like your own domain name andreceive e-mail andWeb traffic to your domain without all the work of setting upyour own e-mail and Web servers? Piece of cake!

    Just get the Domain Name+DNS Plus Service bundle fromEasyDNS.com for $55/year. This service includes the domainname registration (and renewals) and you'll be able to:

    have your domain name annually renewed automaticallywhen you renew the service.

    have e-mails sent to a e-mailaddress automatically forwarded to whatever existinge-mail address you want (such as your e-mail address

    provided by your ISP) without having to pay for additionale-mail services.

    use their EasySMTP service (included with the Plusbundle) to sende-mail messages using your

    e-mail address.

    have Web requests toautomatically forwarded to any URL you want (like yourpersonal Web space you get from your ISP).

    Your own domain name is nice to have for several reasons.You may want to use your last name for your domain name (ifit's available). Some of the benefits of having your own domainname include:

    You can set up e-mail addresses for everymember of your family (called "mailmaps") and simplyforward their e-mail to their existing e-mail account even ifeveryone uses a different ISP or Web-mail service.

    With your own domain name, your e-mail address andWeb URL will always remain the same no matter howoften you switch ISPs or Web-mail services.

    Because so many sites use your e-mail address as a login IDit's a real pain to change your e-mail address. Not to mentionnotifying everyone that your e-mail address is different. With

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    9 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    20/33

    e-mail forwarding using your own domain name, if you switchISPs you simply change the forwarding address. The ability tohave a consistent e-mail address is valuable for students astheir e-mail providers change while they go from high school tocollege to their first job (and having a e-mailaddress looks good on a resume too). It allows you to have the

    same e-mail address if you're forced to change ISPs becauseyou move to a different city. It also protects you from ISPmergers, failures, and name changes. And having a consistentWeb URL via Web forwarding means you won't lose all thesearch engine traffic to your Web pages if the URL to yourpersonal Web space changes.

    One valuable thing about the EasyDNS.com service is that it supports SPF TXTrecords. This allows your to set up Sender Policy Framework for your mail serverwhich prevents spammers from sending e-mails using your domain name. SPF is

    fast becoming the standard for spam prevention. You use it to specify the IPaddresses of servers which are allowed to send e-mails on behalf of your domain(usually only one or two). When a spammer sends an e-mail using your domainname, and the receiving e-mail (SMTP) server is configured to use SPF, thereceiving e-mail server checks the source address of the e-mail against the allowedaddresses listed in your SPF TXT record in your DNS. If there's no match the mailis discarded.

    Domain-less DNS For Free

    If you have a broadband Internet connection without a static IP and have no desire

    to have your own domain name, you can use a free service offered by dyndns.orgto set up a home Web/e-mail/ftp server. It offers a dynamic DNS service which willredirect traffic to your server using their domain name.

    With this free service you use your server's hostname but dyndns.org's domainname. You're basically just adding/modifying an A record for your server in theirzone file. Your Web server would have a URL like:

    E-mail addressed to your server would have to have an address like:

    Because you'll be using your hostname with dyndns.org's domain name, you haveto make sure your hostname isn't the same as that of anyone else using theirservice. As a result, you'll want to come up with a hostname for your server that'sreally unique. Recall that you set the hostname during the installation. You can

    always change it by editing the file. However, you'll also need to checkfor the current hostname in the configuration files of any server applications that

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    0 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    21/33

    may use it, such as Sendmail and Apache, and edit those files as well.

    If you connect your Linux server to the Internet using a modem (we show you howon the Modems page), you'll need to a way to keep your connection up longenough for any dynamic DNS changes to take effect and this could take up to 45minutes. Most ISPs will drop an inactive connection before that. You can use theping command to keep your PPP connection up. The trick is to run it in thebackground and set it so it only sends a ping once every five minutes. Pick a Website and enter:

    Just don't forget to bring it to the foreground and stop it once you've disconnectedyour modem connection. To bring it to the foreground simply type:

    and then press Ctrl-C to exit the ping program.

    ddclient Configuration File for dyndns.org

    If you selected the dyndns.org service when you installed ddclient yourfile should look something like this:

    # Configuration file for ddclient generated by debconf

    #

    # /etc/ddclient.conf

    pid=/var/run/ddclient.pid

    protocol=dyndns2use=if, if=ppp0

    server=members.dyndns.org

    login=bgates

    password=luvlinux

    your-debian-box-hostname.dyndns.org

    Note that this file indicates the ppp0 (dialup modem) interface was entered duringthe installation rather than the 'eth0' that you would use for a network card.

    If your server is behind a cable/DSL router (such as a Linksys, DLink, or Netgear)or some other type of firewall or proxy server, replace the line:

    with the line:

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    1 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    22/33

    This simply uses a page on dyndns.org's Web site to display your 'outside' IPaddress. The ddclient software will read the IP address off the returned HTMLcode.

    Security Note: Even home Web/e-mail servers need to beset up securely. Spammers have a talent for quickly locatingimproperly secured e-mail servers and using them as spam

    relay points. This not only puts your server at risk butgobbles up all your bandwidth. If you are going to set up ahome Web/e-mail server, be sure to do it securely. That notonly involves setting up the server in a secure fashion duringthe initial install, but also includes configuring Apache andSendmail in a secure manner. The procedures on thesepages do not result in secure servers. If you are going toset up your own Web/e-mail server you'll need to buy somebooks and do some research to learn how to do it securely.More information is given on the Securing Servers page.You'll also want to take a look at the Firewall page forinformation on how to use IPTABLES entries to help protectyour server and your home network. (Remember that if youonly have one server Apache and Sendmail are going to berunning on the same system that is acting as yourNAT/firewall system.) In addition, the Packages page showsyou how to use the cron scheduler and a shell script toautomatically keep your system up to date with the latestsecurity patches.

    Dynamic DNS is OK for home servers, but it's not really appropriate for businesses.Static IP addresses and having your ISP or a third party like EasyDNS host your

    DNS records would be more appropriate for Internet server implementations bybusinesses.

    Installing ddclient

    Before installing this package be sure to sign up for an account with EasyDNS ordyndns.org. You'll need your account username and password when you installthe package. With your account set up you install the package by typing in

    at the shell prompt. You'll then be prompted for the following:

    Select the service you want to use.1.

    The next screen may seem confusing if you selectedEasyDNS in Step 1 because it prompts you for "yourDynDNS fully qualified domain names" and then givesexamples for dyndns.org. What they mean by the"DynDNS" is "Dynamic DNS", not "DynDNS.org". The

    2.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    2 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    23/33

    "fully qualified" is also a bit misleading. You don'tneed to enter a trailing period after the TLD (.com, .net,or .org Top Level Domain). All you need to do is enteryour server's hostname followed by your, ordyndns.org's, domain name. Examples:

    or

    Enter the username you chose when you signed upwith your service.

    3.

    Enter the password you chose when you signed upwith your service.

    4.

    Enter the interface that will be connecting to theservice. This will most likely be 'eth0' for an ethernet

    card (even if it is connected to a LAN which has afirewall router) or 'ppp0' for modem use (note thatthat's a zero on the end, not the letter O).

    5.

    If you entered 'ppp0' you'll be asked if you wantddcleint to run automatically every time you connect.You may want to select No here so you have the optionof running it or not.

    6.

    You'll then be asked if you want to run ddclient as adaemon. If this server is going to be a full-time Web or

    e-mail server with a broadband connection you shouldanswer Yes to this.

    7.

    The client will now be installed and the appropriate configuration file like the onesshown above will be created. Even though the file was created for you, we showedyou the typical files for both dyndns.org and EasyDNS services in case you need toedit them at a later point. If you want to examine your config file you can do sousing the nano text editor with the command:

    If you're using a modem connection you'll want to first connect to your ISP with thecommand. If you didn't set ddclient to run as a daemon then just type in:

    at the shell prompt once you're connected. The resulting message will tell you whatIP address your external interface has (and what the DNS record will be updatedwith.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    3 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    24/33

    As mentioned earlier, it will take awhile for this update to take affect. To see if it hastaken affect yet, try pinging using your domain name and see if the returned IPaddress matches what was indicated in the message when you started ddclient.Note that even if you used the above ping command in the background to keepyour connection up you can still issue a second ping command in the foreground tocheck the returned IP address.

    Other DNS Server Files

    Given that a DNS server can host the zone files for many different domains, eachhaving two zone files, it needs a way to tell which zone files are for which domains.

    It does this in the named.conf file which, like the zone files themselves, is locatedin the directory (which you'l l see when we install Bind shortly).

    Of the two zone files for each domain the one we've been talking about all alonghas been for forward lookups (resolving names to IP addresses). This zone file is

    typically named db.my-last-name.net.

    DNS also offers a "reverse lookup" function that allows you to translate IPaddresses to host/domain names. The information that allows this to happen isstored in the second zone file. Here's a reverse-lookup zone file that corresponds tothe simpler zone file we showed earlier:

    $TTL 86400

    1.168.192.in-addr.arpa. IN SOA ns1.easydns.com. \

    me.my-name.com. (

    2004011522 ; Serial no., based on date

    21600 ; Refresh after 6 hours3600 ; Retry after 1 hour

    604800 ; Expire after 7 days

    3600 ; Minimum TTL of 1 hour

    )

    51 IN PTR debian

    @ IN NS ns1.easydns.com.

    @ IN NS ns2.easydns.com.

    Note that the NS records are the same but there's no A records. And since we only

    have one system handling all three Web, e-mail, and FTP server functions we onlyneed one PTR record. A PTR (Pointer) record is the opposite of an A record. It hasthe host part of the IP address and gives the corresponding hostname. Typicallyyou want a PTR record for every A record in the forward-lookup file provided theserver is in the domain. We don't have PTR records for the name servers abovebecause they're in a different domain (and thus in a different address space).

    Why is only the host part of the IP address needed in this file? Because thenetwork portion of the IP address is used when naming the reverse-lookup zone

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    4 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    25/33

    file, and it's reversed. Because 192.168.1.x is a Class C network, the first threeoctets make up the network portion of the IP address so it's used in the zone filename. Only the last octet specifies the individual host so it's used to specify thehost in PTR records. With the above example IP address, the zone file would benamed:

    db.1.168.192

    The reverse-lookup zone file is also located in the directory. There'sanother place this naming convention is used. Take a look at the start of the SOArecord. The domain is specified as

    is the default domain for all reverse lookups. As you'll see below, theshorthand method of specifying this with the '@' is normally used.

    DNS Tools, Testing, and Troubleshooting

    When you're testing changes to your DNS records things may not act the way youexpect them to. What you need is some patience. Most DNS servers cachelookups. If you make a change to a zone record on EasyDNS or dyndns.org, or theIP address you pulled from your ISP changes and ddclient sends the update, it'lltake the DNS servers at EasyDNS or dyndns.org up to 15 minutes to update. Thenthe DNS server that your desktop system is using to resolve names may cache theold information for another 20 to 30 minutes.

    If you're using a Windows system to test DNS changes don't forget that it also hasa DNS cache. You can clear it manually in a DOS window with the command:

    As a result, if you make a change to your zone records give it at least 45 minutesbefore you try to see if the changes had the desired effect. Web browsers alsocache name-to-address information. If you're using a Web browser to test yourchanges, you may want to go and delete all the files in the browser's cachedirectory as well.

    The above makes playing around with dynamic DNS when using a modem kind ofa pain. You have to keep the connection up for for at least 45 minutes because ifyou disconnect, you'll pull a different IP address when you reconnect and yourDNS records will have invalid IP addresses. That's why I showed you how to runthe ping command in the background to keep the dial-up connection alive.

    A DNS problem will likely be in one of three places:

    The DNS server addresses specified in the TCP/IP configuration on the PC

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    5 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    26/33

    you are using to do the pinging are not correct.The registrar's domain record does not contain the correct name serverhostnames and/or addresses.The authoritative DNS servers for the domain do not have the domain's zonerecords configured correctly.

    The most basic tool for testing DNS is the ping command. If you can ping a Webserver using its IP address but not it's domain name, you have a DNS problem. Ifyou canping a server using its domain name you'll notice that the server's IPaddress is also displayed. Verifying that this is the correct IP address will verify thatDNS is working properly. Another thing ping can tell you is if you're pinging anactual server or an alias. Using the MIT example again, you may type in

    but the response will be something like

    Another common tool for testing DNS is nslookup (name server lookup) and it'savailable on Linux systems and NT-class Windows systems (NT-WS, 2000 Pro). Asyou saw earlier in this page this command will show you what name server your PCis using to resolve names, as well as return hostname and address information onthe server that's specified as the target of the command. However, it also has aninteractive mode that increase its usefulness. If you simply type in:

    and you'll get a prompt. There are several statements that you can enter at hisprompt. One helpful one is when you want your system to send queries to adifferent, other than the default, name server. At the prompt type in the 'server'command followed by the IP address of the DNS server to use:

    Then you just type in the domain name you want information on at the prompt.You'll see in the response that the name server being queried has changed to theone you specified. Type 'exit' at the prompt when you're done. Another similar tool

    on Linux systems is the dig command. You can specify the alternate DNS server to

    use on the command line:

    The parameter tells it to return information on all record types. Check the manpages for and for more information.

    If you want to make sure that BIND isn't having a problem with your zone files, youcan check the syslog after you boot the system (which is when BIND starts up and

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    6 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    27/33

    reads the zone files). At a shell prompt just type in:

    and look near the bottom of the file. You'll see messages when BIND was started.Check to see if any of them refer to any errors that were encountered. If it didn'thave a problem with the zone file you'll see it referenced along with:

    indicating that it has set the serial number (version) to 1.

    Your Own DNS Server

    Don't set up your Debian system as a DNS server if itdoesn't have access to the Internet. It will try and useexternal DNS servers (called "root hints" which we explainlater) to resolve names and they won't be accessible. Thiswill cause problems trying to FTP or telnet to your Debianserver even over a local LAN using only IP addresses.

    DNS is simply another server application. You can use your Linux system as anauthoritative, LAN, or simple DNS server. Simple DNS servers and LAN serverswhich also provide simple DNS services (resolving Internet host/domain names)need to be connected to the Internet but being behind a firewall should not presenta problem as long as you have UDP port 53 is open on the firewall. If you're going

    to set up and test a secondary authoritative DNS server you'll also need to haveTCP port 53 open on the firewall as well for zone transfers.

    We'll show you how to set up simple and LAN DNS servers in this section. Settingup production ("real") authoritative DNS servers (remember that you need at leasttwo) is beyond the scope of this page because you'll need to do quite a bit morereading to learn about zone transfers (insecure and secure) between primary andsecondary servers and you'll need to know a lot more about the file.The issue of server security also becomes more important. However, seeing how toset up DNS server files for a LAN DNS server will be a good start.

    Where to learn more - The best of our bookshelves:

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    7 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    28/33

    More info...

    DNS and BIND is another case where an O'Reilly book isconsidered the bible in the industry. I doubt there's a DNSserver admin out there that doesn't have a copy. The 4th Editioncovers BIND 9 with its security enhancements. The first threechapters provide a detailed foundation in the basics of DNSoperation from zone files to root name servers. From there it's all

    about server configuration. Setting up multiple servers,incremental zone transfers, and round-robin load distribution arejust a few of the things covered. It also covers how to set up aserver to respond to DDNS requests from clients and DHCPservers as well as how to control which systems have this abilitythrough ACLs (Access Control Lists). How to use BIND'sdebugging levels and debugger output to solve problems is alsocovered.

    A Simple DNS Server

    As mentioned earlier, the most widely used DNS application is called BIND andinstalling it is simply a matter of entering the command:

    Congratulations! You now have a simple DNS server. Now just change the DNSserver settings in the TCP/IP configuration files on the workstations on your LAN sothat they start using this server as their preferred DNS server. You can use yourISP's DNS server(s) as alternate servers as this will provide some redundancy ifyour server ever goes down. You'll also want to modify the file on

    the DNS server itself so that it points to itself. Do that by opening the file in a texteditor with the command:

    and making sure the first line is:

    Why is setting up a simple DNS server so easy? Because of things called "roothints". The root hints are a list of root-level DNS servers in the file.

    Your simple DNS server will query a root server to get the addresses ofauthoritative DNS servers for each given domain (so it can contact thoseauthoritative DNS servers to get the IP addresses of the desired hosts).

    Just remember that your simple DNS server needs a 24/7 connection to theInternet. Or it at least needs to be connected to the Internet any time any systemon your LAN needs to access anything on the Internet.

    A LAN DNS Server

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    8 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    29/33

    We'll cover setting up a LAN DNS server for a small LAN where the workstationaddresses are statically assigned. If you have a larger LAN that uses DHCP, you'llneed to set up the server to respond to DDNS update requests because a system'sA record will need to be updated when DHCP assigns the system a differentaddress.

    In setting up a LAN DNS server we need to:

    Create the forward and reverse zone files.Update the named.conf configuration file with things called "forwarders"Update the named.conf configuration file so that the server knows it'sauthoritative for the LAN domain.

    The zone files are just like the zone files we have above. You can even copy/pastethe following zone files into a text editor and edit them accordingly if you want. Ifyou're viewing this page on a Windows system, you can copy/paste them into

    Notepad and FTP them to your Debian system (remember to use ASCII mode whenyou FTP). Because the zone file names aren't Windows-friendly just save them inNotepad using names like forward.txt and reverse.txt. You can rename them whenwe copy them from your home directory to the directory. Remember thatFTP won't work with the root account (it's a security thing) so use the user accountyou created when you installed Debian. When you FTP the files to your Debiansystem they'll go into this account's home directory. We'll copy them over to theright place in a bit.

    Here's the forward-lookup zone file for a LAN with the domain name kplan.net.Note that the A records are grouped together, as are the other record types, and

    that there are no blank lines. However, when trying to get my DNS server to work Idid see an error in the syslog file about the reverse-lookup zone file not ending in a"new line" so make sure there's a blank line at the bottom of the file.

    $TTL 86400

    kplan.net. IN SOA woody.kplan.net. \

    keith.kplan.net. (

    2004011522 ; Serial no., based on date

    21600 ; Refresh after 6 hours

    3600 ; Retry after 1 hour

    604800 ; Expire after 7 days

    3600 ; Minimum TTL of 1 hour

    )potato-gw IN A 192.168.10.1

    w2kpro IN A 192.168.10.10

    ntserver IN A 192.168.10.20

    solarisintel IN A 192.168.10.30

    solarissparc IN A 192.168.10.40

    woody IN A 192.168.10.50

    @ IN NS woody

    @ IN MX 10 woody

    www IN CNAME woody

    ftp IN CNAME woody

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    9 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    30/33

    woody IN CNAME @

    And here's the reverse-lookup zone file for the same domain:

    $TTL 86400

    @ IN SOA woody.kplan.net. \

    keith.kplan.net. (

    2004011522 ; Serial no., based on date

    21600 ; Refresh after 6 hours

    3600 ; Retry after 1 hour

    604800 ; Expire after 7 days

    3600 ; Minimum TTL of 1 hour

    )

    1 IN PTR potato-gw

    10 IN PTR w2kpro

    20 IN PTR ntserver

    30 IN PTR solarisintel

    40 IN PTR solarissparc50 IN PTR woody

    @ IN NS woody

    Notice that instead of using at the start of the SOA record Ijust used the shortcut. Now when I add a new system to my network I can just addentries to these two files rather than editing the HOSTS files on all of the serversand workstations.

    If you created these files on a Windows system using Notepad and FTPed them toyour Debian server, go into the directory you FTPed them into and move/renamethem like so:

    and

    While the zone file naming convention that BIND uses by default is db. followed bythe domain name, and the reverse-lookup zone file is similar except that thedomain name is replaced by the reversed network address, you can actually namethem whatever you want. You tell the server what zone files to use in the

    file.

    named.conf

    The file is the main configuration file for a DNS server. In it you tel l theserver what, if any, forwarders to use, what domains it's authoritative for, and whichzone files it should use for each domain.

    Forwarders let you specify other DNS servers to use when your DNS server

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    0 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    31/33

    receives a query for a domain it isn't authoritative for. Your LAN DNS server will beauthoritative for your LAN's domain name, but it won't know about domains on theInternet. When it gets a query for an Internet domain it will forward the request outto a DNS server specified in the forwarders section of the named.conf file.

    Open the file using the ee text editor. In the options sectionyou'll see an indented block of text like this:

    // forwarders {

    // 0.0.0.0;

    // };

    You typically want to put your ISP's DNS servers here. The ' ' are commentcharacters in this file so you'll need to remove those also. You should end up witha block of text that looks like this:

    forwarders {

    192.168.243.9;

    192.168.253.9;

    };

    We used private addresses in the above example but naturally these would bepublically-accessible DNS servers (your ISP's). Now we have to add the content tothe file so the server knows it knows it's authoritative for the kplan.net domain. Atthe bottom of the file you'll see the line:

    Below this line we'll enter the following for the forward and reverse zone files:

    zone "kplan.net" {

    type master;

    file "/etc/bind/db.kplan.net";

    };

    zone "10.168.192.in-addr.arpa" {

    type master;

    file "/etc/bind/db.10.168.192";};

    Save the file and we're in business from a server perspective. The named daemonis running, we already have a root hints database, our zone files our set up, andour forwarders are set up in the configuration file. Now just change the

    file on any Debian and UNIX systems so it looks like this:

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    1 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    32/33

    search kplan.net

    nameserver 192.168.10.50

    On Windows systems you'd have to change the "Preferred DNS server" in theTCP/IP properties to the 192.168.10.50 address.

    Now that you've got a feel for what DNS does for you, and possibly have your owndomain name with name resolution capabilities, it's time to start setting up someservers.

    SECURITY WARNING

    Do NOT plan to use the system you will create using these guide pages as a"production" (real) server. It will NOT be secure!

    There are many steps involved in creating a secure Internet or LAN server. Whilewe do refer to some things you can do to make your system more secure, thereare many other measures related to system security that also need to be takeninto consideration and they are not covered on these pages.

    These guide pages are meant as a learning tool only. The knowledge gained onthese pages will help you understand the material covered in security-relatedpublications when you are ready to consider setting up a production server.

    Did you find this page helpful ?If so, please help keep this site operating

    by using our CD, gear, or book pages.

    Site, content, documents, original images Copyright 2003-2010 Keith Parkansky All rights reservedDuplication of any portion of this site or the material contained herein without

    the express written consent of Keith Parkansky, USA is strictly prohibited.

    This site is in no way affiliated with the Debian Project, the debian.org Web site, orSoftware In The Public Interest, Inc. No endorsement of this site by the Debian Projector Software In the Public Interest is expressed or implied. Debian and the Debian logoare registered trademarks of Software In The Public Interest, Inc. Linux is a registeredtrademark of Linus Torvalds. The Tux penguin graphic is the creation of Larry Ewing.

    LIABILITY

    IN NO EVENT WILL KEITH PARKANSKY OR BLUEHOST INCORPORATED OR ANY OF ITS' SUBSIDIARIES BE LIABLE TO ANYPARTY (i) FOR ANY DIRECT, INDIRECT, SPECIAL, PUNITIVE OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR INFORMATION, AND THELIKE), OR ANY OTHER DAMAGES ARISING IN ANY WAY OUT OF THE AVAILABILITY, USE, RELIANCE ON, OR INABILITY TO USE

    THE INFORMATION, METHODS, HTML OR COMPUTER CODE, OR "KNOWLEDGE" PROVIDED ON OR THROUGH THIS WEBSITE,COMMONLY REFERRED TO AS THE "ABOUT DEBIAN" WEBSITE, OR ANY OF ITS' ASSOCIATED DOCUMENTS, DIAGRAMS,IMAGES, REPRODUCTIONS, COMPUTER EXECUTED CODE, OR ELECTRONICALLY STORED OR TRANSMITTED FILES ORGENERATED COMMUNICATIONS OR DATA EVEN IF KEITH PARKANSKY OR BLUEHOST INCORPORATED OR ANY OF ITS'

    SUBSIDIARIES SHALL HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, AND REGARDLESS OF THE FORM OFACTION, WHETHER IN CONTRACT, TORT, OR OTHERWISE; OR (ii) FOR ANY CLAIM ATTRIBUTABLE TO ERRORS, OMISSIONS,

    OR OTHER INACCURACIES IN, OR DESTRUCTIVE PROPERTIES OF ANY INFORMATION, METHODS, HTML OR COMPUTERCODE, OR "KNOWLEDGE" PROVIDED ON OR THROUGH THIS WEBSITE, COMMONLY REFERRED TO AS THE "ABOUT DEBIAN"WEBSITE, OR ANY OF ITS' ASSOCIATED DOCUMENTS, DIAGRAMS, IMAGES, REPRODUCTIONS, COMPUTER EXECUTED CODE,

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    2 of 33 9/1/2010 5:37

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm
  • 8/8/2019 Linux DNS Server - LAN

    33/33

    OR ELECTRONICALLY STORED, TRANSMITTED, OR GENERATED FILES, COMMUNICATIONS, OR DATA. ALL INFORMATION,METHODS, HTML OR COMPUTER CODE IS PROVIDED STRICTLY "AS IS" WITH NO GUARANTY OF ACCURACY AND/OR

    COMPLETENESS. USE OF THIS SITE CONSTITUTES ACCEPTANCE OF ALL STATED TERMS AND CONDITIONS.

    Linux DNS Server - How To Set Up Static or Dynamic DNS for Your ... http://www.aboutdebian.com/dn

    http://www.aboutdebian.com/dns.htmhttp://www.aboutdebian.com/dns.htm