Pi to WordPress – Part 4: Domain Name and DNS
This is part 4 of a series, documenting the setup of an out-of-the-box Raspberry Pi to a self-hosted SSL WordPress site.
At this stage your self-hosted WordPress site should be accessible over HTTP on your public IP address, http://x.x.x.x. But of course nobody is going to access it this way; you need a catchy domain name!
Registering a domain name is simple enough, but will likely come at a small expense, depending on what domain name and top-level domain (TLD) you want to use.
There are “free” domains out there (check out freenon.com for example), but you will be limited to unfamiliar TLDs such as .gq, .tk, .ml etc. At best these domains look a little unprofessional, and at worse can often be associated with and classified as spam domains. I also can’t vouch for the support and DNS services that free domain registrars provide, and how “free” your domain may be after the first year.
You don’t have to spend an arm and a leg to get a decent and reliable TLD domain; I registered defaultroot.com with GoDaddy for 1 year for about €10. With some patience on my part it probably could have been cheaper! Discounts generally apply for multi-year purchases. So choose any decent domain registrar and find a domain name you are happy with. Be aware that domain registration is often bundled with web-hosting and vice-versa. We’re hosting our own site, so don’t need hosting! But I will discuss this more at the end of this series, as you need to weigh up the pros/cons and costs of running your own web server compared with the relative ease and convenience of a hosted solution; bundled domain name and hosting being one such benefit.
Once you’ve purchased your domain name, you will need to point the DNS for your domain (in my cause defaultroot.com) to your public IP address, which we discovered in the previous part of this guide.
When a user types in https://defaultroot.com, their machine will do a DNS lookup for defaultroot.com to their primary DNS server, which is often their home router. If the router does not have an IP for this domain cached, it will make a DNS query to a public DNS server, generally your ISP DNS servers, to eventually return your public IP address to the browser, which can then initiate a TCP connection directly to your IP.
It’s very simple to update the DNS record for your domain. Using GoDaddy as an example, you log onto the site, select your domain, click DNS Management, and amend the A record value for the domain with your public IP address. The A record is the value returned when a device makes a DNS lookup for your domain name. You can ignore all other types for now, and leave TTL settings as their default.
It may take a while for the change to take effect. You can test it has worked by running a DNS query against your domain registrar’s DNS servers, but more realistically you’ll want to see if the change has replicated to more popular and widely used DNS servers, such as Google DNS on 188.8.131.52.
To test this on a Windows machine, in cmd run:
nslookup defaultroot.com 184.108.40.206
If successful, it will return the public IP you assigned to the domain’s A record:
C:\Users\admin>nslookup defaultroot.com 220.127.116.11 Server: dns.google Address: 18.104.22.168 Non-authoritative answer: Name: defaultroot.com Address: 22.214.171.124
With the domain name registered and the A record pointing to our public address, you should now be able to open a web browser to https://defaultroot.com. Bear in mind we have not yet configured HTTPS, so you will not be able to make a HTTPS connection, which some browsers will default to if you don’t specify the full http:// address in the address bar.
We’ll address this issue in the next part, where we’ll generate a free SSL certificate and install it on our Pi, allowing for a trusted, secure, encrypted HTTPS connection.