Preface

Here’s to hopefully getting this done in under an hour (as opposed to the quasi 4 full days that it took me the first time).

Requirements

  • Something to act as a webserver (Raspberry Pi in this example)
  • A wee bit of money for a domain ( £/$/€ 0.99 for 1st year if you choose a shitty one, but who cares!)
  • Basic networking knowledge will help

If you have a god, I’d start praying!

Here goes trying to explain what I want to do in a couple of sentences. I have a Raspberry Pi which I use to host some fun personal projects. Recently, the stuff I’ve been working on required me to create a simple REST endpoint to access a database. I’ve done this before using Java, but I wanted to try something new, and frankly, more lightweight this time round. Enter Nodejs. Never used it, and 7 days ago I didn’t even know what it did. Fantastic, we know what we’re using for that. Wrote some simple code, using Express as the server, and created a sample endpoint (/api/). Now, I wanted to access this using an iOS app, and I also wanted to send stuff through HTTPs for security reasons. First I generated some self signed certificates, and used those. However, iOS being smart, it wouldn’t let me access the endpoint since the CA (myself) wasn’t trusted. Touché Apple, touché. Cool, an extra challenge! So I proceeded to spend the next 2 days trying to figure out how in the hell I could get myself a free/cheap (free) certificate from a trusted CA. Enter Let’s Encrypt. These guys give you a free certificate with a three month validity, and it should, with my current setup, renew itself automatically. Finally, I obviously didn’t want, and frankly wouldn’t have been allowed, to use my IP in the address. For three reasons, it’s dynamic, you can’t generate certs for an IP, and to a lesser extent privacy (because you can easily find that out). Alright, so I got myself a cheap domain form GoDaddy, 1 year lease, for 99c. This is for TESTING. I won’t need it for a year. I’ll just buy a different one after. But pointing this to my IP wouldn’t fix the dynamic IP problem. Enter no-ip.com. These guys are legit awesome, and you can just use them and leave out GoDaddy. No-ip gives you a hostname, lets you point it towards your dynamic IP, and gives you a program (a cron job of sorts I believe) to run on your server which will notify their DNS whenever the dynamic IP changes. I haven’t tested whether this works yet, since my IP hasn’t changed since I set it up, but only time will tell. Also free, but they require you to extend the lease (or whatever) every month. I don’t know how this is done, but I think you just need to click a button in an email. Alright. That only took around 430 words to explain. Child’s play. Ooooh, let’s put on some Drake.

We’re gonna go about this backwards, simpler that way. You can choose to skip the GoDaddy stuff.

Tutorial

Getting a hostname from no-ip

This is the simplest part so let’s get it over. Navigate to no-ip, and set yourself up with a new account.

2016-10-13-15_55_07

Fill in the basic stuff and let’s move on. For the love of pizza, don’t use your name. Once you’ve activated your account, go to the control panel and update the hostname’s A record such that it points towards your IP. If you don’t know it, literally Google “What is my IP?”. Now, you probably want to go to the “Device Configuration Assistant” and follow the instructions there. No point in repeating here. Note, this is important only if your have a dynamic IP. Which you probably do. You might also be able to set this up from your router… i.e. your router will tell no-ip when it’s public IP changes. Mine isn’t that smart. But I just followed the instructions on there.

Check that one off. It’s done.

Using GoDaddy to get a domain and point it at your no-ip hostname

First part’s simple. Choose a domain, buy it. You don’t need me for that. A retarded housefly could do it. Once that’s done, come here and we’ll configure it. Start by clicking on ‘Manage DNS’.

2016-10-13 15_55_07-.png

Very quick intro to DNS. An A record is used to point a domain to an IP. A CNAME can be used to point to an other address, and link that to a subdomain which serves as the host. Slightly discombobulating I know. If you take a gander at the default setting it’ll make a lot more sense. You have an A record which points to you IP, with the host set to @ (meaning root, i.e. example.com), and a CNAME with the host set to WWW (among others), with the value set to @. Therefore, accessing http://www.example.com, as well as example.com, point to the same location. But we don’t want that A record. So go ahead and delete it. Remember, we had set up the A record over at no-ip. Now, change the www CNAME entry to point towards the hostname no-ip gave you, and save your changes.

2016-10-13 16_30_55-.png

As it stands, you’d be able to access your site using http://www.example.com. But typing in example.com wouldn’t work. Why? I just told you why good sir! You don’t have a record for that.2016-10-13 15_55_07-.png But worry not, if you scroll all the way to the bottom, you can set a forwarding rule. Forward your domain to http://www.example.com without masking (why bother). This way, when someone tries to access example.com (which would result in an error), they are automatically redirected to http://www.example.com (which is where you have all your goodness). Now, for the sake of this example I’m using www, but you can name the subdomain whatever you want. For instance, I set mine to ‘api’. Because I’m not creating a website, merely somewhere to access my REST endpoint. So set this to whatever makes you happy… dog, cat, bird. I frankly couldn’t care. What’s important is that the CNAME host and the subdomain specified in the forwarding are the same.

And that’s that… http://www.exmaple.com OR exmaple.com point to mynoiphost.ddns.net, which in turn points to xxx.xxx.xxx.xxx (which is dynamic).