Skip to content

Port Forwarding

Brian Torkelson edited this page Sep 2, 2017 · 5 revisions

What is Port Forwarding

Now that your OctoPi is setup to accept connections from the internet its time to setup your router to forward these requests to your OctoPi. We do this by setting up what is called a Port Forward. By default your router allows all outgoing connections from your home network to the internet. But any incoming connections are rejected. This where we have a problem. We need to accept incoming connections directed to our OctoPi in order to access it remotely. We do this by setting up a Port Forward rule on your router. Basically it's an exception in your router's firewall to say "any incoming connections on port 443 will be accepted and forwarded to IP address 192.168.1.150".

I will do my best to explain the steps ahead, although being I do not know the brand or model of your particular router I will attempt to generalize the steps. Portforward.com is an excellent resource where you can look up your specific router and find detailed instructions on how to setup a static IP address and how to setup a port forward. If your router is not listed on portforward.com I would suggest going to the manufacturer's website to find instructions.

Log into Your Router

The first step is to log in to your router's configuration page. This can be done by typing your router's local IP address into your web browser. For most home networks this is either 192.168.1.1 or 192.168.0.1. You can be sure by opening the command prompt in Windows. To do this press the windows key and "R" at the same time to bring up the run dialogue box. Type cmd.exe. Once the command prompt open use comamnd

ipconfig /all

find the listing where it says default gateway. This is your router's IP address.

On Linux and Mac this is much easier. Open terminal and use command

netstat -rn

You will find your router's IP address under the Gateway column, usually in the row denoted as 0.0.0.0 or default.

Now that you are at the login page for your router you need to enter your username and password. You either know these credentials or you don't. Most routers will have a sticker on the bottom of them disclosing this information if you left them at their defaults. If not you can check this database to see if any of these login credentials work. If you changed the default username and password but forgot it, you may consider doing a full reset on your router...this will be a pain and I'm not responsible for what havoc may ensue.

Setup a Static IP Address

Hopefully you logged into your router without hassle. Before creating a Port Forward we need to give our OctoPi a static IP address. This is because our Port Forward will refer to only one IP address. If we allow the DHCP server on router to assign all IP addresses dynamically one day you may come home and your laptop my have the OctoPi's IP address assigned and exposed to the internet, thus a major security risk. Each router is different and runs different software, so this will be hard to generalize. My best advice is to go to the manufacturer's website of your router to look up exactly where to find these settings. Most routers have this under the DHCP section of the settings. You most likely will find an option to Assign Static IP Address. You will then be given (in most cases) a list of clients to pick from. Most likely it the OctoPi will show up with a host name of OctoPi or Raspberry Pi, choose the appropriate host and assign it an IP address. When I assign a static IP address I like to set it as something memorable, like 192.168.1.150.

Setup a Port Forward

Now that your OctoPi has a static IP address we can finally assign it a Port Forwarding rule. The same applies here, many routers use different software so it will be quite impossible for me to generalize this for you. Check your manufacturers website for detailed instructions.

You will be setting up a port forward rule for the IP address you assigned your OctoPi. For my case it will be 192.168.1.150 and you will choose the TCP protocol. Incoming and Outgoing port ranges will all be set to port 443. And if you chose this as a custom service feel free to name it whatever you like, I chose OctoPi so i can easily identify it if I ever make any changes.

Optional Webcam Only Stream

I set up the HAProxy config file to also allow you to forward port 9080 to your OctoPi. If you choose to do this simply create a second port forwarding. This time choose port 9080 for all incoming and outgoing ranges. If you choose to forward this port it will display your webcam stream only. There will be no password protection on this port either, but your OctoPi will remain secure, as only the webcam is visible. Use this option only if you want to allow anonymous viewing of your webcam, i.e. friends or family.

Next Step: Accessing from the Web