Posted on July 9, 2017 at 11:00 AM
The internet can be thought of as a large country. Everyone in the country has their own address, where they 'live'. Internet addresses are known as IP addresses(which many of you probably already know). Every modem/router hookup has it's own external IP address, one that the world uses to connect to you. These addresses are typically in IPv4 format, and look something like xxx.xxx.xxx.xxx, 4 sets of numbers, no more than 3 numbers per set. These numbers may be anything between 0-255, Hackmypi.com runs on 73.xxx.xxx.xxx for instance(censoring my IP a bit here, but you get the point.)
Internal networks run on a different IP system. An IP for an internal network looks like 192.168.x.x or 10.0.x.x. Typically the 10.0.x.x internal IP addresses are issued by Comcast routers, whereas the 192.168.x.x IP addresses are issued by most other routers. Now internal IP addresses function independent of external IP addresses. Internal here meaning 'within your home' or 'on your wifi/home network'. External meaning 'IP address the world sees'.
Every modem/router gets issued an external IP, every device within your house does not. So my house may have external IP 188.8.131.52, and that serves as the only IP for me to access my network from the outside world. My home devices all have their own IP's of the 10.0.x.x variety, but ALL traffic goes through my modem/router to the outside world from those devices, thus every device in my house, to the outside world, looks like 184.108.40.206.
Think of it like an apartment building. The address for the apartment building may be 123 Main St, so everyone in the building lives at 123 Main St. What the modem/router does with internal IP's is assign every device a room. So my laptop is room 200 at 123 Main St, my desktop is room 201 at 123 Main St, etc. If I want to send a letter to my friend from my laptop, the address on the envelope is still 123 Main St. Ports are basically sub addresses within the rooms. So 'Port 80 on my webserver at 10.0.0.1' is the same as saying 'the Master Bedroom in apartment 201'.
If I have a Pi running a camera feed over my internet on port 8081, and the Pi's IP address is 10.0.0.3 for example, then INSIDE my network, I can see it on a web browser at 10.0.0.3:8081 (the ':' denotes port in web addressing). If you wanted to view this camera feed from the outside world, you have to 'forward' the port on the modem/router. What forwarding does is allow for the outside world to get data directly from one device on a network, over that port. It'd be the same as having people send a letter directly to your Master Bedroom, in room 201 at 123 Main St apartment complex.
So there are external IP's that the world sees, one per household usually (think address of an apartment complex). Internal IP's that are given to your device by your modem/router (Think individual apartments inside the complex) and then Ports, which are different access points within your device (Think rooms in the apartment). Make sense?
Now, why does this matter for a Pi project? Think back to my PiCamPart1 project. The wifi Cam streams across my network at 10.0.0.13:8081, where 10.0.0.13 is the LOCAL IP of the Pi, and 8081 is the port. Anyone on my internal network can view the pi at 10.0.0.13 port 8081, but anyone outside my network cannot see it, because outside my network, everything looks like 220.127.116.11 (Which is my router, not my pi). Every device on a local network has a port 8081, including the router. To view the PiCam from outside my network, what I have to do is link the router's port 8081 to my pi's 8081 at 10.0.0.13. So 18.104.22.168:8081 points to 10.0.0.13:8081. When forwarded, if I connect to 22.214.171.124:8081 from anywhere in the world, I will see the same thing as if I was on my network connecting to 10.0.0.13:8081.
Some notes about this: Every device on my network has a port 8081, but my router only has 1 port 8081. Basically the router can only forward to 1 port 8081 and if you have multiple PiCams, you need to set them to broadcast on multiple ports. If all 3 cams are on port 8081, the router can only broadcast to one device on that port, so the other 2 cams will not be seen from outside the network.
The hard part comes next, actually forwarding the port. The problem is, every router is different and it would be impractical for me to write a guide for every router ever. I'll outline the basic steps for you, but you may need to do some additional research for your specific router model.
For more information: Click Here
Enter your Name and Email to receive notifications about new posts
Feel free to email me at email@example.com with any questions!