Skip to main content

How to Setup a DNS Server in Ubuntu

Overview
Would you like to setup a DNS Server in Ubuntu? How about setting up a private internal domain name at home? Well, you’ve 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’s a good question. I’ve 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’s jump right to it!

What is DNS?
First of all, let’s cover the basics. What is DNS? DNS stands for Domain Name Server. It’s 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.

A typical DNS request is when someone is accessing a website. Let’s 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’t 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’s browser. If the domain name is not found, a “server not found” message is displayed on the browser.

Assumptions
Enough with the DNS background. Let’s now start configuring our own DNS server. Let’s assume that we have the following: we want to create a private internal domain name called mydomain.com, our private internal network is 192.168.0.x and our router and gateway is set at 192.168.0.1. Let’s assume all devices are going to be configured with static IP addresses. 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 3 computers connected to our network:

  • Ubuntu Server, the DNS server - 192.168.0.9
  • Ubuntu Desktop - 192.168.0.10
  • PC - 192.168.0.11

Instructions
1. To install the DNS server, we need to install Bind 9.

  1. $ sudo apt-get install bind9

2. Let’s configure Bind. We need to touch 5 files.

We will edit 3 files.

  • /etc/bind/named.conf.local
  • /etc/bind/named.conf.options
  • /etc/resolv.conf

We will create 2 files.

  • /etc/bind/zones/mydomain.com.db
  • /etc/bind/zones/rev.0.168.192.in-addr.arpa

A. First step. Lets add our domain zone - mydomain.com.

  1. $ sudo vi /etc/bind/named.conf.local
  1. # Our domain zone
  2. zone "mydomain.com" {
  3. type master;
  4. file "/etc/bind/zones/mydomain.com.db";
  5. };
  6. # For reverse DNS
  7. zone "0.168.192.in-addr.arpa" {
  8. type master;
  9. file "/etc/bind/zones/rev.0.168.192.in-addr.arpa";
  10. };

Save file. Exit.

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.

B. Let’s add the DNS servers from your ISP. In my case, I’m using Comcast DNS servers. You can place the primary and secondary DNS servers here separated by semicolons.

  1. $ sudo vi /etc/bind/named.conf.options
  1. forwarders {
  2. 68.87.76.178;
  3. };

Save file. Exit.

C. Now, let’s 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.

  1. $ sudo vi /etc/resolv.conf
  1. search mydomain.com.
  2. nameserver 192.168.0.9

D. Now, let’s define the zones.

  1. $ sudo mkdir /etc/bind/zones
  2. $ sudo vi /etc/bind/zones/mydomain.com.db
  1. $TTL 3D
  2. @ IN SOA ns.mydomain.com. admin.mydomain.com. (
  3. 2007062001
  4. 28800
  5. 3600
  6. 604800
  7. 38400
  8. );
  9. mydomain.com. IN NS ns.mydomain.com.
  10. ubuntudesktop IN A 192.168.0.10
  11. www IN CNAME ubuntudesktop
  12. pc IN A 192.168.0.11
  13. gw IN A 192.168.0.1
  14. TXT "Network Gateway"

The TTL or time to live is set for 3 days
The ns.mydomain.com nameserver is defined
ubuntudesktop, pc and gateway are entered as an A record
An alias of www is assigned to ubuntudesktop using CNAME

E. Let’s create a “rev.0.168.192.in-addr.arpa” file for reverse lookup.

  1. $ sudo vi /etc/bind/zones/rev.0.168.192.in-addr.arpa
  1. $TTL 3D
  2. @ IN SOA ns.mydomain.com. admin.mydomain.com. (
  3. 2007062001
  4. 28800
  5. 604800
  6. 604800
  7. 86400
  8. )
  9. IN NS ns.mydomain.com.
  10. 1 IN PTR gw.mydomain.com.
  11. 10 IN PTR ubuntudesktop.mydomain.com.
  12. 11 IN PTR pc.mydomain.com.

3. Let’s restart Bind to activate our latest changes.

  1. $ sudo /etc/init.d/bind9 restart

4. Finally, let’s test our new domain and DNS entries.

Dig

  1. $ dig mydomain.com

Nslookup

  1. $ nslookup gw

Popular posts from this blog

Freenas Snapshots Replication Backup

Mungkin anda sudah mengetahui Freenas sebelumnya. Ya..Freenas adalah salah satu software NAS Storage berbasis FreeBSD. Karena kehandalannya, Freenas banyak digunakan sebagai NAS Storage di dunia IT. Saya pernah berfikir bagaimana jika Freenas yang kita gunakan mengalami masalah, crash misalnya. Mungkin jika hardisknya menggunakan RAID bisa tinggal ganti disknya. Bagaimana jika tidak ada RAID (hari gini Server gak ada Raid hdewww heee) atau hal lain yang membuat data tidak bisa digunakan di Freenas. Tutorial ini saya buat untuk berbagi ilmu kepada rekan2 sekalian. Saya akan coba membuat Replikasi Freenas. Dimana Dataset pada salah satu Freenas (Freenas A) akan di snapshot dan di replikasikan ke Freenas B Hal yang perlu disiapkan : 1.  Freenas A : 192.168.100.1 (Primary) Disk 8GB x 2 2.  Freenas B : 192.168.100.2 (Secondary) Disk 8GB x 2 SETING FREENAS A DAN B Kita akan buat raid mirror untuk 2 disk. Storage - Volume Manager   Volume Name :

Migrasi Nextcloud 19 ke Nextcloud 20.02 (Beda Server)

Server A : 192.168.0.1 (Server lama : Centos 7), port 80 Server B : 192.168.0.2 (Server baru : Centos 8), port 80 Nginx Load Balance : 192.168.0.10, port 443 untuk SSL Tahapan : 1. Upgrade Nextcloud 19.0.3 ke 19.0.5 (server lama) 2. Instalasi server baru (Centos 8) 3. Backup dan restore data nextcloud dan databas ke server baru 4. Konfigurasi Nextcloud di server baru dan Nginx Server 5. Finish A. Upgrade Nextcloud 19.0.3 ke 19.0.5 Untuk Upgrade 19.0.3 ke 20.0.2 tidak dapat dijalankan secara langsung. Harus bertahap upgrade ke versi minor. 19.0.3 -> 19.0.5 secara otomais. Dan upgrade ke 20.0.2 secara manual. 1. Login ke Nextcloud 2. Setting - Administration-Overview 3. Versi yang tersedia 19.0.5 5. Pilih Open updater  4. Start Update 5.  Pilih No (for usage of the web based updater), untuk mode maintenance dan upgrade via console. 6. Masuk ke console dan ke directory /var/www/html/nextcloud 7. Jalankan $ sudo   - u  apache   php occ upgrade 8. Maintenance mode masih dalam keadaan

Zimbra Error Subject : ***UNCHECKED***

Beberapa hari yang lalu Subject email Zimbra selalu di tambahkan tulisan ***UNCHECKED***. Padahal tidak ada perubahan konfigurasi mail server sebelumnya. Cari di google ada beberapa referensi yaitu merubah file /opt/zimbra/. Tahapan : #su root #cd /opt/zimbra/amavisd/bin #cp -pa amavisd amavid.org #vi amavisd Rubah isi file di baris : #su zimbra $undecipherable_subject_tag = '***UNCHECKED*** '; menjadi $undecipherable_subject_tag = '';   $zmamavisdctl restart Di hari berikutnya saya coba cek kembali utilisasi mail dengan 'top'. Terilhat penggunaan clamd sebesar 100%. Coba dicek di log /var/log/zimbra.log |grep clamd hasilnya mail amavis[26778]: (26778-07) ClamAV-clamd: All attempts (1) failed connecting to /opt/zimbra/data/clamav/clamav.sock, retrying (1) Oct 24 10:10:43 mail amavis[26778]: (26778-07) (!)connect to /opt/zimbra/data/clamav/clamav.sock failed, attempt #1: Can't connect to UNIX socket /opt/zimbra/data/clamav/clamav.sock: Co