A Step-by-step Guide to Set Up Port-forwarding for OctoPrint Remote Access
Port-forwarding is a technique that gives you access to your OctoPrint from anywhere on the internet, not just when you are on your home network. This guide will walk you through the process step-by-step to show you how to set it up.
Important note: Port-forwarding may be a potential security risk for your home network. Please avoid it unless you know what risks you are taking by setting up port-forwarding. You may want to check other options for accessing OctoPrint from the internet.
Why Port-forwarding?â
Weâre still staying home far more than the norm, but for those who are still out and about and wanting to check your print to make sure its on-task or to see if you even started the print, a common question is âhow do I connect when Iâm not on my home internet?â
Youâre able to connect to it at home using a web browser and navigating to the simple IP address: 192.168.0.XXX; but, when you try to connect to that on the go, you get a 404, address not found error. The reason is simple â your Raspberry Pi and OctoPrint server, while completely accessible at home, is not exposed to the wider web. That is, Your OctoPrint is only accessible on your local area network (LAN), but not accessible to the world-wide web (WAN â Wide Area Network). Your router serves as the gatekeeper that connects your LAN to the WAN, but also makes sure that your LAN isnât accessible to everyone on the web for your security and privacy. Its also used to make sure that your internal network doesnât request individual IPâs on the WAN (Which is why all of your home devices typically take the IP address of (192.168.0.XXX) but you only have one WAN IP.
So what do you need to do to connect your Raspberry Pi to the rest of the world? Well, youâll need to forward exterior requests for webpages (what your web browser is looking for) to your Pi. Specifically, youâll need to instruct your router to forward requests for port 80 (HTTP) to the Pi on your LAN.
What is a port? A port is a specific endpoint for traffic, normally used for separating data flows and allowing multiple different forms of communication to be easily sorted to a single IP. There are unique ports typically used for webpages, email, Minecraft, SSH, file transfer, and many, many other applications. The port that we will specifically be using will be port 80, which is the default for HTTP traffic, which is what is used for loading webpages in your browser.
Prerequisitesâ
In order to forward the port to your Pi, youâll need to know a few things:
- Your routerâs
- IP address
- Username+Password
- Your external IP address
- Your Raspberry Piâs IP address on your LAN.
Find out your routerâs IP addressâ
As for your routerâs IP address, the simplest way of trying to find it is to attempt to access common home router IPâs such as 192.168.0.1 or 192.168.1.1.
Alternatively, you can try to open up the command prompt (for windows) and run the command ip config
â the âdefault gatewayâ provided will very likely be your routerâs ip.
Log in your router with username and passwordâ
Open your router's IP address in a web browser, and youâll likely come across a login screen similar to the one shown below. If you know your username and password, GREAT! If you donât, the default may be in the manual or on the side of the router. If you canât find the manual/not on a sticker, try googling your model with the default password. If the default doesnât work, you may be out of luck unless you do a hard reset to bring everything back to stock. If the default does work, I recommend changing the default user and password to grant a more secure interface.
CAUTION â DO NOT DO THIS UNLESS YOU KNOW HOW TO RE-SETUP YOUR SERVICE, AS YOU MAY LOSE CONNECTION IF YOUR ROUTER WAS MANAGING AUTHENTICATION.
Find out your external IP addressâ
Once youâre logged in, youâll likely be greeted by a generic info screen, similar to the below:
Thankfully, my router is generous enough to give me item #2 on our list, the external IP of the router. This is the address that the rest of the world can use to contact your entire home network, and how your traffic appears to others. Weâll use this later. Depending on your ISP, this may or may not be fixed. My provider has a super-stable IP that only changes when I reboot my router, but others may use a constantly rotating IP. Dynamic DDNS will be required if this is the case, but is outside of the purview of this guide.
If your router doesnât provide this information, a simple search on google for âwhat is my IPâ should provide the same information.
Find out your Raspberry Piâs IP addressâ
If you already know your Raspberry Pi's IP address, you can skip this step.
Otherwise, I assume you are access your OctoPrint using a name like octopi.local
. If this is the case, you can find out its IP address by:
- SSH to your Raspberry Pi. Here is how to do it on Windows, Mac, and Linux.
- Run command
ip addr
. You can find the IP address in the output, as shown in this screenshot.
Finally, set up port-forwarding!â
The âbasicâ tab that Iâm given doesnât have the settings Iâm looking for. This may differ on your particular router.
Opening the Advanced tab and I get quite a bit more information.
What Iâm going to be looking for is âport forwardingâ which I expect to be in the security or NAT (Network Address Translation) forwarding sections.
By trial-and-error, I find âvirtual serversâ which holds some port forwards I have already filled out.
As you can see, there are several fields â Service Type, which is just a description of the service, external port (which is the port that the WAN will see) internal IP (which is where the external portâs traffic will be directed to), internal port (where the port will be rerouted to, can be different than the external port) and the protocol.
To add it, I hit the âaddâ button (whoâd a thunk) and am greeted with the form below.
Fill in the form! If youâd like an extra layer of obfuscation, its perfectly acceptable to make your external port 42069 or whatever youâd like, and still route it to internal port 80, all it would mean is that when you enter your WAN IP into your browser, youâll have to add :42069 to the end before you hit enter. Itâll still work just the same.
Once you have added the entry, it will appear just like the other entries in the table:
Once this is added, you should now be able to access your OctoPrint session from a device not hooked up to your local network. Try this on a phone with the wifi disabled â open the browser, and CAREFULLY type in the external IP from earlier. If you specified a custom port (NOT 80) youâll need to append :custom_port as described earlier.
If successful, you should be greeted with the login for OctoPrint! From here, you should be able to log in and do all the things that you could do from home, from wherever in the world!
Iâve tried to be as generic as possible with this guide, making sure to use the language that is easily searchable should your router be labelled differently. Many possible permutations can be solved with ârouter_model port forwardâ and filling in similar information as described here.
Let us know if this guide helped you and if you have any questions!
IMPORTANT:
AGAIN, BY EXPOSING YOUR PRINTER TO THE WIDER WEB, YOU MAY BE EXPOSING YOURSELF TO MALICIOUS ATTACKS THAT MAY DAMAGE YOUR EQUIPMENT. PLEASE BE CAREFUL AND USE STRONG PASSWORDS TO PROTECT YOUR PRINTER/HOME.