Personal Cloud #1 - DNS and Domain names

Let’s talk about THE CLOUD!

No, not weather clouds and certainly not the buzzword that TV media loves to use out of context so much. Let’s talk about distributed, elastic, public computational services, and how you can make your own.

I know that definition is a bit wordy, but it is accurate. The cloud is just a buzzword that describes the 3 main characteristics of public cloud computing. First is distributed, computational power is managed by multiple, hundreds, or even thousands of interconnected systems. Second is elasticity, cloud services are designed to react automatically to user demand, being able to add more resources as well as reduce them accordingly to meet the current demand. And last is public accessibility, the systems that make up the cloud network are housed in physical servers in multiple locations or even separate machines while being accessible over the internet.

The cloud is most certainly the next frontier of our technological age, and only seems to increase in demand as internet connectivity becomes more ubiquitous and end-user speeds increase.

So what about hosting your own cloud? It sounds complicated but it really isn’t. You can host your own email, files, voice chat and more all under your control.

This is going to be a multi-part series about creating your own personal cloud. This week we start with setting up the virtual machine and getting a DNS server working. So let’s get started!

We are going to use DigitalOcean for the VPS, Namecheap for the domain, and Debian Jessie for the OS.
You could use pretty much any other cloud provider or domain registrar and the steps should be basically the same.

Let’s start with heading over to Namecheap and picking up a domain name. Keep an eye out for specials, you can usually get some domains for $0.99 a year on there. And as a humble request if you would use the namecheap affiliate link I have down below when you buy a domain name, I would greatly appreciate every little bit to help offset the cost of these videos.

https://www.namecheap.com/?aff=107064

So after you get the domain, head to the dashboard and hit “Manage” on your domain name. Go to the “Advanced DNS” tab. Down at the bottom we want to register a nameserver.

Head over to DigitalOcean and spin up a Debian VM. Make sure to use an SSH key.

If you set the hostname as the domain you bought then DigitalOcean will automatically setup reverse-DNS on the IP which we will need for a later step when we get to postfix.

If you plan on creating more than one VM or plan to add more in the future, make sure to give the VM an actual unique hostname, such as vm-1.yourdomain.com

So after it is created we need the IPv4 address for NameCheap. Go ahead and copy that. Back on NameCheap click “Add Nameserver” and paste the IP in there. Add a second nameserver and paste the same IP in there. Back on the Domain tab change the nameservers to Custom DNS and add ns1.yourdomain.com and ns2.yourdomain.com.

Now let’s go setup Bind9 on our VM.

Install bind9 and bind9utils
Edit /etc/bind/named.conf.local and add our first domain:

zone “domain.com" {
type master;
file "/etc/bind/zones/db.domain.com";
allow-transfer { none; };
};

Next edit the zone file itself and add in this template:

;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     ns1.domain.com. admin.domain.com. (
                          1         ; Serial
                       5000         ; Refresh
                       5000         ; Retry
                    2419200         ; Expire
                      50000 )       ; Negative Cache TTL
;
; Name servers
domain.com.    IN      NS      ns1.domain.com.
domain.com.    IN      NS      ns2.domain.com.
; A records for name servers
ns1             IN      A       123.123.123.123
                IN      AAAA    1234:1234:1234:1234::1234:1234
ns2             IN      A       123.123.123.123
                IN      AAAA    1234:1234:1234:1234::1234:1234
; Mail
                IN      MX  10  domain.com.
; Other A records
@               IN      A       123.123.123.123
                IN      AAAA    1234:1234:1234:1234::1234:1234

Go ahead and add to the end the current VM you are on so you can use the domain to connect:

VM-1            IN      A       123.123.123.123
                IN      AAAA    1234:1234:1234:1234::1234:1234

Any time you edit this file to add new DNS records, you have to increment the Serial number by 1 so bind knows to reload it and push the changes. Reload bind9’s config: service bind9 reload

Now we wait for the DNS server registration and the domain name updates to propagate. This could take up to 2-3 days, but should happen within a few hours depending on your ISP’s DNS, but if you are watching this video you should be using Google’s DNS or OpenDNS anyway.

So after a few hours or a day, check back and see if it works. Ping your server using the domain name. If you get a reply then success! You have just setup your own DNS server! You can use this DNS server for other domains too, just add another zone to the config and another zone file with the new domain. Just make sure to keep the “Name servers” line pointing to ns1.domain.com and ns2.domain.com of your first domain, and they set the DNS servers in Namecheap to those nameservers.

Make sure to enable the firewall on your VM. Easiest way to do this is with UFW.
Apt install ufw

Also make sure to allow port 22 for SSH, as well as port 53 for DNS queries.

Ufw allow 22
Ufw allow 53

Then ufw enable to turn it on.

Next week: Nginx and Let's Encrypt!

9 Likes