This document is a supporting document for the project Repurposing My Old Phone into an ARM Linux Web Server. This document is about buying a domain name, configuring DNS, and applying the security features provided by the DNS registrar.
Buying a domain is not strictly necessary, so before you spend any money, learn what happens if you buy a domain vs if you don't below.
Domain name is not what gets people to your website, IP address is. Which means, just knowing the IP address is enough to visit a website. For instance, to visit www.google.com, you could put 142.250.65.78 (this may change as time passes) in the URL bar and you land at www.google.com. So why buy a domain name, since IP address is free(not quite)?
If you skip buying a domain, and just get an IP address, you should tell people that your website is at xxx.xxx.xx.xx instead of saying your website is at www.awesomecoolreader.com. The problem is that people can't remember IP addresses as easily as website names, and if you can't obtain a static IP address (common case in residential networks and home labs), your website's IP address keeps changing, so today it's xxx.xxx.xx.xx, tomorrow it is xyy.yy.yx.xy. So, people can't access the website after the IP address has changed, and worse, even you can't access it before you figure out what it has changed to. There are many other reasons why DNS servers are used to resolve domain names into IP addresses instead of just using the IP addresses, but these two reasons should help you make your decision. If you don't care about other people visiting your website, you can skip buying a domain name, but if you want easier access, and want to present it to people, buying a domain name is a better choice.
Here is the a better explanation that you will definitely understand.
Buying a domain name:
Running straight up IP address:
Yes, you read that correctly! you can get domain names for around 10$ a year (do look at the renew cost tho). So if you decided to buy a domain name, you can follow along with the rest of this section. But if you decided to not buy a domain name right away, I want to tell you to not worry about it and still follow along with this section in case you ever change your mind.
You can do your own research and find an fitting domain registrar. For me, it was Cloudflare Registrar. I wasn't picky about the registrar for my first website, but Cloudflare Registrar exceeded my expectations. The amount of support, and security you get from Cloudflare just by buying one of their inexpensive domain names is huge. So follow me if you picked Cloudflare Registrar too. If you decided to go with another registrar, this document can still provide you with some valuable information.
You can search Cloudflare Registrar in google, then navigate to products, or follow the link https://www.cloudflare.com/products/registrar/. Then search for the domain name you want to obtain. You might not find the exact domain name you were looking for in which case you have to make a little tweak on the name like you did when you made your Instagram account. There are a lot of options including different TLDs (the thing after the .), but to increase your aura, you can try and get the .com TLD. www.awesomecoolreader.sketchyTLD might raise some side eyes, whereas www.awesomecoolreader.com is easily accepted. I am buying the name sushantadk.com.
Find the name you like, then give Cloudflare all your info and money and you should be good to go!
For people to visit your website through the domain name, the domain name needs to know where your website is. So, we need to assign an IP address to the domain name.
DNS servers host data in zones. Right now, we are only concerned with the A zone. This zone is also called a host record which records the hostname and IPv4 address. When a DNS client queries the name using forward lookup request, DNS responds with the IPv4 address from this record.
To assign the IP address, let's first login to Cloudflare Registrar. On the right sidebar, click on Domains, then overview. Find your domain and click on it. Again, from the sidebar, click DNS then Records. Choose the option to Add record. Select type: 'A', name '@', and IPv4 address, 'yourPublicIPv4Address', enable proxy, and save. We enter @ for Name because we are hosting it from the root directory, for ex: awesomecoolreader.com, and we enter the public IPv4 address so that the world can find us, and you can obtain it by running curl ipinfo.io/ip from your terminal or by visiting https://whatismyipaddress.com/.
But what if people search for www.awesomecoolreader.com? The 'www' part is handled through a canonical name(CNAME), which is a DNS record that maps one domain name to another. In this case, www.awesomecoolreader.com can mapped to awesomecoolreader.com which has our IP address.
To do this, click on Add record again. Select type: 'CNAME', Name: 'www', and Target: 'yourRootDomain', and save. Now you should have two DNS records, A record with your root domain pointing to your public IP address, and CNAME record with your alias pointing to your root domain.
So now, people searching awesomecoolreader.com are directed to your public IPv4 address, and people searching for www.awesomecoolreader.com are directed to awesomecoolreader.com, which again directs them to your public IPv4 address.
Just pointing the domain names to your public IPv4 address is not enough to get visitors to your server. We also have to configure the router to send web traffic to our server. To do this, enter ip route on your terminal. The terminal will return: 'Default via' followed by an IP address, which will look like 192.168.1.1. This is your default gateway. Open up a browser and enter this IP address. This will take you to your router's login page. If you know the password(and if it's default, please change it), you can login but if you don't you can follow the password recovery instructions. After logging in, the router, Select advanced settings and look for something along the lines of Port Forwarding, Port Mapping, or Firewall Rules. We are trying to find the section which lets us forward a specific traffic to a IP address. In my router, it is under Port forwarding.
Once you are in the Port Forwarding settings, it'll let you add a rule. For the initial configuration, do Application: Apache(or whatever server you are running), Original Port: 80, Protocol: TCP, Fwd to Addr: yourServer'sIPAddress(you can obtain it by running ifconfig on your server's terminal), fwd to Port: 80, Schedule: Always. Notice that we are forwarding port 80 traffic, which is the HTTP traffic, and forwarding the traffic to port 80 on the server. HTTP traffic isn't secure because the traffic isn't encrypted, so the browser will throw warnings when someone visits your website. Let's fix that.
By default, the Apache server is listening on port 80.