This is what I did…
My broadband router provides a firewall service that prevents anything on the Internet from accessing my home network. This is a good thing. I can look out at the Internet and download webpages but nothing on the Internet can look at my computer.
So first I need to permit anyone on the Internet to access the webpages being served by my Pi, and nothing else.
These webpages are being served using HTTP which by default uses network port 80. So if I get my router to pass any network traffic it receives on port 80 to my Pi then the web service it is running can deal with it. If that traffic consists of HTTP requests for webpages then the Pi will provide them. If the traffic contains anything else then it will be ignored.
This selective passing on of network traffic is called Port Forwarding.
So I logged onto my router and under the settings menu there was an option for Port Forwarding. I then selected the required port, these were listed by name rather than port number so I selected ‘HTTP Server (World Wide Web)’ and I could then select the computer I wanted to forward the network traffic to, my Pi.
After saving those router changes I could now view my website via the Internet by using my router’s IP address. i.e. by visiting http://188.8.131.52/ from a web browser.
[Note: this is different from the IP address of my Pi on my home network, which is still 192.168.1.84 and can also be used to access my website, but only from within my home network. My router’s IP address is unique on the Internet and my router is now passing any HTTP traffic it receives onto my Pi, whose own IP address is only valid within my home network.]
A Domain Name:
I can now visit my website from anywhere on the Internet but I can’t expect any other visitors because they won’t know my IP address. I need a proper website name which can then be translated into my IP address. [This translation function is called a Domain Name Service or DNS.]
To get a name for my website (called a domain name) I’d like to say that I shopped around and got the best deal available. Actually I just visited a major domain name reseller’s website and quickly bought benningtons.net before someone else beat me to it! The process is very easy and quite addictive. I could have easily bought more but one domain name is all I need.
bennington.net would have cost $2,000 but benningtons.net will cost me just £8.39 a year. I can shop around and transfer the name to another domain reseller if necessary but so far 1&1 have been ok with only one follow-up sales call, so far.
Domain Name Service (DNS):
Now to make the connection between my new domain name and my home IP address.
During the process of registering my new domain name I setup an admin account with 1&1. I can now use that account to login and change the ‘name server’ settings for my domain.
Each domain can have up to four name servers registered. Type benningtons.net into your browser and you are first directed to the nearest of these name servers to then be redirected to my home IP address and so to my Raspberry Pi web server. [Actually that’s what happens the first time you visit but for subsequent visits my IP address will be remembered (cached for a short while) and the process will be a bit quicker.]
I’m using DNSexit.com as my DNS providor so I therefore changed the name servers for my domain name at 1&1 to be dns1.dnsexit.com, dns2.dnsexit.com, etc…
Unlike when I registered my domain name, this time I did do a fair amount of research into DNS services. DNSexit.com is not only free, they have been very reliable and, for reasons that will follow, technically capable.
I can now login to my DNSexit.com admin account and allocate my home IP address to benningtons.net.
Voila! I can now visit my website from anywhere on the Internet by typing www.benningtons.net into a browser.
Dynamic DNS (DDNS):
Actually there is one last problem to overcome. I have a cheap (I wish!) home broadband service that doesn’t provide a dedicated IP address. This means that every day or so my router will be allocated a new IP address. [This happens because there are not enough IP addresses to go around. So by reallocating them my Internet Service Providor (ISP) only needs enough IP addresses for whoever is currently online. Even though I want my Raspberry Pi to always be online.]
This means that the link between my domain name and my IP address will regularly be broken and will stay broken until I tell my DNS provider my new IP address.
The solution is to use a Dynamic DNS and this is why I chose DNSexit.com. Not only do they provide a DDNS they also suggest solutions for Linux as well as Windows.
DDNS works by running a client program from within my home network to check my routers external IP address (the one provided by my ISP). Should that IP address change then a notification can be automatically sent to DNSexit.com who can update their domain name servers with my new IP address.
Their name servers also notify all vistors that my IP address has a short lifespan. This should prevent any visitors from continuing to use cached details for my old IP address because they’ll be checking more frequently than usual to see if my IP address has changed.
The whole DDNS process isn’t flawless. The short lifespan on my DNS can impair performance and some disruption may occur for a minute or two when my IP address changes. But that happens infrequently and so for a cheap home hosted website DDNS is ideal.
DNSexit.com provide many sample DDNS client programs (to check if my IP address has changed) or I could even write my own. I downloaded their ipUpdate client, followed the README.txt instructions and made the following notes:
1. The client could run on any computer within my home network, although one that is always running. It doesn’t have to run on the Pi web server but I did and it doesn’t appear to cause any performance issues.
2. No additional packages were required on my Pi. Perl version 5 or higher is a requirement but that was already installed.
3. There’s a step in the setup.pl script that logs me into my DNSexit.com account and asks me to select my domain name from a list of only one. This wouldn’t work for me and Perl is not easy to follow but I eventually found it required a ‘space’ character to be typed after my name selection?
4. After completing the setup.pl script the client program is set to start running every time the Pi boots up.
5. This client program wakes up every few minutes (adjustable) and keeps a running commentary in /var/log/dnsexit.log which I expect will get rather large as time goes by. Initially it’s nice to see what the program is doing but I’ll have to cut back on the logging to perhaps only log when the IP address actually changes.
And that’s it! My Raspberry Pi hosted website has now been running for a couple of weeks and has calmly survived several IP address changes.
Categorised as: Computer Stuff
Comments are disabled on this post