{"id":359,"date":"2011-12-24T12:39:08","date_gmt":"2011-12-24T12:39:08","guid":{"rendered":"https:\/\/noi3.org\/site\/?p=359"},"modified":"2023-03-07T07:42:33","modified_gmt":"2023-03-07T07:42:33","slug":"how-to-setup-a-dns-server-in-ubuntu","status":"publish","type":"post","link":"https:\/\/site.noi3.org\/?p=359","title":{"rendered":"How to Setup a DNS Server in Ubuntu"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/storage.googleapis.com\/static.configserverfirewall.com\/images\/ubuntu\/ubuntu-set-dns-server.png\" \/><\/p>\n<p><strong>Overview<\/strong><br \/>\nWould you like to setup a DNS Server in Ubuntu? How about setting up a private internal domain name at home? Well, you\u2019ve come to the right place. There are number of tutorials on the internet showing you how to setup a DNS Server with Ubuntu using Bind 9. So, why another how-to document? That\u2019s a good question. I\u2019ve decided I needed to write a simple tutorial that anyone with a little bit of Linux knowledge would be able to follow. In the process, I hope readers are also able to learn how DNS works. Ok, let\u2019s jump right to it!<\/p>\n<p><strong>What is DNS?<\/strong><\/p>\n<p>First of all, let\u2019s cover the basics. What is DNS? DNS stands for Domain Name Server. It\u2019s a service that runs on a server that translates humanly recognizable domain names such as www.yahoo.com or www.google.com into its assigned IP addresses. If the DNS server does not recognize the domain name being requested, it will forward the domain name request to another DNS server and so on until the name is resolved.<\/p>\n<p>A typical DNS request is when someone is accessing a website. Let\u2019s use the www.yahoo.com domain as an example. When a user clicks a Yahoo link or types the Yahoo URL on the address bar of the browser, the DNS server processes the domain request. If it doesn\u2019t find www.yahoo.com on its DNS table, it will forward the request to another DNS server with a higher authority and so on until it finds a server with the URL entry. The IP address information is then sent back to the user\u2019s browser. If the domain name is not found, a \u201cserver not found\u201d message is displayed on the browser.<\/p>\n<p><strong>Assumptions<\/strong><\/p>\n<p>Enough with the DNS background. Let\u2019s now start configuring our own DNS server. Let\u2019s assume that we have the following: we want to create a private internal domain name called <strong>mydomain.com<\/strong>, our private internal network is <strong>192.168.0.x<\/strong> and our router and gateway is set at <strong>192.168.0.1<\/strong>. Let\u2019s assume all devices are going to be configured with <strong>static IP addresses<\/strong>. Normally, most computer systems nowadays are configured to automatically obtain IP addresses from the DHCP server\/router. In this example, we will use static IP addresses to show how DNS works. Finally, we have <strong>3 computers<\/strong> connected to our network:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Ubuntu Server, the DNS server \u2013 192.168.0.9<\/li>\n<li>Ubuntu Desktop \u2013 192.168.0.10<\/li>\n<li>PC \u2013 192.168.0.11<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Instructions<\/strong><\/p>\n<p>1. To install the DNS server, we need to install Bind 9.<\/p>\n<pre lang=\"bash\"> sudo apt-get install bind9<\/pre>\n<p>2. Let\u2019s configure Bind. We need to touch 5 files.<\/p>\n<p>We will edit 3 files.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\/etc\/bind\/named.conf.local<\/li>\n<li>\/etc\/bind\/named.conf.options<\/li>\n<li>\/etc\/resolv.conf<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>We will create 2 files.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\/etc\/bind\/zones\/mydomain.com.db<\/li>\n<li>\/etc\/bind\/zones\/rev.0.168.192.in-addr.arpa<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>A. First step. Lets add our domain zone \u2013 mydomain.com.<\/p>\n<pre lang=\"bash\"> sudo vi \/etc\/bind\/named.conf.local<\/pre>\n<pre lang=\"bash\"> # Our domain zone zone \"mydomain.com\" {    type master;    file \"\/etc\/bind\/zones\/mydomain.com.db\"; };  # For reverse DNS zone \"0.168.192.in-addr.arpa\" {    type master;    file \"\/etc\/bind\/zones\/rev.0.168.192.in-addr.arpa\"; };<\/pre>\n<p>Save file. Exit.<\/p>\n<p>We just created a new domain. Please note: later we will create two files named mydomain.com.db and rev.0.168.192.in-addr.arpa files. Also, notice the reverse IP address sequence in the reverse DNS section.<\/p>\n<p>B. Let\u2019s add the DNS servers from your ISP. In my case, I\u2019m using Comcast DNS servers. You can place the primary and secondary DNS servers here separated by semicolons.<\/p>\n<pre lang=\"bash\"> sudo vi \/etc\/bind\/named.conf.options<\/pre>\n<pre lang=\"bash\"> forwarders {    68.87.76.178; };<\/pre>\n<p>Save file. Exit.<\/p>\n<p>C. Now, let\u2019s modify the resolv.conf file found in \/etc and place the IP address of our DNS server which is set to 192.168.0.9.<\/p>\n<pre lang=\"bash\"> $ sudo vi \/etc\/resolv.conf<\/pre>\n<pre lang=\"bash\"> search mydomain.com. nameserver 192.168.0.9<\/pre>\n<p>D. Now, let\u2019s define the zones.<\/p>\n<pre lang=\"bash\"> sudo mkdir \/etc\/bind\/zones sudo vi \/etc\/bind\/zones\/mydomain.com.db<\/pre>\n<pre lang=\"bash\"> $TTL 3D @ IN SOA ns.mydomain.com. admin.mydomain.com. (    2007062001    28800    3600    604800    38400 ); mydomain.com.  IN      NS         ns.mydomain.com. ubuntudesktop  IN      A          192.168.0.10 www            IN      CNAME      ubuntudesktop pc             IN      A          192.168.0.11 gw             IN      A          192.168.0.1                        TXT        \"Network Gateway\"<\/pre>\n<p>The TTL or time to live is set for 3 days<br \/>\nThe ns.mydomain.com nameserver is defined<br \/>\nubuntudesktop, pc and gateway are entered as an A record<br \/>\nAn alias of www is assigned to ubuntudesktop using CNAME<\/p>\n<p>E. Let\u2019s create a \u201crev.0.168.192.in-addr.arpa\u201d file for reverse lookup.<\/p>\n<pre lang=\"bash\"> sudo vi \/etc\/bind\/zones\/rev.0.168.192.in-addr.arpa<\/pre>\n<pre lang=\"bash\"> $TTL 3D @       IN      SOA     ns.mydomain.com. admin.mydomain.com. (                 2007062001                 28800                 604800                 604800                 86400 )         IN      NS      ns.mydomain.com. 1       IN      PTR     gw.mydomain.com. 10      IN      PTR     ubuntudesktop.mydomain.com. 11      IN      PTR     pc.mydomain.com.<\/pre>\n<p>3. Let\u2019s restart Bind to activate our latest changes.<\/p>\n<pre lang=\"bash\"> sudo \/etc\/init.d\/bind9 restart<\/pre>\n<p>4. Finally, let\u2019s test our new domain and DNS entries.<\/p>\n<p>Dig<\/p>\n<pre lang=\"bash\"> $ dig mydomain.com<\/pre>\n<p>Nslookup<\/p>\n<pre lang=\"bash\"> nslookup gw<\/pre>\n<p>5. That\u2019s it.<\/p>\n<p>If you enjoyed this article, please share it with others using the social buttons below. If you like to be updated when a new article is published, please subscribe via email, RSS or follow me on Twitter: @ulyssesonline.<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>Would you like to setup a DNS Server in Ubuntu? How about setting up a private internal domain name at home? Well, you\u2019ve come to the right place. There are number of tutorials on the internet showing you how to setup a DNS Server with Ubuntu using Bind 9. So, why another how-to document? That\u2019s a good question. I\u2019ve decided I needed to write a simple tutorial that anyone with a little bit of Linux knowledge would be able to follow. In the process, I hope readers are also able to learn how DNS works. Ok, let\u2019s jump right to it!<\/p>\n","protected":false},"author":1,"featured_media":8484,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[205,206,207],"class_list":["post-359","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-informatica","tag-dns","tag-server","tag-setare"],"_links":{"self":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts\/359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=359"}],"version-history":[{"count":1,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts\/359\/revisions"}],"predecessor-version":[{"id":8485,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts\/359\/revisions\/8485"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/media\/8484"}],"wp:attachment":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}